Skip to content

Commit

Permalink
chore(lint): update prettier configuration (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
morremeyer authored Nov 8, 2023
1 parent 02b15a7 commit cf3000b
Show file tree
Hide file tree
Showing 64 changed files with 1,928 additions and 1,775 deletions.
6 changes: 3 additions & 3 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"printWidth": 85,
"semi": true,
"semi": false,
"singleQuote": true,
"trailingComma": "all"
"trailingComma": "es5",
"arrowParens": "avoid"
}
2 changes: 1 addition & 1 deletion packages/ynap-bank2ynab-converter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@envelope-zero/ynap-bank2ynab-converter",
"version": "1.14.41",
"version": "1.14.42",
"license": "MIT",
"author": {
"email": "[email protected]",
Expand Down
120 changes: 60 additions & 60 deletions packages/ynap-bank2ynab-converter/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,119 +1,119 @@
#! /usr/bin/env node

import fetch from 'node-fetch';
import fs from 'fs';
import { Command } from 'commander';
import fetch from 'node-fetch'
import fs from 'fs'
import { Command } from 'commander'

const program = new Command();
const program = new Command()

program
.description('Fetch and parse the current bank2ynab config file to JSON')
.option(
'-e, --exclude <items>',
'Exclude banks by their name (comma-separated)',
(v: string) => v.split(',').map((i) => i.trim()),
(v: string) => v.split(',').map(i => i.trim())
)
.option(
'-b, --branch <branch>',
'Set the branch that the config should be fetched from',
'master',
'master'
)
.option('-o, --output <file>', 'Set the output file path', 'bank2ynab.json')
.parse(process.argv);
.parse(process.argv)

import { ParserConfig } from './parserconfig';
import { ParserConfig } from './parserconfig'

const CONFIG_URL = `https://raw.githubusercontent.com/bank2ynab/bank2ynab/${
program.opts()['branch']
}/bank2ynab.conf`;
}/bank2ynab.conf`

const CONFIG_LINK = `https://github.com/bank2ynab/bank2ynab/blob/${
program.opts()['branch']
}/bank2ynab.conf`;
}/bank2ynab.conf`

const SECTION = new RegExp(/^\s*\[([^\]]+)]/);
const KEY = new RegExp(/\s*(.*?)\s*[=:]\s*(.*)/);
const COMMENT = new RegExp(/^\s*[;#]/);
const SECTION = new RegExp(/^\s*\[([^\]]+)]/)
const KEY = new RegExp(/\s*(.*?)\s*[=:]\s*(.*)/)
const COMMENT = new RegExp(/^\s*[;#]/)

const ignorelist = program.opts()['exclude'] || [];
const ignorelist = program.opts()['exclude'] || []

interface Sections {
[k: string]: ConfigFields;
[k: string]: ConfigFields
}

interface ConfigFields {
Line: string;
'Source Filename Pattern'?: string;
'Source Filename Extension'?: string;
'Header Rows'?: string;
'Footer Rows'?: string;
'Input Columns'?: string;
'Date Format'?: string;
'Inflow or Outflow Indicator'?: string;
'Source CSV Delimiter'?: string;
Plugin?: string;
[k: string]: string;
Line: string
'Source Filename Pattern'?: string
'Source Filename Extension'?: string
'Header Rows'?: string
'Footer Rows'?: string
'Input Columns'?: string
'Date Format'?: string
'Inflow or Outflow Indicator'?: string
'Source CSV Delimiter'?: string
Plugin?: string
[k: string]: string
}

export const parseConfig = (config: string) => {
const lines = config.split('\n');
const lines = config.split('\n')

const sections: Sections = {};
const sections: Sections = {}

let currentSection = null;
let currentSection = null

for (let i = 0; i < lines.length; i++) {
const line = lines[i];
const line = lines[i]

if (line.match(COMMENT)) {
continue;
continue
}

const sectionMatch = line.match(SECTION);
const sectionMatch = line.match(SECTION)
if (sectionMatch) {
currentSection = sectionMatch[1];
sections[currentSection] = { Line: String(i + 1) };
continue;
currentSection = sectionMatch[1]
sections[currentSection] = { Line: String(i + 1) }
continue
}

const keyMatch = line.match(KEY);
const keyMatch = line.match(KEY)
if (currentSection && keyMatch && keyMatch[1] && keyMatch[2]) {
const key = keyMatch[1].trim();
const value = keyMatch[2].trim();
const key = keyMatch[1].trim()
const value = keyMatch[2].trim()
if (Object.keys(sections).includes(currentSection)) {
sections[currentSection][key] = value;
sections[currentSection][key] = value
}
}
}

return sections;
};
return sections
}

const script = async () => {
const resp = await fetch(CONFIG_URL);
const resp = await fetch(CONFIG_URL)

if (!resp.ok) {
throw new Error(`Fetch failed: ${resp.status}\n\n${resp.body}`);
throw new Error(`Fetch failed: ${resp.status}\n\n${resp.body}`)
}

const configData = await resp.textConverted();
const configData = await resp.textConverted()

const config = parseConfig(configData);
const config = parseConfig(configData)

console.log('Excluding', ignorelist.length, 'items from ignorelist.');
console.log('Excluding', ignorelist.length, 'items from ignorelist.')

const filteredConfig: ParserConfig[] = Object.keys(config)
.map((c) => ({ ...config[c], Name: c }))
.map(c => ({ ...config[c], Name: c }))
.filter(
(c) =>
c =>
c.Name !== 'DEFAULT' &&
!ignorelist.includes(c.Name) &&
!c.Plugin &&
c['Source Filename Pattern'] !== 'unknown!' &&
c['Input Columns'],
c['Input Columns']
)
.map(
(c) =>
c =>
({
name: c.Name.split(' ').slice(1).join(' '),
country: c.Name.split(' ')[0].toLowerCase(),
Expand All @@ -128,25 +128,25 @@ const script = async () => {
dateFormat: c['Date Format'],
inflowOutflowFlag: c['Inflow or Outflow Indicator']
?.split(',')
.map((s) => s.trim()),
.map(s => s.trim()),
headerRows: Number(c['Header Rows'] || '1'),
footerRows: Number(c['Footer Rows'] || '0'),
}) as ParserConfig,
);
}) as ParserConfig
)

console.log(
'Parsed',
filteredConfig.length,
'bank configs. Filtered from',
Object.keys(config).length,
'configs.',
);
'configs.'
)

fs.writeFileSync(
program.opts()['output'],
JSON.stringify(filteredConfig, null, 2),
);
console.log('Saved configs to', program.opts()['output'].output);
};
JSON.stringify(filteredConfig, null, 2)
)
console.log('Saved configs to', program.opts()['output'].output)
}

script();
script()
20 changes: 10 additions & 10 deletions packages/ynap-bank2ynab-converter/src/parserconfig.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export interface ParserConfig {
filenamePattern: string;
filenameExtension: string;
headerRows: number;
footerRows: number;
inputColumns: string[];
inflowOutflowFlag?: [string, string, string];
dateFormat?: string;
name: string;
link: string;
country: string;
filenamePattern: string
filenameExtension: string
headerRows: number
footerRows: number
inputColumns: string[]
inflowOutflowFlag?: [string, string, string]
dateFormat?: string
name: string
link: string
country: string
}
2 changes: 1 addition & 1 deletion packages/ynap-parsers/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ module.exports = {
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
testEnvironment: 'jsdom',
};
}
2 changes: 1 addition & 1 deletion packages/ynap-parsers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@envelope-zero/ynap-parsers",
"version": "1.15.34",
"version": "1.15.35",
"description": "Parsers from various formats to YNAB CSV",
"main": "index.js",
"author": "Envelope Zero Team <[email protected]> (https://envelope-zero.org)",
Expand Down
68 changes: 34 additions & 34 deletions packages/ynap-parsers/src/at/ing/ing-austria.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { generateYnabDate, ingAustria } from './ing-austria';
import { YnabFile } from '../..';
import { encode } from 'iconv-lite';
import { generateYnabDate, ingAustria } from './ing-austria'
import { YnabFile } from '../..'
import { encode } from 'iconv-lite'

const content = encode(
`IBAN;Text;Valutadatum;Währung;Soll;Haben
AT483200000012345864;Outflow from Max Mustermann;01.12.2019;EUR;100,01;0,00
AT483200000012345864;Inflow from John Doe;02.12.2019;EUR;0,00;200,01`,
'ISO-8859-1',
);
'ISO-8859-1'
)

const ynabResult: YnabFile[] = [
{
Expand All @@ -28,50 +28,50 @@ const ynabResult: YnabFile[] = [
},
],
},
];
]

describe('ING Austria Parser Module', () => {
describe('Matcher', () => {
it('should match ING Austria files by file name', async () => {
const fileName = 'ING_Umsaetze.csv';
const result = !!fileName.match(ingAustria.filenamePattern);
expect(result).toBe(true);
});
const fileName = 'ING_Umsaetze.csv'
const result = !!fileName.match(ingAustria.filenamePattern)
expect(result).toBe(true)
})

it('should not match other files by file name', async () => {
const invalidFile = new File([], 'test.csv');
const result = await ingAustria.match(invalidFile);
expect(result).toBe(false);
});
const invalidFile = new File([], 'test.csv')
const result = await ingAustria.match(invalidFile)
expect(result).toBe(false)
})

it('should match ING Austria files by fields', async () => {
const file = new File([content], 'test.csv');
const result = await ingAustria.match(file);
expect(result).toBe(true);
});
const file = new File([content], 'test.csv')
const result = await ingAustria.match(file)
expect(result).toBe(true)
})

it('should not match empty files', async () => {
const file = new File([], 'test.csv');
const result = await ingAustria.match(file);
expect(result).toBe(false);
});
});
const file = new File([], 'test.csv')
const result = await ingAustria.match(file)
expect(result).toBe(false)
})
})

describe('Parser', () => {
it('should parse data correctly', async () => {
const file = new File([content], 'test.csv');
const result = await ingAustria.parse(file);
expect(result).toEqual(ynabResult);
});
});
const file = new File([content], 'test.csv')
const result = await ingAustria.parse(file)
expect(result).toEqual(ynabResult)
})
})

describe('Date Converter', () => {
it('should format an input date correctly', () => {
expect(generateYnabDate('03.05.2018')).toEqual('05/03/2018');
});
expect(generateYnabDate('03.05.2018')).toEqual('05/03/2018')
})

it('should throw an error when the input date is incorrect', () => {
expect(() => generateYnabDate('1.1.1')).toThrow('not a valid date');
});
});
});
expect(() => generateYnabDate('1.1.1')).toThrow('not a valid date')
})
})
})
Loading

0 comments on commit cf3000b

Please sign in to comment.