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 f738b11 commit 04d6ba2
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 33 deletions.
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
},
},
];
2 changes: 1 addition & 1 deletion hello-world/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"assert-deep-strict-equal": "~1.2",
"fetch-json": "~3.3",
"jshint": "~2.13",
"mocha": "~10.4",
"mocha": "~10.7",
"server-listening": "~1.2"
}
}
37 changes: 9 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,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 @@ -86,22 +67,22 @@
"jsdom": "~24.1"
},
"devDependencies": {
"@eslint/js": "~9.3",
"@eslint/js": "~9.9",
"@types/express": "~4.17",
"@types/jsdom": "~21.1",
"@types/node": "~20.12",
"@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",
"eslint": "8.57.0",
"eslint": "~9.9",
"fetch-json": "~3.3",
"jshint": "~2.13",
"mocha": "~10.4",
"rimraf": "~5.0",
"run-scripts-util": "~1.2",
"typescript": "~5.4",
"typescript-eslint": "~7.11",
"mocha": "~10.7",
"rimraf": "~6.0",
"run-scripts-util": "~1.3",
"typescript": "~5.5",
"typescript-eslint": "~8.1",
"w3c-html-validator": "~1.8"
}
}
6 changes: 3 additions & 3 deletions server-listening.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ const serverListening = {
return new Promise(resolve => server.close(resolve));
},
jsdomOnLoad(dom: JSDOM): Promise<JSDOM> {
const name = dom && dom.constructor && dom.constructor.name;
const name = (<unknown>dom)?.constructor?.name;
if (name !== 'JSDOM')
throw Error(`[server-listening] Unable to load DOM: ${name} => ${String(dom)}`);
throw new Error(`[server-listening] Unable to load DOM: ${String(dom)} => ${name}`);
let done: (jsdom: JSDOM) => void;
dom.window.onload = () => done(dom);
return new Promise(resolve => done = resolve);
},
jsdomCloseWindow(dom: JSDOM): Promise<JSDOM> {
if (dom)
if (<unknown>dom)
dom.window.close();
return new Promise(resolve => resolve(dom));
},
Expand Down
2 changes: 1 addition & 1 deletion spec/package.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('The jsdomOnLoad() function', () => {

it('throws an error if the DOM is missing', () => {
const callhandleDom = () => serverListening.jsdomOnLoad(null);
const exception = { message: '[server-listening] Unable to load DOM: null => null' };
const exception = { message: '[server-listening] Unable to load DOM: null => undefined' };
assert.throws(callhandleDom, exception);
});

Expand Down

0 comments on commit 04d6ba2

Please sign in to comment.