Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: drop eslint v7 & node.js < 18 #161

Merged
merged 12 commits into from
Jan 8, 2024
12 changes: 3 additions & 9 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,19 @@ jobs:
node: [18.x, 20.x]
include:
aladdin-add marked this conversation as resolved.
Show resolved Hide resolved
- os: ubuntu-latest
node: "16.0.x"
eslint: "8.x"
- os: ubuntu-latest
node: "16.x"
eslint: "8.x"
- os: ubuntu-latest
node: "19.x"
node: "21.x"
eslint: "8.x"
- os: ubuntu-latest
node: "20.x"
eslint: "7.0.x"
eslint: "9.0.0-alpha.0"
scagood marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ${{ matrix.os }}
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: Install Packages
Expand Down
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 | `Node.js:^18.18.0 \|\| ^20.9.0 \|\| >=21.1.0` | `ESLint>=8.23.0` |
| 16.x | `Node.js>=16.0.0` | `ESLint>=7.0.0` |
| 15.x | `Node.js>=12.22.0` | `ESLint>=7.0.0` |
aladdin-add marked this conversation as resolved.
Show resolved Hide resolved

**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.
scagood marked this conversation as resolved.
Show resolved Hide resolved
},
},
{
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"
}
}
41 changes: 41 additions & 0 deletions tests/eslint-rule-tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* @fileoverview Helpers for tests.
* @author 唯然<weiran.zsd@outlook.com>
*/
"use strict"
const eslintVersion = require("eslint/package.json").version
const RuleTester = require("eslint").RuleTester
const unofficialApis = require("eslint/use-at-your-own-risk")
aladdin-add marked this conversation as resolved.
Show resolved Hide resolved
const globals = require("globals")

// greater than or equal to ESLint v9
exports.gteEslintV9 = +eslintVersion.split(".")[0] >= 9
scagood marked this conversation as resolved.
Show resolved Hide resolved

exports.FlatRuleTester = exports.gteEslintV9
? RuleTester
: unofficialApis.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
Loading
Loading