Skip to content

Commit

Permalink
Another round of prefer-const rule updates
Browse files Browse the repository at this point in the history
  • Loading branch information
joel-jeremy committed Dec 2, 2023
1 parent 5f52801 commit 0b626d4
Show file tree
Hide file tree
Showing 96 changed files with 1,506 additions and 1,428 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ module.exports = {
'./packages/loot-core/src/client/**/*',
'./packages/loot-core/src/mocks/**/*',
'./packages/loot-core/src/platform/**/*',
// './packages/loot-core/src/server/**/*',
'./packages/loot-core/src/server/**/*',
'./packages/loot-core/src/shared/**/*',
'./packages/loot-core/src/types/**/*',
'./packages/loot-core/webpack/**/*',
Expand Down
10 changes: 5 additions & 5 deletions packages/loot-core/src/server/accounts/export-to-csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export async function exportToCSV(
}

export async function exportQueryToCSV(query) {
let { data: transactions } = await aqlQuery(
const { data: transactions } = await aqlQuery(
query
.select([
{ Id: 'id' },
Expand All @@ -61,18 +61,18 @@ export async function exportQueryToCSV(query) {
.options({ splits: 'all' }),
);

let parentsPayees = new Map();
for (let trans of transactions) {
const parentsPayees = new Map();
for (const trans of transactions) {
if (trans.IsParent) {
parentsPayees.set(trans.Id, trans.Payee);
}
}

// filter out any parent transactions
let noParents = transactions.filter(t => !t.IsParent);
const noParents = transactions.filter(t => !t.IsParent);

// map final properties for export and grab the payee for splits from their parent transaction
let transactionsForExport = noParents.map(trans => {
const transactionsForExport = noParents.map(trans => {
return {
Account: trans.Account,
Date: trans.Date,
Expand Down
18 changes: 9 additions & 9 deletions packages/loot-core/src/server/accounts/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { getServer } from '../server-config';
import * as bankSync from './sync';

export async function handoffPublicToken(institution, publicToken) {
let [[, userId], [, key]] = await asyncStorage.multiGet([
const [[, userId], [, key]] = await asyncStorage.multiGet([
'user-id',
'user-key',
]);
Expand All @@ -19,7 +19,7 @@ export async function handoffPublicToken(institution, publicToken) {
throw new Error('Invalid institution object');
}

let id = uuidv4();
const id = uuidv4();

// Make sure to generate an access token first before inserting it
// into our local database in case it fails
Expand All @@ -42,7 +42,7 @@ export async function handoffPublicToken(institution, publicToken) {
}

export async function findOrCreateBank(institution, requisitionId) {
let bank = await db.first(
const bank = await db.first(
'SELECT id, bank_id, name FROM banks WHERE bank_id = ?',
[requisitionId],
);
Expand All @@ -63,7 +63,7 @@ export async function findOrCreateBank(institution, requisitionId) {
}

export async function addAccounts(bankId, accountIds, offbudgetIds = []) {
let [[, userId], [, userKey]] = await asyncStorage.multiGet([
const [[, userId], [, userKey]] = await asyncStorage.multiGet([
'user-id',
'user-key',
]);
Expand All @@ -76,8 +76,8 @@ export async function addAccounts(bankId, accountIds, offbudgetIds = []) {

return Promise.all(
accounts.map(async acct => {
let id = await runMutator(async () => {
let id = await db.insertAccount({
const id = await runMutator(async () => {
const id = await db.insertAccount({
account_id: acct.account_id,
name: acct.name,
official_name: acct.official_name,
Expand Down Expand Up @@ -109,7 +109,7 @@ export async function addGoCardlessAccounts(
accountIds,
offbudgetIds = [],
) {
let [[, userId], [, userKey]] = await asyncStorage.multiGet([
const [[, userId], [, userKey]] = await asyncStorage.multiGet([
'user-id',
'user-key',
]);
Expand All @@ -122,8 +122,8 @@ export async function addGoCardlessAccounts(

return Promise.all(
accounts.map(async acct => {
let id = await runMutator(async () => {
let id = await db.insertAccount({
const id = await runMutator(async () => {
const id = await db.insertAccount({
account_id: acct.account_id,
name: acct.name,
official_name: acct.official_name,
Expand Down
19 changes: 10 additions & 9 deletions packages/loot-core/src/server/accounts/parse-file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ beforeEach(global.emptyDatabase());
// libofx spits out errors that contain the entire
// source code of the file in the stack which makes
// it hard to test.
let old = console.warn;
const old = console.warn;
beforeAll(() => {
console.warn = () => {};
});
Expand All @@ -35,11 +35,12 @@ async function importFileWithRealTime(
) {
// Emscripten requires a real Date.now!
global.restoreDateNow();
let { errors, transactions } = await parseFile(filepath, {
const parseFileResult = await parseFile(filepath, {
enableExperimentalOfxParser: true,
});
global.restoreFakeDateNow();

let transactions = parseFileResult.transactions;
if (transactions) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
transactions = (transactions as any[]).map(trans => ({
Expand All @@ -50,20 +51,20 @@ async function importFileWithRealTime(
: trans.date,
}));
}

const errors = parseFileResult.errors;
if (errors.length > 0) {
return { errors, added: [] };
}

let { added } = await reconcileTransactions(accountId, transactions);
const { added } = await reconcileTransactions(accountId, transactions);
return { errors, added };
}

describe('File import', () => {
test('qif import works', async () => {
prefs.loadPrefs();
await db.insertAccount({ id: 'one', name: 'one' });
let { errors } = await importFileWithRealTime(
const { errors } = await importFileWithRealTime(
'one',
__dirname + '/../../mocks/files/data.qif',
'MM/dd/yy',
Expand All @@ -76,7 +77,7 @@ describe('File import', () => {
prefs.loadPrefs();
await db.insertAccount({ id: 'one', name: 'one' });

let { errors } = await importFileWithRealTime(
const { errors } = await importFileWithRealTime(
'one',
__dirname + '/../../mocks/files/data.ofx',
);
Expand All @@ -88,7 +89,7 @@ describe('File import', () => {
prefs.loadPrefs();
await db.insertAccount({ id: 'one', name: 'one' });

let { errors } = await importFileWithRealTime(
const { errors } = await importFileWithRealTime(
'one',
__dirname + '/../../mocks/files/credit-card.ofx',
);
Expand All @@ -100,7 +101,7 @@ describe('File import', () => {
prefs.loadPrefs();
await db.insertAccount({ id: 'one', name: 'one' });

let { errors } = await importFileWithRealTime(
const { errors } = await importFileWithRealTime(
'one',
__dirname + '/../../mocks/files/data.qfx',
);
Expand Down Expand Up @@ -134,7 +135,7 @@ describe('File import', () => {
prefs.loadPrefs();
await db.insertAccount({ id: 'one', name: 'one' });

let { errors } = await importFileWithRealTime(
const { errors } = await importFileWithRealTime(
'one',
__dirname + '/../../mocks/files/8859-1.qfx',
'yyyy-MM-dd',
Expand Down
24 changes: 12 additions & 12 deletions packages/loot-core/src/server/accounts/parse-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ export async function parseFile(
filepath: string,
options?: ParseFileOptions,
): Promise<ParseFileResult> {
let errors = Array<ParseError>();
let m = filepath.match(/\.[^.]*$/);
const errors = Array<ParseError>();
const m = filepath.match(/\.[^.]*$/);

if (m) {
let ext = m[0];
const ext = m[0];

switch (ext.toLowerCase()) {
case '.qif':
Expand All @@ -54,8 +54,8 @@ async function parseCSV(
filepath: string,
options?: ParseFileOptions,
): Promise<ParseFileResult> {
let errors = Array<ParseError>();
let contents = await fs.readFile(filepath);
const errors = Array<ParseError>();
const contents = await fs.readFile(filepath);

let data;
try {
Expand All @@ -81,8 +81,8 @@ async function parseCSV(
}

async function parseQIF(filepath: string): Promise<ParseFileResult> {
let errors = Array<ParseError>();
let contents = await fs.readFile(filepath);
const errors = Array<ParseError>();
const contents = await fs.readFile(filepath);

let data;
try {
Expand Down Expand Up @@ -131,7 +131,7 @@ async function parseOFX(

// Banks don't always implement the OFX standard properly
// If no payee is available try and fallback to memo
let useMemoFallback = options.fallbackMissingPayeeToMemo;
const useMemoFallback = options.fallbackMissingPayeeToMemo;

return {
errors,
Expand All @@ -152,13 +152,13 @@ async function parseOFXNodeLibOFX(
filepath: string,
options: ParseFileOptions,
): Promise<ParseFileResult> {
let { getOFXTransactions, initModule } = await import(
const { getOFXTransactions, initModule } = await import(
/* webpackChunkName: 'xfo' */ 'node-libofx'
);
await initModule();

let errors = Array<ParseError>();
let contents = await fs.readFile(filepath, 'binary');
const errors = Array<ParseError>();
const contents = await fs.readFile(filepath, 'binary');

let data;
try {
Expand All @@ -173,7 +173,7 @@ async function parseOFXNodeLibOFX(

// Banks don't always implement the OFX standard properly
// If no payee is available try and fallback to memo
let useMemoFallback = options.fallbackMissingPayeeToMemo;
const useMemoFallback = options.fallbackMissingPayeeToMemo;

return {
errors,
Expand Down
4 changes: 2 additions & 2 deletions packages/loot-core/src/server/accounts/payees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as db from '../db';
export async function createPayee(description) {
// Check to make sure no payee already exists with exactly the same
// name
let row = await db.first(
const row = await db.first(
`SELECT id FROM payees WHERE UNICODE_LOWER(name) = ? AND tombstone = 0`,
[description.toLowerCase()],
);
Expand All @@ -29,7 +29,7 @@ export async function getStartingBalancePayee() {
);
}

let id = await createPayee('Starting Balance');
const id = await createPayee('Starting Balance');
return {
id,
category: category ? category.id : null,
Expand Down
12 changes: 6 additions & 6 deletions packages/loot-core/src/server/accounts/qif2json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ type QIFTransaction = {
};

export default function parse(qif, options: { dateFormat?: string } = {}) {
let lines = qif.split('\n');
const lines = qif.split('\n');
let line = lines.shift();
let type = /!Type:([^$]*)$/.exec(line.trim());
let data: {
const type = /!Type:([^$]*)$/.exec(line.trim());
const data: {
dateFormat: string | undefined;
type?;
transactions: QIFTransaction[];
} = {
dateFormat: options.dateFormat,
transactions: [],
};
let transactions = data.transactions;
const transactions = data.transactions;
let transaction: QIFTransaction = {};

if (!type || !type.length) {
Expand Down Expand Up @@ -69,7 +69,7 @@ export default function parse(qif, options: { dateFormat?: string } = {}) {
transaction.payee = line.substring(1).replace(/&amp;/g, '&');
break;
case 'L':
let lArray = line.substring(1).split(':');
const lArray = line.substring(1).split(':');
transaction.category = lArray[0];
if (lArray[1] !== undefined) {
transaction.subcategory = lArray[1];
Expand All @@ -79,7 +79,7 @@ export default function parse(qif, options: { dateFormat?: string } = {}) {
transaction.clearedStatus = line.substring(1);
break;
case 'S':
let sArray = line.substring(1).split(':');
const sArray = line.substring(1).split(':');
division.category = sArray[0];
if (sArray[1] !== undefined) {
division.subcategory = sArray[1];
Expand Down
Loading

0 comments on commit 0b626d4

Please sign in to comment.