Skip to content

Commit

Permalink
feat!: requires node >= 18 & eslint >= 8.23.0 (#456)
Browse files Browse the repository at this point in the history
* feat!: required node >= 18 & eslint >= 8.23.0

* chore: switch to eslint flat-rule-tester

* build: split eslint-rule-tester

* build: fix npm install

* fix: npm scripts order

* fix: revert unexpected tests changes

* fix: npm scripts order

* chore: eslint-plugin-n v17.0.0
  • Loading branch information
aladdin-add authored Apr 9, 2024
1 parent dcb794f commit 4adeb6c
Show file tree
Hide file tree
Showing 33 changed files with 215 additions and 133 deletions.
28 changes: 19 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@ jobs:
fail-fast: false
matrix:
node-version:
- 21
- 20
- 18
- 16
- 14
os:
- ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm install --force # ts-eslint does not support eslint v9 yet.
- run: npm test

lint:
Expand All @@ -32,18 +31,29 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "18.x"
- run: npm install
node-version: "lts/*"
- run: npm install --force # ts-eslint does not support eslint v9 yet.
- run: npm run lint

eslint7:
eslint8:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "18.x"
- run: npm install
- run: npm install --save-dev eslint@7
node-version: "lts/*"
- run: npm install --force # ts-eslint does not support eslint v9 yet.
- run: npm install --save-dev eslint@8
- run: npm test

test-remote:
name: eslint-remote-tester
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "lts/*"
- run: npm install --force # ts-eslint does not support eslint v9 yet.
- run: npm install --save-dev eslint@8 # eslint-remote-tester does not support eslint v9.
- run: npm run test:remote
9 changes: 6 additions & 3 deletions lib/rules/no-unused-placeholders.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,12 @@ module.exports = {
const PLACEHOLDER_MATCHER = /{{\s*([^{}]+?)\s*}}/g;
const placeholdersInMessage = new Set();

messageValue.replace(PLACEHOLDER_MATCHER, (fullMatch, term) => {
placeholdersInMessage.add(term);
});
messageValue.replaceAll(
PLACEHOLDER_MATCHER,
(fullMatch, term) => {
placeholdersInMessage.add(term);
}
);

data.properties.forEach((prop) => {
const key = utils.getKeyName(prop);
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/require-meta-docs-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = {
const expectedUrl =
!options.pattern || !ruleName
? undefined
: options.pattern.replace(/{{\s*name\s*}}/g, ruleName);
: options.pattern.replaceAll(/{{\s*name\s*}}/g, ruleName);

/**
* Check whether a given URL is the expected URL.
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ module.exports = {
return fixer.replaceText(node, `{\n${propertyText}\n}`);
}
return fixer.insertTextAfter(
sourceCode.getLastToken(node.properties[node.properties.length - 1]),
sourceCode.getLastToken(node.properties.at(-1)),
`,\n${propertyText}`
);
},
Expand Down
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"lint:js": "eslint --cache --ignore-pattern \"**/*.md\" .",
"lint:js-docs": "eslint --no-inline-config \"**/*.md\"",
"lint:package-json": "npmPkgJsonLint .",
"lint:remote": "eslint-remote-tester",
"release": "release-it",
"test": "nyc --all --check-coverage --include lib mocha tests --recursive",
"test:remote": "eslint-remote-tester",
"update:eslint-docs": "eslint-doc-generator"
},
"files": [
Expand Down Expand Up @@ -52,29 +52,29 @@
"devDependencies": {
"@commitlint/cli": "^17.1.2",
"@commitlint/config-conventional": "^17.1.0",
"@eslint/eslintrc": "^2.0.2",
"@eslint/js": "^8.57.0",
"@eslint/eslintrc": "^3.0.2",
"@eslint/js": "^9.0.0",
"@release-it/conventional-changelog": "^4.3.0",
"@types/eslint": "^8.56.6",
"@types/eslint": "^8.56.7",
"@types/estree": "^1.0.5",
"@typescript-eslint/parser": "^5.62.0",
"@typescript-eslint/utils": "^5.62.0",
"@typescript-eslint/parser": "^7.5.0",
"@typescript-eslint/utils": "^7.5.0",
"chai": "^4.3.6",
"dirty-chai": "^2.0.1",
"eslint": "^8.57.0",
"eslint": "^9.0.0",
"eslint-config-not-an-aardvark": "^2.1.0",
"eslint-config-prettier": "^8.5.0",
"eslint-doc-generator": "^1.7.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-eslint-plugin": "file:./",
"eslint-plugin-markdown": "^3.0.0",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-n": "^17.0.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-unicorn": "^46.0.0",
"eslint-plugin-unicorn": "^52.0.0",
"eslint-remote-tester": "^3.0.1",
"eslint-scope": "^7.1.1",
"espree": "^9.4.0",
"globals": "^13.20.0",
"eslint-scope": "^8.0.1",
"espree": "^10.0.1",
"globals": "^15.0.0",
"husky": "^8.0.1",
"lodash": "^4.17.21",
"markdownlint-cli": "^0.39.0",
Expand All @@ -87,10 +87,10 @@
"typescript": "^5.4.3"
},
"peerDependencies": {
"eslint": ">=7.0.0"
"eslint": ">=8.23.0"
},
"engines": {
"node": "^14.17.0 || ^16.0.0 || >= 18.0.0"
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
},
"release-it": {
"git": {
Expand Down
15 changes: 15 additions & 0 deletions tests/lib/eslint-rule-tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @fileoverview Helpers for tests.
* @author 唯然<[email protected]>
*/

'use strict';

const eslintVersion = require('eslint/package.json').version;
const { RuleTester } = require('eslint');
const { FlatRuleTester } = require('eslint/use-at-your-own-risk');

// greater than or equal to ESLint v9
exports.gteEslintV9 = +eslintVersion.split('.')[0] >= 9;

exports.RuleTester = exports.gteEslintV9 ? RuleTester : FlatRuleTester;
6 changes: 4 additions & 2 deletions tests/lib/rules/consistent-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@
// ------------------------------------------------------------------------------

const rule = require('../../../lib/rules/consistent-output');
const RuleTester = require('eslint').RuleTester;
const RuleTester = require('../eslint-rule-tester').RuleTester;

const ERROR = { messageId: 'missingOutput', type: 'ObjectExpression' };

// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------

const ruleTester = new RuleTester();
const ruleTester = new RuleTester({
languageOptions: { sourceType: 'commonjs' },
});
ruleTester.run('consistent-output', rule, {
valid: [
`
Expand Down
6 changes: 4 additions & 2 deletions tests/lib/rules/fixer-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
// ------------------------------------------------------------------------------

const rule = require('../../../lib/rules/fixer-return');
const RuleTester = require('eslint').RuleTester;
const RuleTester = require('../eslint-rule-tester').RuleTester;

// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------

const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } });
const ruleTester = new RuleTester({
languageOptions: { sourceType: 'commonjs' },
});
ruleTester.run('fixer-return', rule, {
valid: [
`
Expand Down
10 changes: 6 additions & 4 deletions tests/lib/rules/meta-property-ordering.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
// ------------------------------------------------------------------------------

const rule = require('../../../lib/rules/meta-property-ordering');
const RuleTester = require('eslint').RuleTester;
const RuleTester = require('../eslint-rule-tester').RuleTester;

// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------

const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } });
const ruleTester = new RuleTester({
languageOptions: { sourceType: 'commonjs' },
});
ruleTester.run('test-case-property-ordering', rule, {
valid: [
`
Expand All @@ -31,7 +33,7 @@ ruleTester.run('test-case-property-ordering', rule, {
meta: {type, docs, fixable, schema, messages},
create() {},
};`,
parserOptions: { sourceType: 'module' },
languageOptions: { sourceType: 'module' },
},

`
Expand Down Expand Up @@ -124,13 +126,13 @@ ruleTester.run('test-case-property-ordering', rule, {
},
create() {},
};`,
parserOptions: { sourceType: 'module' },
errors: [
{
messageId: 'inconsistentOrder',
data: { order: ['type', 'docs', 'fixable'].join(', ') },
},
],
languageOptions: { sourceType: 'module' },
},
{
code: `
Expand Down
6 changes: 4 additions & 2 deletions tests/lib/rules/no-deprecated-context-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
// ------------------------------------------------------------------------------

const rule = require('../../../lib/rules/no-deprecated-context-methods');
const RuleTester = require('eslint').RuleTester;
const RuleTester = require('../eslint-rule-tester').RuleTester;

// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------

const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } });
const ruleTester = new RuleTester({
languageOptions: { sourceType: 'commonjs' },
});
ruleTester.run('no-deprecated-context-methods', rule, {
valid: [
`
Expand Down
6 changes: 4 additions & 2 deletions tests/lib/rules/no-deprecated-report-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
// ------------------------------------------------------------------------------

const rule = require('../../../lib/rules/no-deprecated-report-api');
const RuleTester = require('eslint').RuleTester;
const RuleTester = require('../eslint-rule-tester').RuleTester;

// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------

const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } });
const ruleTester = new RuleTester({
languageOptions: { sourceType: 'commonjs' },
});
ruleTester.run('no-deprecated-report-api', rule, {
valid: [
`
Expand Down
8 changes: 5 additions & 3 deletions tests/lib/rules/no-identical-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// ------------------------------------------------------------------------------

const rule = require('../../../lib/rules/no-identical-tests');
const RuleTester = require('eslint').RuleTester;
const RuleTester = require('../eslint-rule-tester').RuleTester;

const ERROR_OBJECT_TEST = { messageId: 'identical', type: 'ObjectExpression' };
const ERROR_STRING_TEST = { messageId: 'identical', type: 'Literal' };
Expand All @@ -19,7 +19,9 @@ const ERROR_STRING_TEST = { messageId: 'identical', type: 'Literal' };
// Tests
// ------------------------------------------------------------------------------

const ruleTester = new RuleTester();
const ruleTester = new RuleTester({
languageOptions: { sourceType: 'commonjs' },
});
ruleTester.run('no-identical-tests', rule, {
valid: [
`
Expand Down Expand Up @@ -232,8 +234,8 @@ ruleTester.run('no-identical-tests', rule, {
});
}
`,
parserOptions: { ecmaVersion: 2015 },
errors: [{ messageId: 'identical', type: 'TemplateLiteral' }],
languageOptions: { ecmaVersion: 2015 },
},
],
});
10 changes: 6 additions & 4 deletions tests/lib/rules/no-missing-message-ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
// ------------------------------------------------------------------------------

const rule = require('../../../lib/rules/no-missing-message-ids');
const RuleTester = require('eslint').RuleTester;
const RuleTester = require('../eslint-rule-tester').RuleTester;

// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------

const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 9 } });
const ruleTester = new RuleTester({
languageOptions: { sourceType: 'commonjs' },
});

ruleTester.run('no-missing-message-ids', rule, {
valid: [
Expand Down Expand Up @@ -75,7 +77,7 @@ ruleTester.run('no-missing-message-ids', rule, {
}
};
`,
parserOptions: { sourceType: 'module' },
languageOptions: { sourceType: 'module' },
},
// unrelated function 1
`
Expand Down Expand Up @@ -321,14 +323,14 @@ ruleTester.run('no-missing-message-ids', rule, {
}
};
`,
parserOptions: { sourceType: 'module' },
errors: [
{
messageId: 'missingMessage',
data: { messageId: 'foo' },
type: 'Literal',
},
],
languageOptions: { sourceType: 'module' },
},
{
// Helper function with messageId parameter, inside rule, with missing messageId due to parameter reassignment.
Expand Down
6 changes: 4 additions & 2 deletions tests/lib/rules/no-missing-placeholders.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// ------------------------------------------------------------------------------

const rule = require('../../../lib/rules/no-missing-placeholders');
const RuleTester = require('eslint').RuleTester;
const RuleTester = require('../eslint-rule-tester').RuleTester;

/**
* Create an error for the given key
Expand All @@ -29,7 +29,9 @@ function error(missingKey, type, extra) {
// Tests
// ------------------------------------------------------------------------------

const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } });
const ruleTester = new RuleTester({
languageOptions: { sourceType: 'commonjs' },
});
ruleTester.run('no-missing-placeholders', rule, {
valid: [
`
Expand Down
Loading

0 comments on commit 4adeb6c

Please sign in to comment.