From 65ac4b506b71d649f899d43f3a99a74d4cf33ade Mon Sep 17 00:00:00 2001 From: Ferdinand Prantl Date: Wed, 10 Apr 2024 07:36:58 +0200 Subject: [PATCH 1/4] Upgrade to ESLint 9, flatconfig and Node.js 18 (#173) Upgrade the eslint dependency. Change the documentation and tests to use the new configuration format. Also, upgrade Node.js in the build pipeline. > When ESLint v10.0.0 is released (end of 2024 or early 2025 in all likelihood), the eslintrc configuration system will be completely removed. https://eslint.org/blog/2023/10/flat-config-rollout-plans/#eslintrc-removed-in-eslint-v10.0.0 * Describe and test the usage only with flatconfig. It'll be the only config format soon. Who needs to retain `.eslintrc` can stay with eslint 8. * ESLint 9 supports only Node.js `^18.18.0 || ^20.9.0 || >=21.1.0`. * The formatter `eslint-tap` works, but because it doesn't follow the NPM package naming convention `eslint-formatter-*`, it has to be specified using a path to the script with the main exports. --- .github/workflows/main.yml | 5 ++--- conf/eslint.js | 8 ++++++++ conf/eslint.json | 6 ------ conf/rules/no-alert.js | 16 +++++++++------- gruntfile.js | 7 +++++-- package.json | 6 +++--- readme.md | 8 +++++--- 7 files changed, 32 insertions(+), 24 deletions(-) create mode 100644 conf/eslint.js delete mode 100644 conf/eslint.json diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3b8aa864..4d6b3da6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,9 +10,8 @@ jobs: fail-fast: false matrix: node-version: - - 16 - - 14 - - 12 + - 20 + - 18 steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 diff --git a/conf/eslint.js b/conf/eslint.js new file mode 100644 index 00000000..7a1f2c29 --- /dev/null +++ b/conf/eslint.js @@ -0,0 +1,8 @@ +module.exports = [ + { + rules: { + 'no-alert': 1, + 'camelcase': 2 + } + } +]; diff --git a/conf/eslint.json b/conf/eslint.json deleted file mode 100644 index b1ccfef6..00000000 --- a/conf/eslint.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "rules": { - "no-alert": 1, - "camelcase": 2 - } -} diff --git a/conf/rules/no-alert.js b/conf/rules/no-alert.js index 930d0a29..c126c278 100644 --- a/conf/rules/no-alert.js +++ b/conf/rules/no-alert.js @@ -1,10 +1,12 @@ 'use strict'; -module.exports = function (context) { - return { - CallExpression(node) { - if (node.callee.name === 'alert') { - context.report(node, 'testing custom rules.'); +module.exports = { + create(context) { + return { + CallExpression(node) { + if (node.callee.name === 'alert') { + context.report(node, 'testing custom rules.'); + } } - } - }; + }; + } }; diff --git a/gruntfile.js b/gruntfile.js index 92f22233..096191a8 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -1,10 +1,13 @@ 'use strict'; + +const noAlertRule = require('./conf/rules/no-alert'); + module.exports = grunt => { grunt.initConfig({ eslint: { options: { - overrideConfigFile: 'conf/eslint.json', - rulePaths: ['conf/rules'], + overrideConfigFile: 'conf/eslint.js', + plugins: { noAlertRule }, quiet: true }, validate: ['test/fixture/{1,2}.js'] diff --git a/package.json b/package.json index 9c5895ba..6aa49867 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "url": "https://sindresorhus.com" }, "engines": { - "node": ">=12" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "scripts": { "test": "grunt" @@ -28,10 +28,10 @@ ], "dependencies": { "chalk": "^4.1.2", - "eslint": "^8.44.0" + "eslint": "^9.0.0" }, "devDependencies": { - "grunt": "^1.0.1", + "grunt": "^1.6.1", "grunt-cli": "^1.4.3", "grunt-shell": "^4.0.0" }, diff --git a/readme.md b/readme.md index f852f349..467ea92c 100644 --- a/readme.md +++ b/readme.md @@ -29,11 +29,13 @@ grunt.registerTask('default', ['eslint']); ### Custom config and rules ```js +const noAlertRule = require('./conf/rules/no-alert'); + grunt.initConfig({ eslint: { options: { - overrideConfigFile: 'conf/eslint.json', - rulePaths: ['conf/rules'] + overrideConfigFile: 'conf/eslint.js', + plugins: { noAlertRule } }, target: ['file.js'] } @@ -46,7 +48,7 @@ grunt.initConfig({ grunt.initConfig({ eslint: { options: { - format: require('eslint-tap') + format: './node_modules/eslint-tap/index.js' }, target: ['file.js'] } From 2adc6f33b002d071bd0bf9ec3125d340012b86cc Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 11 Apr 2024 19:42:20 +0900 Subject: [PATCH 2/4] Update main.yml --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4d6b3da6..346585cf 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,8 +13,8 @@ jobs: - 20 - 18 steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - run: npm install From b90875403cef9e0bb18e27a12e8e6c24955e7ed8 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 11 Apr 2024 19:43:09 +0900 Subject: [PATCH 3/4] Update gruntfile.js --- gruntfile.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gruntfile.js b/gruntfile.js index 096191a8..0cde514d 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -7,7 +7,9 @@ module.exports = grunt => { eslint: { options: { overrideConfigFile: 'conf/eslint.js', - plugins: { noAlertRule }, + plugins: { + noAlertRule + }, quiet: true }, validate: ['test/fixture/{1,2}.js'] From de61bef35e060c7c14612e14a7e077cf8486cbb8 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 11 Apr 2024 19:43:23 +0900 Subject: [PATCH 4/4] Update readme.md --- readme.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 467ea92c..241bb7d5 100644 --- a/readme.md +++ b/readme.md @@ -35,7 +35,9 @@ grunt.initConfig({ eslint: { options: { overrideConfigFile: 'conf/eslint.js', - plugins: { noAlertRule } + plugins: { + noAlertRule + } }, target: ['file.js'] }