Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🀍

Feature/Set prefer-const to error in eslint configuration (#3888)

dw-0fc5ed887ff50
diff --git a/.eslintrc.json b/.eslintrc.json
index a3b868692c..d3f7edea90 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -139,7 +139,6 @@
"@typescript-eslint/require-await": "warn",
"@typescript-eslint/restrict-template-expressions": "warn",
"@typescript-eslint/unbound-method": "warn",
- "prefer-const": "warn",
// The following rules are part of @typescript-eslint/stylistic-type-checked
// and can be remove once solved
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 80b0236d8a..0a43aa44c0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Extended the _Public API_ with the health check endpoint (experimental)
+### Changed
+
+- Switched the `prefer-const` rule from `warn` to `error` in the `eslint` configuration
+
## 2.113.0 - 2024-10-06
### Added
diff --git a/apps/api/src/app/admin/admin.service.ts b/apps/api/src/app/admin/admin.service.ts
index 6c3d7c1417..860f19851f 100644
--- a/apps/api/src/app/admin/admin.service.ts
+++ b/apps/api/src/app/admin/admin.service.ts
@@ -233,7 +233,7 @@ export class AdminService {
const extendedPrismaClient = this.getExtendedPrismaClient();
try {
- let [assetProfiles, count] = await Promise.all([
+ const symbolProfileResult = await Promise.all([
extendedPrismaClient.symbolProfile.findMany({
orderBy,
skip,
@@ -264,6 +264,8 @@ export class AdminService {
}),
this.prismaService.symbolProfile.count({ where })
]);
+ const assetProfiles = symbolProfileResult[0];
+ let count = symbolProfileResult[1];
const lastMarketPrices = await this.prismaService.marketData.findMany({
distinct: ['dataSource', 'symbol'],
diff --git a/apps/api/src/app/benchmark/benchmark.service.ts b/apps/api/src/app/benchmark/benchmark.service.ts
index f57f5fa306..34f101a8e5 100644
--- a/apps/api/src/app/benchmark/benchmark.service.ts
+++ b/apps/api/src/app/benchmark/benchmark.service.ts
@@ -234,7 +234,7 @@ export class BenchmarkService {
return { marketData };
}
- for (let marketDataItem of marketDataItems) {
+ for (const marketDataItem of marketDataItems) {
const exchangeRate =
exchangeRates[`${currentSymbolItem.currency}${userCurrency}`]?.[
format(marketDataItem.date, DATE_FORMAT)
diff --git a/apps/api/src/app/import/import.service.ts b/apps/api/src/app/import/import.service.ts
index c42cd300b8..30415970d7 100644
--- a/apps/api/src/app/import/import.service.ts
+++ b/apps/api/src/app/import/import.service.ts
@@ -266,21 +266,18 @@ export class ImportService {
const activities: Activity[] = [];
- for (let [
- index,
- {
- accountId,
- comment,
- currency,
- date,
- error,
- fee,
- quantity,
- SymbolProfile,
- type,
- unitPrice
- }
- ] of activitiesExtendedWithErrors.entries()) {
+ for (const [index, activity] of activitiesExtendedWithErrors.entries()) {
+ const accountId = activity.accountId;
+ const comment = activity.comment;
+ const currency = activity.currency;
+ const date = activity.date;
+ const error = activity.error;
+ let fee = activity.fee;
+ const quantity = activity.quantity;
+ const SymbolProfile = activity.SymbolProfile;
+ const type = activity.type;
+ let unitPrice = activity.unitPrice;
+
const assetProfile = assetProfiles[
getAssetProfileIdentifier({
dataSource: SymbolProfile.dataSource,
@@ -491,12 +488,13 @@ export class ImportService {
userCurrency: string;
userId: string;
}): Promise<Partial<Activity>[]> {
- let { activities: existingActivities } = await this.orderService.getOrders({
- userCurrency,
- userId,
- includeDrafts: true,
- withExcludedAccounts: true
- });
+ const { activities: existingActivities } =
+ await this.orderService.getOrders({
+ userCurrency,
+ userId,
+ includeDrafts: true,
+ withExcludedAccounts: true
+ });
return activitiesDto.map(
({
diff --git a/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts b/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts
index ba3b602376..3d39b80b5e 100644
--- a/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts
+++ b/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts
@@ -217,7 +217,7 @@ export abstract class PortfolioCalculator {
}
}
- let exchangeRatesByCurrency =
+ const exchangeRatesByCurrency =
await this.exchangeRateDataService.getExchangeRatesByCurrency({
currencies: uniq(Object.values(currencies)),
endDate: endOfDay(this.endDate),
@@ -261,7 +261,7 @@ export abstract class PortfolioCalculator {
const daysInMarket = differenceInDays(this.endDate, this.startDate);
- let chartDateMap = this.getChartDateMap({
+ const chartDateMap = this.getChartDateMap({
endDate: this.endDate,
startDate: this.startDate,
step: Math.round(
@@ -701,9 +701,9 @@ export abstract class PortfolioCalculator {
let netPerformanceAtStartDate: number;
let netPerformanceWithCurrencyEffectAtStartDate: number;
- let totalInvestmentValuesWithCurrencyEffect: number[] = [];
+ const totalInvestmentValuesWithCurrencyEffect: number[] = [];
- for (let historicalDataItem of historicalData) {
+ for (const historicalDataItem of historicalData) {
const date = resetHours(parseDate(historicalDataItem.date));
if (!isBefore(date, start) && !isAfter(date, end)) {
@@ -832,13 +832,13 @@ export abstract class PortfolioCalculator {
}): { [date: string]: true } {
// Create a map of all relevant chart dates:
// 1. Add transaction point dates
- let chartDateMap = this.transactionPoints.reduce((result, { date }) => {
+ const chartDateMap = this.transactionPoints.reduce((result, { date }) => {
result[date] = true;
return result;
}, {});
// 2. Add dates between transactions respecting the specified step size
- for (let date of eachDayOfInterval(
+ for (const date of eachDayOfInterval(
{ end: endDate, start: startDate },
{ step }
)) {
@@ -847,7 +847,7 @@ export abstract class PortfolioCalculator {
if (step > 1) {
// Reduce the step size of last 90 days
- for (let date of eachDayOfInterval(
+ for (const date of eachDayOfInterval(
{ end: endDate, start: subDays(endDate, 90) },
{ step: 3 }
)) {
@@ -855,7 +855,7 @@ export abstract class PortfolioCalculator {
}
// Reduce the step size of last 30 days
- for (let date of eachDayOfInterval(
+ for (const date of eachDayOfInterval(
{ end: endDate, start: subDays(endDate, 30) },
{ step: 1 }
)) {
@@ -867,7 +867,7 @@ export abstract class PortfolioCalculator {
chartDateMap[format(endDate, DATE_FORMAT)] = true;
// Make sure some key dates are present
- for (let dateRange of ['1d', '1y', '5y', 'max', 'mtd', 'wtd', 'ytd']) {
+ for (const dateRange of ['1d', '1y', '5y', 'max', 'mtd', 'wtd', 'ytd']) {
const { endDate: dateRangeEnd, startDate: dateRangeStart } =
getIntervalFromDateRange(dateRange);
diff --git a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator.ts b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator.ts
index b66bc0d531..950d9e4d37 100644
--- a/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator.ts
+++ b/apps/api/src/app/portfolio/calculator/twr/portfolio-calculator.ts
@@ -27,7 +27,7 @@ export class TWRPortfolioCalculator extends PortfolioCalculator {
let hasErrors = false;
let netPerformance = new Big(0);
let totalFeesWithCurrencyEffect = new Big(0);
- let totalInterestWithCurrencyEffect = new Big(0);
+ const totalInterestWithCurrencyEffect = new Big(0);
let totalInvestment = new Big(0);
let totalInvestmentWithCurrencyEffect = new Big(0);
let totalTimeWeightedInvestment = new Big(0);
@@ -156,7 +156,7 @@ export class TWRPortfolioCalculator extends PortfolioCalculator {
[date: string]: Big;
} = {};
- let totalAccountBalanceInBaseCurrency = new Big(0);
+ const totalAccountBalanceInBaseCurrency = new Big(0);
let totalDividend = new Big(0);
let totalDividendInBaseCurrency = new Big(0);
let totalInterest = new Big(0);
@@ -320,7 +320,7 @@ export class TWRPortfolioCalculator extends PortfolioCalculator {
}
if (ordersByDate[dateString]?.length > 0) {
- for (let order of ordersByDate[dateString]) {
+ for (const order of ordersByDate[dateString]) {
order.unitPriceFromMarketData =
marketSymbolMap[dateString]?.[symbol] ?? lastUnitPrice;
}
@@ -813,8 +813,9 @@ export class TWRPortfolioCalculator extends PortfolioCalculator {
// return format(date, 'yyyy');
// })
]) {
- // TODO: getIntervalFromDateRange(dateRange, start)
- let { endDate, startDate } = getIntervalFromDateRange(dateRange);
+ const dateInterval = getIntervalFromDateRange(dateRange);
+ const endDate = dateInterval.endDate;
+ let startDate = dateInterval.startDate;
if (isBefore(startDate, start)) {
startDate = start;
diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts
index 89eeb666d4..bbc8f437eb 100644
--- a/apps/api/src/app/portfolio/portfolio.service.ts
+++ b/apps/api/src/app/portfolio/portfolio.service.ts
@@ -943,7 +943,9 @@ export class PortfolioService {
currency: this.request.user.Settings.settings.baseCurrency
});
- let { hasErrors, positions } = await portfolioCalculator.getSnapshot();
+ const portfolioSnapshot = await portfolioCalculator.getSnapshot();
+ const hasErrors = portfolioSnapshot.hasErrors;
+ let positions = portfolioSnapshot.positions;
positions = positions.filter(({ quantity }) => {
return !quantity.eq(0);
@@ -1984,7 +1986,7 @@ export class PortfolioService {
SymbolProfile,
type
} of ordersByAccount) {
- let currentValueOfSymbolInBaseCurrency =
+ const currentValueOfSymbolInBaseCurrency =
getFactor(type) *
quantity *
(portfolioItemsNow[SymbolProfile.symbol]?.marketPriceInBaseCurrency ??
diff --git a/apps/api/src/app/user/user.service.ts b/apps/api/src/app/user/user.service.ts
index a3dfc2fcae..c04af5fbfb 100644
--- a/apps/api/src/app/user/user.service.ts
+++ b/apps/api/src/app/user/user.service.ts
@@ -56,7 +56,7 @@ export class UserService {
{ Account, id, permissions, Settings, subscription }: UserWithSettings,
aLocale = locale
): Promise<IUser> {
- let [access, firstActivity, tags] = await Promise.all([
+ const accessesResult = await Promise.all([
this.prismaService.access.findMany({
include: {
User: true
@@ -72,6 +72,9 @@ export class UserService {
}),
this.tagService.getInUseByUser(id)
]);
+ const access = accessesResult[0];
+ const firstActivity = accessesResult[1];
+ let tags = accessesResult[2];
let systemMessage: SystemMessage;
diff --git a/apps/api/src/services/data-provider/data-enhancer/openfigi/openfigi.service.ts b/apps/api/src/services/data-provider/data-enhancer/openfigi/openfigi.service.ts
index 4d26b31fb9..8d2d180e38 100644
--- a/apps/api/src/services/data-provider/data-enhancer/openfigi/openfigi.service.ts
+++ b/apps/api/src/services/data-provider/data-enhancer/openfigi/openfigi.service.ts
@@ -43,7 +43,7 @@ export class OpenFigiDataEnhancerService implements DataEnhancerInterface {
this.configurationService.get('API_KEY_OPEN_FIGI');
}
- let abortController = new AbortController();
+ const abortController = new AbortController();
setTimeout(() => {
abortController.abort();
diff --git a/apps/api/src/services/data-provider/data-provider.service.ts b/apps/api/src/services/data-provider/data-provider.service.ts
index bd20541aff..385c7b0788 100644
--- a/apps/api/src/services/data-provider/data-provider.service.ts
+++ b/apps/api/src/services/data-provider/data-provider.service.ts
@@ -458,7 +458,9 @@ export class DataProviderService {
promises.push(
promise.then(async (result) => {
- for (let [symbol, dataProviderResponse] of Object.entries(result)) {
+ for (const [symbol, dataProviderResponse] of Object.entries(
+ result
+ )) {
if (
[
...DERIVED_CURRENCIES.map(({ currency }) => {
@@ -577,7 +579,7 @@ export class DataProviderService {
return { items: lookupItems };
}
- let dataProviderServices = this.configurationService
+ const dataProviderServices = this.configurationService
.get('DATA_SOURCES')
.map((dataSource) => {
return this.getDataProvider(DataSource[dataSource]);
diff --git a/apps/api/src/services/data-provider/eod-historical-data/eod-historical-data.service.ts b/apps/api/src/services/data-provider/eod-historical-data/eod-historical-data.service.ts
index cc23344a35..3a840340ef 100644
--- a/apps/api/src/services/data-provider/eod-historical-data/eod-historical-data.service.ts
+++ b/apps/api/src/services/data-provider/eod-historical-data/eod-historical-data.service.ts
@@ -203,7 +203,7 @@ export class EodHistoricalDataService implements DataProviderInterface {
requestTimeout = this.configurationService.get('REQUEST_TIMEOUT'),
symbols
}: GetQuotesParams): Promise<{ [symbol: string]: IDataProviderResponse }> {
- let response: { [symbol: string]: IDataProviderResponse } = {};
+ const response: { [symbol: string]: IDataProviderResponse } = {};
if (symbols.length <= 0) {
return response;
diff --git a/apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts b/apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts
index 31b2f885cc..db95a34872 100644
--- a/apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts
+++ b/apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts
@@ -63,11 +63,11 @@ export class ExchangeRateDataService {
return {};
}
- let exchangeRatesByCurrency: {
+ const exchangeRatesByCurrency: {
[currency: string]: { [dateString: string]: number };
} = {};
- for (let currency of currencies) {
+ for (const currency of currencies) {
exchangeRatesByCurrency[`${currency}${targetCurrency}`] =
await this.getExchangeRates({
startDate,
@@ -94,7 +94,7 @@ export class ExchangeRateDataService {
!isBefore(date, startDate);
date = subDays(resetHours(date), 1)
) {
- let dateString = format(date, DATE_FORMAT);
+ const dateString = format(date, DATE_FORMAT);
// Check if the exchange rate for the current date is missing
if (
@@ -351,7 +351,7 @@ export class ExchangeRateDataService {
startDate: Date;
}) {
const dates = eachDayOfInterval({ end: endDate, start: startDate });
- let factors: { [dateString: string]: number } = {};
+ const factors: { [dateString: string]: number } = {};
if (currencyFrom === currencyTo) {
for (const date of dates) {
@@ -379,10 +379,10 @@ export class ExchangeRateDataService {
} else {
// Calculate indirectly via base currency
- let marketPriceBaseCurrencyFromCurrency: {
+ const marketPriceBaseCurrencyFromCurrency: {
[dateString: string]: number;
} = {};
- let marketPriceBaseCurrencyToCurrency: {
+ const marketPriceBaseCurrencyToCurrency: {
[dateString: string]: number;
} = {};
diff --git a/apps/client/src/app/components/account-detail-dialog/account-detail-dialog.component.ts b/apps/client/src/app/components/account-detail-dialog/account-detail-dialog.component.ts
index d6791760bb..d4bdad5566 100644
--- a/apps/client/src/app/components/account-detail-dialog/account-detail-dialog.component.ts
+++ b/apps/client/src/app/components/account-detail-dialog/account-detail-dialog.component.ts
@@ -121,7 +121,7 @@ export class AccountDetailDialog implements OnDestroy, OnInit {
}
public onExport() {
- let activityIds = this.dataSource.data.map(({ id }) => {
+ const activityIds = this.dataSource.data.map(({ id }) => {
return id;
});
diff --git a/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts b/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts
index 027c06bd6b..b94ba79d50 100644
--- a/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts
+++ b/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts
@@ -463,7 +463,7 @@ export class GfHoldingDetailDialogComponent implements OnDestroy, OnInit {
}
public onExport() {
- let activityIds = this.dataSource.data.map(({ id }) => {
+ const activityIds = this.dataSource.data.map(({ id }) => {
return id;
});
diff --git a/apps/client/src/app/services/data.service.ts b/apps/client/src/app/services/data.service.ts
index 4135335c6d..b5affeb603 100644
--- a/apps/client/src/app/services/data.service.ts
+++ b/apps/client/src/app/services/data.service.ts
@@ -287,7 +287,7 @@ export class DataService {
}
public deleteActivities({ filters }) {
- let params = this.buildFiltersAsQueryParams({ filters });
+ const params = this.buildFiltersAsQueryParams({ filters });
return this.http.delete<any>(`/api/v1/order`, { params });
}
diff --git a/libs/common/src/lib/helper.ts b/libs/common/src/lib/helper.ts
index 689150b68a..005d3d77e1 100644
--- a/libs/common/src/lib/helper.ts
+++ b/libs/common/src/lib/helper.ts
@@ -135,7 +135,7 @@ export function extractNumberFromString({
// Remove non-numeric characters (excluding international formatting characters)
const numericValue = value.replace(/[^\d.,'’\s]/g, '');
- let parser = new NumberParser(locale);
+ const parser = new NumberParser(locale);
return parser.parse(numericValue);
} catch {