Skip to content

Commit

Permalink
Update to ESLint 9, support flat config, and require Node.js 18 (#175)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
prantlf and sindresorhus authored Apr 11, 2024
1 parent 0704be0 commit 81834b4
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 26 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ jobs:
fail-fast: false
matrix:
node-version:
- 16
- 14
- 12
- 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
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.');
}
}
}
};
};
}
};
9 changes: 7 additions & 2 deletions gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
'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
10 changes: 7 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ 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 +50,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 81834b4

Please sign in to comment.