From efb0b936a34af895a66720660f49e3cb01d7f3d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Wed, 10 Jul 2024 16:09:28 +0200 Subject: [PATCH] chore: update ESLint to v9 (#1064) Do Prettier linting separately as recommendeded. --- .eslintrc.yml | 25 ----------------------- .github/workflows/nodejs.yml | 2 +- .prettierignore | 2 ++ CONTRIBUTING.md | 6 +++--- eslint.config.js | 39 ++++++++++++++++++++++++++++++++++++ lib/lookup.js | 2 +- lib/lookup.json | 2 +- lib/package-manager/test.js | 2 +- package.json | 13 ++++++++---- test/fixtures/.eslintrc.yml | 2 -- test/fixtures/package.json | 2 +- 11 files changed, 58 insertions(+), 39 deletions(-) delete mode 100644 .eslintrc.yml create mode 100644 .prettierignore create mode 100644 eslint.config.js delete mode 100644 test/fixtures/.eslintrc.yml diff --git a/.eslintrc.yml b/.eslintrc.yml deleted file mode 100644 index 963cc9d5d..000000000 --- a/.eslintrc.yml +++ /dev/null @@ -1,25 +0,0 @@ -env: - node: true - es6: true -parserOptions: - sourceType: module - ecmaVersion: 2020 - -rules: - eqeqeq: [error, always] - no-useless-escape: error - capitalized-comments: [error, always, { ignoreConsecutiveComments: true }] - strict: error - no-var: error - prefer-template: error - no-template-curly-in-string: error - prefer-arrow-callback: error - padding-line-between-statements: - - error - - { blankLine: always, prev: directive, next: '*' } - # Rule is buggy: https://github.com/eslint/eslint/issues/11899 - require-atomic-updates: off - -extends: - - eslint:recommended - - plugin:prettier/recommended diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index eb72b9496..d0d886f2f 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -8,7 +8,7 @@ on: jobs: lint: - name: Lint using ESLint + name: Lint using ESLint and Prettier runs-on: ubuntu-latest diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000..8dc4ccbb3 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,2 @@ +/README.md +/test/fixtures/custom-lookup-broken.json diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 322156026..15c77bfc3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -52,9 +52,9 @@ This is for adding a module to be included in the default `citgm-all` runs. - Module source code must be on Github. - Published versions must include a tag on Github - The test process must be executable with only the commands - `npm install && npm test` or (`yarn install && yarn test` - or `pnpm install && pnpm test`) using the tarball - downloaded from the Github tag mentioned above + `npm install && npm test` or (`yarn install && yarn test` or + `pnpm install && pnpm test`) using the tarball downloaded from the GitHub tag + mentioned above - The tests pass on supported major release lines - The maintainers of the module remain responsive when there are problems - At least one module maintainer must be added to the lookup maintainers field diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 000000000..c878f9f52 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,39 @@ +import js from '@eslint/js'; +import prettier from 'eslint-config-prettier'; +import globals from 'globals'; + +export default [ + js.configs.recommended, + prettier, + { + languageOptions: { + globals: { + ...globals.node + } + }, + rules: { + 'capitalized-comments': [ + 'error', + 'always', + { ignoreConsecutiveComments: true } + ], + eqeqeq: ['error', 'always'], + 'no-template-curly-in-string': 'error', + 'no-useless-escape': 'error', + 'no-var': 'error', + 'padding-line-between-statements': [ + 'error', + { blankLine: 'always', prev: 'directive', next: '*' } + ], + 'prefer-arrow-callback': 'error', + 'prefer-template': 'error', + strict: 'error' + } + }, + { + files: ['test/fixtures/**'], + languageOptions: { + sourceType: 'commonjs' + } + } +]; diff --git a/lib/lookup.js b/lib/lookup.js index f2586bc66..349217850 100644 --- a/lib/lookup.js +++ b/lib/lookup.js @@ -78,7 +78,7 @@ export function getLookupTable(options) { } return lookup; - } catch (err) { + } catch { return undefined; } } diff --git a/lib/lookup.json b/lib/lookup.json index 13530b1f0..b20adaee9 100644 --- a/lib/lookup.json +++ b/lib/lookup.json @@ -312,7 +312,7 @@ "scripts": ["rebuild-tests", "test"], "tags": "native", "head": true, - "skip": [ "win32", "aix", "s390x"], + "skip": ["win32", "aix", "s390x"], "comment": "Skipped while a proper solution is found" }, "node-gyp": { diff --git a/lib/package-manager/test.js b/lib/package-manager/test.js index 25e7aaa07..93328cffd 100644 --- a/lib/package-manager/test.js +++ b/lib/package-manager/test.js @@ -35,7 +35,7 @@ export async function test(packageManager, context) { data = await readPackage(join(wd, 'package.json'), false); // Explicitly set the version to the value in the downloaded package.json. context.module.version = data.version; - } catch (err) { + } catch { throw new Error('Package.json Could not be found'); } if ( diff --git a/package.json b/package.json index be5fa0f94..29966cc56 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,11 @@ "lib" ], "scripts": { - "lint": "eslint bin/* lib/ test/ --cache", + "lint": "npm run lint:eslint && npm run lint:prettier", + "lint:eslint": "eslint . --cache", + "lint:eslint:fix": "npm run eslint -- --fix", + "lint:prettier": "prettier --check .", + "lint:prettier:fix": "prettier --write .", "tap": "tap run \"test/**/test-*.js\"", "test": "npm run lint && npm run tap" }, @@ -56,11 +60,12 @@ "yarn": "^1.22.21" }, "devDependencies": { + "@eslint/js": "^9.6.0", "ansi-regex": "^6.0.1", - "eslint": "^8.56.0", + "eslint": "^9.6.0", "eslint-config-prettier": "^9.1.0", - "eslint-plugin-prettier": "^5.1.3", - "prettier": "^3.1.1", + "globals": "^15.8.0", + "prettier": "^3.3.2", "string-to-stream": "^3.0.1", "tap": "^18.6.1", "tap-parser": "^15.3.1", diff --git a/test/fixtures/.eslintrc.yml b/test/fixtures/.eslintrc.yml deleted file mode 100644 index 8e5f26e3b..000000000 --- a/test/fixtures/.eslintrc.yml +++ /dev/null @@ -1,2 +0,0 @@ -parserOptions: - sourceType: script diff --git a/test/fixtures/package.json b/test/fixtures/package.json index 9e26dfeeb..0967ef424 100644 --- a/test/fixtures/package.json +++ b/test/fixtures/package.json @@ -1 +1 @@ -{} \ No newline at end of file +{}