Skip to content

Commit

Permalink
Upgrade to ESLint 9, flatconfig and Node.js 18 (#173)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
prantlf committed Apr 10, 2024
1 parent 0704be0 commit 65ac4b5
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 24 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions conf/eslint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = [
{
rules: {
'no-alert': 1,
'camelcase': 2
}
}
];
6 changes: 0 additions & 6 deletions conf/eslint.json

This file was deleted.

16 changes: 9 additions & 7 deletions conf/rules/no-alert.js
Original file line number Diff line number Diff line change
@@ -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.');
}
}
}
};
};
}
};
7 changes: 5 additions & 2 deletions gruntfile.js
Original file line number Diff line number Diff line change
@@ -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']
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=12"
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
},
"scripts": {
"test": "grunt"
Expand All @@ -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"
},
Expand Down
8 changes: 5 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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']
}
Expand All @@ -46,7 +48,7 @@ grunt.initConfig({
grunt.initConfig({
eslint: {
options: {
format: require('eslint-tap')
format: './node_modules/eslint-tap/index.js'
},
target: ['file.js']
}
Expand Down

0 comments on commit 65ac4b5

Please sign in to comment.