Skip to content

Commit

Permalink
feat!: drop eslint v7 & node.js < 18 (#161)
Browse files Browse the repository at this point in the history
chore: switch to new rule-tester.

Signed-off-by: 唯然 <weiran.zsd@outlook.com>
Co-authored-by: Sebastian Good <2230835+scagood@users.noreply.github.com>
  • Loading branch information
aladdin-add and scagood committed Jan 8, 2024
1 parent c191101 commit 41ceed7
Show file tree
Hide file tree
Showing 45 changed files with 542 additions and 549 deletions.
21 changes: 13 additions & 8 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ on:
- cron: 0 0 * * 0

jobs:

lint:
name: Lint
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Install Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Install Packages
Expand All @@ -31,31 +33,34 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
eslint: [8.x]
eslint: [8.x, "9.0.0-alpha.0"]
node: [18.x, 20.x]
include:
- os: ubuntu-latest
node: "16.0.x"
node: "18.18.0"
eslint: "8.x"
- os: ubuntu-latest
node: "16.x"
node: "20.9.0"
eslint: "8.x"
- os: ubuntu-latest
node: "19.x"
node: "21.1.0"
eslint: "8.x"
- os: ubuntu-latest
node: "20.x"
eslint: "7.0.x"
node: "21.x"
eslint: "8.x"
runs-on: ${{ matrix.os }}
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Install Node.js ${{ matrix.node }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- name: npm latest
run: npm i -g npm@latest # use latest npm
- name: Install Packages
run: npm install
- name: Install ESLint ${{ matrix.eslint }}
Expand Down
4 changes: 3 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
registry=https://registry.npmjs.org/
registry = https://registry.npmjs.org/
package-lock = false
force = true
legacy-peer-deps = true
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ Additional ESLint rules for Node.js
npm install --save-dev eslint eslint-plugin-n
```

- Requires Node.js `>=16.0.0`
- Requires ESLint `>=7.0.0`
| Version | Supported Node.js | Supported ESLint Version |
|---------|-------------------|---------------------------|
| 17.x | `^18.18.0 \|\| ^20.9.0 \|\| >=21.1.0` | `>=8.23.0` |
| 16.x | `>=16.0.0` | `>=7.0.0` |
| 15.x | `>=12.22.0` | `>=7.0.0` |

**Note:** It recommends a use of [the "engines" field of package.json](https://docs.npmjs.com/files/package.json#engines). The "engines" field is used by `n/no-unsupported-features/*` rules.

Expand Down
7 changes: 6 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ module.exports = [
{
languageOptions: { globals: globals.mocha },
linterOptions: { reportUnusedDisableDirectives: true },
settings: {
n: { allowModules: ["#eslint-rule-tester"] }, // the plugin does not support import-maps yet.
},
},
{
ignores: [
Expand All @@ -27,7 +30,9 @@ module.exports = [
nodeRecommended,
eslintPluginConfig,
prettierConfig,
{ rules: { "eslint-plugin/require-meta-docs-description": "error" } },
{
rules: { "eslint-plugin/require-meta-docs-description": "error" },
},
{
// these messageIds were used outside
files: ["lib/rules/prefer-global/*.js"],
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"version": "16.6.1",
"description": "Additional ESLint's rules for Node.js",
"engines": {
"node": ">=16.0.0"
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
},
"main": "lib/index.js",
"files": [
"lib/",
"configs/"
],
"peerDependencies": {
"eslint": ">=7.0.0"
"eslint": ">=8.23.0"
},
"dependencies": {
"@eslint-community/eslint-utils": "^4.4.0",
Expand All @@ -31,7 +31,7 @@
"@types/eslint": "^8.44.6",
"@typescript-eslint/parser": "^5.60.0",
"esbuild": "^0.18.7",
"eslint": "^8.56.0",
"eslint": "^8",
"eslint-config-prettier": "^8.8.0",
"eslint-doc-generator": "^1.6.1",
"eslint-plugin-eslint-plugin": "^5.2.1",
Expand Down Expand Up @@ -111,5 +111,8 @@
"lint-staged": {
"*.js": "eslint --cache --fix",
"*.{json,js}": "prettier --write --ignore-path .eslintignore"
},
"imports": {
"#eslint-rule-tester": "./tests/eslint-rule-tester.js"
}
}
42 changes: 42 additions & 0 deletions tests/eslint-rule-tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @fileoverview Helpers for tests.
* @author 唯然<weiran.zsd@outlook.com>
*/
"use strict"
const eslintVersion = require("eslint/package.json").version
const { RuleTester } = require("eslint")
const { FlatRuleTester } = require("eslint/use-at-your-own-risk")
const globals = require("globals")
const semverSatisfies = require("semver/functions/satisfies")

// greater than or equal to ESLint v9
exports.gteEslintV9 = semverSatisfies(eslintVersion, ">=9", {
includePrerelease: true,
})

exports.FlatRuleTester = exports.gteEslintV9 ? RuleTester : FlatRuleTester

// to support the `env:{ es6: true, node: true}` rule-tester (env has been away in flat config.)
// * enabled by default as it's most commonly used in the package.
// * to disable the node.js globals: {languageOptions: {env: {node: false}}}.
const defaultConfig = {
languageOptions: {
ecmaVersion: 6,
sourceType: "commonjs",
globals: globals.node,
},
}
exports.RuleTester = function (config = defaultConfig) {
if (config.languageOptions.env?.node === false)
config.languageOptions.globals = config.languageOptions.globals || {}
delete config.languageOptions.env

config.languageOptions = Object.assign(
{},
defaultConfig.languageOptions,
config.languageOptions
)

const ruleTester = new exports.FlatRuleTester(config)
return ruleTester
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

const assert = require("assert")
const path = require("path")
const { ESLint } = require("eslint")
const { LegacyESLint } = require("eslint/use-at-your-own-risk")
// const {ESLint} = require("eslint")
const { gtEslintV8 } = require("../../helpers")

const originalCwd = process.cwd()

// this is needed as `recommended` config was cached
Expand All @@ -24,7 +24,7 @@ describe("node/recommended config", () => {
beforeEach(() => {
process.chdir(root)
clearRequireCache()
linter = new ESLint({
linter = new LegacyESLint({
baseConfig: { extends: "plugin:n/recommended" },
useEslintrc: false,
})
Expand Down Expand Up @@ -102,7 +102,7 @@ describe("node/recommended config", () => {
beforeEach(() => {
process.chdir(root)
clearRequireCache()
linter = new ESLint({
linter = new LegacyESLint({
baseConfig: { extends: "plugin:n/recommended" },
useEslintrc: false,
})
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/rules/callback-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*/
"use strict"

const RuleTester = require("eslint").RuleTester
const RuleTester = require("#eslint-rule-tester").RuleTester
const rule = require("../../../lib/rules/callback-return")
const ruleTester = new RuleTester({ env: { node: true, es6: true } })
const ruleTester = new RuleTester()

ruleTester.run("callback-return", rule, {
valid: [
Expand Down

0 comments on commit 41ceed7

Please sign in to comment.