Skip to content

Commit

Permalink
Convert to new flat config for eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
dpilafian committed Aug 14, 2024
1 parent 2e81dd3 commit cbc5600
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 33 deletions.
6 changes: 3 additions & 3 deletions clabe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const clabe = {
city: 'Invalid city code: ',
};
if (typeof clabeNum !== 'string')
throw 'clabe.validator.check(clabeNum) -- Expected string, got: ' + typeof clabeNum;
throw new Error('clabe.validator.check(clabeNum) -- Expected string, got: ' + typeof clabeNum);
const bankCode = clabeNum.substring(0, 3);
const cityCode = clabeNum.substring(3, 6);
const account = clabeNum.substring(6, 17);
Expand All @@ -76,7 +76,7 @@ const clabe = {
ok: !validation,
formatOk: !validation || ['bank', 'city'].includes(validation.invalid),
error: validation ? 'invalid-' + validation.invalid : null,
message: validation ? <string>errorMap[validation.invalid] + validation.data : 'Valid',
message: validation ? errorMap[validation.invalid]! + String(validation.data) : 'Valid',
clabe: validation ? null : clabeNum,
tag: bank.tag || null,
bank: bank.name || null,
Expand All @@ -96,7 +96,7 @@ const clabe = {
const pad = (text: string, len: number): string => text.length < len ? pad('0' + text, len) : text;
const fit = (num: number, len: number) => pad(num.toString(), len).slice(-len);
const clabeNum = fit(bankCode, 3) + fit(cityCode, 3) + fit(accountNumber, 11);
return clabeNum + clabe.computeChecksum(clabeNum);
return clabeNum + String(clabe.computeChecksum(clabeNum));
},

banksMap: <ClabeBanksMap>{
Expand Down
22 changes: 22 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// @ts-check

import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';

export default [
eslint.configs.recommended,
...tseslint.configs.strictTypeChecked,
{ ignores: ['**/*.js'] },
{
languageOptions: { parserOptions: { projectService: true } },
rules: {
'@typescript-eslint/no-confusing-void-expression': 'off', //prefer minimal arrow functions
'@typescript-eslint/no-floating-promises': 'off', //annimations may be fire-and-forget
'@typescript-eslint/no-misused-promises': 'off', //annimations may be fire-and-forget
'@typescript-eslint/no-non-null-assertion': 'off', //ts cannot always know value exists
'@typescript-eslint/restrict-template-expressions': 'off', //numbers in templates are natural
'@typescript-eslint/unbound-method': 'off', //safer to not use 'this'
'@typescript-eslint/use-unknown-in-catch-callback-variable': 'off', //clarity over theoretical exceptions
},
},
];
39 changes: 10 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,13 @@
"mocha": true,
"node": true
},
"eslintConfig": {
"ignorePatterns": [
"build",
"dist",
"node_modules"
],
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"@typescript-eslint/no-non-null-assertion": "off"
}
},
"runScriptsConfig": {
"clean": [
"rimraf build dist"
],
"lint": [
"jshint . --exclude-path .gitignore",
"eslint --max-warnings 0 . --ext .ts"
"eslint --max-warnings 0"
],
"build": [
"tsc",
Expand All @@ -84,25 +65,25 @@
"test": "mocha spec/*.spec.js"
},
"devDependencies": {
"@eslint/js": "~9.6",
"@fortawesome/fontawesome-free": "~6.5",
"@types/node": "~20.14",
"@eslint/js": "~9.9",
"@fortawesome/fontawesome-free": "~6.6",
"@types/node": "~22.2",
"add-dist-header": "~1.4",
"assert-deep-strict-equal": "~1.2",
"copy-file-util": "~1.2",
"copy-folder-util": "~1.1",
"dna-engine": "~3.2",
"eslint": "8.57.0",
"eslint": "~9.9",
"esm-to-plain-js": "~1.1",
"jsdom": "~24.1",
"jshint": "~2.13",
"mocha": "~10.6",
"mocha": "~10.7",
"pretty-print-json": "~3.0",
"rimraf": "~5.0",
"run-scripts-util": "~1.2",
"rimraf": "~6.0",
"run-scripts-util": "~1.3",
"typescript": "~5.5",
"typescript-eslint": "~7.15",
"uglify-js": "~3.18",
"typescript-eslint": "~8.1",
"uglify-js": "~3.19",
"w3c-html-validator": "~1.8",
"web-ignition": "~2.2"
}
Expand Down
2 changes: 1 addition & 1 deletion spec/clabe.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<link rel=apple-touch-icon href=https://centerkey.com/graphics/mobile-home-screen.png>
<link rel=preconnect href=https://fonts.googleapis.com>
<link rel=preconnect href=https://fonts.gstatic.com crossorigin>
<link rel=stylesheet href=https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.5/css/all.min.css>
<link rel=stylesheet href=https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.6/css/all.min.css>
<link rel=stylesheet href=https://cdn.jsdelivr.net/npm/dna-engine@3.2/dist/dna-engine.css>
<link rel=stylesheet href=https://cdn.jsdelivr.net/npm/dna-engine@3.2/dist/panel-nav.css>
<link rel=stylesheet href=https://cdn.jsdelivr.net/npm/web-ignition@2.2/dist/reset.min.css>
Expand Down

0 comments on commit cbc5600

Please sign in to comment.