Skip to content

Commit

Permalink
breaking: drop eslint < 8.57.1; add v9
Browse files Browse the repository at this point in the history
  • Loading branch information
yutak23 authored and ljharb committed Sep 27, 2024
1 parent d275043 commit 4cc38cb
Show file tree
Hide file tree
Showing 29 changed files with 438 additions and 102 deletions.
17 changes: 3 additions & 14 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,10 @@ jobs:
node-version: ${{ fromJson(needs.matrix.outputs.majors) }}
eslint:
- 8
- 7
include:
- node-version: 14
eslint: 7.7
- 9
exclude:
- node-version: 15
eslint: 8
- node-version: 13
eslint: 8
- node-version: 11
eslint: 8
- node-version: 10
eslint: 8
- node-version: 19
eslint: 9

steps:
- uses: actions/checkout@v2
Expand All @@ -48,8 +39,6 @@ jobs:
node-version: ${{ matrix.node-version }}
skip-ls-check: true
- run: npm install --no-save eslint@${{ matrix.eslint }}
- run: npm install --no-save @eslint/eslintrc@0
if: ${{ matrix.eslint != 8 }}
- run: npm prune > /dev/null
- run: npm ls > /dev/null
- run: npm run cover
Expand Down
45 changes: 45 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const globals = require('globals');
const js = require('@eslint/js')
const json = require('eslint-plugin-json');

module.exports = [
{
files: [
"**/*.js",
"**/*.mjs",
"**/*.cjs",
],
...js.configs.recommended,

languageOptions: {
globals: {
...globals.commonjs,
...globals.es2015,
...globals.node,
},
parserOptions: {
ecmaVersion: 2022,
},
},
},
{
files: ['test/**/*.js'],
languageOptions: {
globals: {
...globals.mocha,
},
},
},
{
ignores: [
'node_modules/**',
'coverage/**',
'.nyc_output/**',
'dist/**',
],
},
{
files: ['**/*.json'],
...json.configs.recommended,
},
];
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
},
"scripts": {
"cover": "nyc --reporter=lcov --reporter=text --reporter=html npm run tests-only",
"lint": "eslint --ext .js,.json .",
"lint": "eslint .",
"pretest": "npm run lint",
"tests-only": "mocha --recursive",
"tests-only": "mocha 'test/bin/**/*.js' 'test/lib/**/*.js' --recursive",
"test": "npm run tests-only",
"posttest": "npx npm@'>=10.2' audit --production",
"update-contributors": "all-contributors generate",
Expand Down Expand Up @@ -42,18 +42,23 @@
"yargs": "^16.2.0"
},
"devDependencies": {
"@eslint/js": "^9.11.1",
"all-contributors-cli": "^4.11.2",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.7.0",
"codecov": "^2.3.1",
"commitizen": "^2.10.1",
"create-require": "^1.1.1",
"cz-conventional-changelog": "^2.1.0",
"eslint": "^7 || ^8.2.0",
"eslint-plugin-json": "^3.1.0",
"eslint": "^8.57.1 || ^9.14.0",
"eslint-plugin-json": "^4.0.1",
"ghooks": "^2.0.4",
"globals": "^15.9.0",
"in-publish": "^2.0.1",
"lodash.merge": "^4.6.2",
"mocha": "^3.5.3",
"npm-run-all": "^4.1.5",
"nyc": "^11.9.0",
Expand All @@ -65,7 +70,7 @@
"validate-commit-msg": "^2.14.0"
},
"peerDependencies": {
"eslint": "^7 || ^8.2.0"
"eslint": "^8.57.1 || ^9.14.0"
},
"nyc": {
"exclude": [
Expand Down
1 change: 1 addition & 0 deletions src/lib/normalize-plugin-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function _getNormalizer() {

return eslintNaming;
}
// eslint-disable-next-line no-unused-vars, no-empty
} catch (err) {
}
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/object-diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function compare(diff, a, b) {
if (!diff[n]) {
try {
assert.deepEqual(a[n], b[n]);
// eslint-disable-next-line no-unused-vars
} catch (err) {
diff[n] = {
config1: a[n],
Expand Down
11 changes: 6 additions & 5 deletions src/lib/rule-finder.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ let builtinRules, FlatESLint;
try {
const eslintInternal = require('eslint/use-at-your-own-risk');
builtinRules = eslintInternal.builtinRules;
FlatESLint = eslintInternal.FlatESLint;
FlatESLint = ESLint.configType === 'flat' ? ESLint : eslintInternal.FlatESLint;
// eslint-disable-next-line no-empty, no-unused-vars
} catch (e) {}

function _loadEslint(options, useFlatConfig) {
Expand Down Expand Up @@ -51,10 +52,10 @@ async function _getConfigs(overrideConfigFile, files, useFlatConfig) {

async function _getConfig(configFile, files, useFlatConfig) {
return Array.from(await _getConfigs(configFile, files, useFlatConfig)).reduce((prev, item) => {
const plugins = useFlatConfig
const plugins = useFlatConfig || ESLint.configType === 'flat'
? Object.assign({}, prev.plugins, item.plugins)
: [...new Set([].concat(prev.plugins || [], item.plugins || []))]

return Object.assign(prev, item, {
rules: Object.assign({}, prev.rules, item.rules),
plugins
Expand All @@ -79,7 +80,7 @@ function _getPluginRules(config, useFlatConfig) {
const plugins = config.plugins;
/* istanbul ignore else */
if (plugins) {
if (useFlatConfig) {
if (useFlatConfig || ESLint.configType === 'flat') {
Object.entries(config.plugins)
.filter(([, { rules }]) => rules)
.forEach(([pluginName, { rules }]) => {
Expand Down Expand Up @@ -167,7 +168,7 @@ function RuleFinder(config, {omitCore, includeDeprecated, useFlatConfig}) {
async function createRuleFinder(specifiedFile, options) {
const configFile = _getConfigFile(specifiedFile);

const {ext = ['.js']} = options;
const {ext = ['.js', '.cjs', '.mjs']} = options;
const extensionRegExp = _createExtensionRegExp(ext);
const files = glob.sync(`**/*`, {dot: true, matchBase: true})
.filter(file => extensionRegExp.test(file));
Expand Down
5 changes: 0 additions & 5 deletions test/.eslintrc

This file was deleted.

12 changes: 12 additions & 0 deletions test/fixtures/post-v8/eslint-dedupe-plugin-rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const eslintrc = require('./eslintrc');
const merge = require('lodash/merge');
const plugin = require('eslint-plugin-plugin');

module.exports = merge(eslintrc, {
plugins: {
plugin
},
rules: {
"plugin/duplicate-bar-rule": [2]
}
});
34 changes: 34 additions & 0 deletions test/fixtures/post-v8/eslint-with-deprecated-rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const plugin = require('eslint-plugin-plugin');
const scopeEslintPluginScopedPlugin = require('@scope/eslint-plugin-scoped-plugin');
const scope = require('@scope/eslint-plugin');
const scopeWithDashEslintPluginScopedWithDashPlugin = require('@scope-with-dash/eslint-plugin-scoped-with-dash-plugin');
const scopeWithDash = require('@scope-with-dash/eslint-plugin');

module.exports = {
plugins: {
plugin,
'@scope/scoped-plugin': scopeEslintPluginScopedPlugin,
'@scope': scope,
'@scope-with-dash/scoped-with-dash-plugin': scopeWithDashEslintPluginScopedWithDashPlugin,
'@scope-with-dash': scopeWithDash
},
rules: {
'foo-rule': [2],
'old-rule': [2],

'plugin/foo-rule': [2],
'plugin/old-plugin-rule': [2],

'@scope/scoped-plugin/foo-rule': [2],
'@scope/scoped-plugin/old-plugin-rule': [2],

'@scope/foo-rule': [2],
'@scope/old-plugin-rule': [2],

'@scope-with-dash/scoped-with-dash-plugin/foo-rule': [2],
'@scope-with-dash/scoped-with-dash-plugin/old-plugin-rule': [2],

'@scope-with-dash/foo-rule': [2],
'@scope-with-dash/old-plugin-rule': [2]
}
}
40 changes: 40 additions & 0 deletions test/fixtures/post-v8/eslint-with-overrides.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const plugin = require('eslint-plugin-plugin');
const scopeEslintPluginScopedPlugin = require('@scope/eslint-plugin-scoped-plugin');
const scope = require('@scope/eslint-plugin');
const scopeWithDashEslintPluginScopedWithDashPlugin = require('@scope-with-dash/eslint-plugin-scoped-with-dash-plugin');
const scopeWithDash = require('@scope-with-dash/eslint-plugin');

module.exports = [
{
plugins: {
plugin,
},
rules: {
"foo-rule": [2],
"old-rule": [2],

"plugin/old-plugin-rule": [2]
},
},
{
files: ["**/*.json"],
plugins: {
'@scope/scoped-plugin': scopeEslintPluginScopedPlugin,
'@scope': scope,
},
rules: {
"@scope/scoped-plugin/foo-rule": [2],
"@scope/foo-rule": [2]
}
},
{
files: ["**/*.txt"],
plugins: {
'@scope-with-dash/scoped-with-dash-plugin': scopeWithDashEslintPluginScopedWithDashPlugin,
'@scope-with-dash': scopeWithDash
},
rules: {
"@scope-with-dash/scoped-with-dash-plugin/old-plugin-rule": [2]
}
}
];
10 changes: 10 additions & 0 deletions test/fixtures/post-v8/eslint-with-plugin-with-no-rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const plugin = require('eslint-plugin-plugin');
const eslintPluginNoRules = require('eslint-plugin-no-rules');

module.exports = {
plugins: {
plugin,
'no-rules': eslintPluginNoRules
},
rules: {}
}
26 changes: 26 additions & 0 deletions test/fixtures/post-v8/eslint_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const eslintYml = require('./eslint_yml');
const plugin = require('eslint-plugin-plugin');
const scopeEslintPluginScopedPlugin = require('@scope/eslint-plugin-scoped-plugin');
const scope = require('@scope/eslint-plugin');
const scopeWithDashEslintPluginScopedWithDashPlugin = require('@scope-with-dash/eslint-plugin-scoped-with-dash-plugin');
const scopeWithDash = require('@scope-with-dash/eslint-plugin');

module.exports = [
eslintYml,
{
plugins: {
plugin,
'@scope/scoped-plugin': scopeEslintPluginScopedPlugin,
'@scope': scope,
'@scope-with-dash/scoped-with-dash-plugin': scopeWithDashEslintPluginScopedWithDashPlugin,
'@scope-with-dash': scopeWithDash
},
rules: {
'@scope/scoped-plugin/foo-rule': [2],
'@scope/foo-rule': [2],

'@scope-with-dash/scoped-with-dash-plugin/foo-rule': [2],
'@scope-with-dash/foo-rule': [2]
}
}
];
8 changes: 8 additions & 0 deletions test/fixtures/post-v8/eslint_yml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const eslintrc = require('./eslintrc');
const merge = require('lodash/merge');

module.exports = merge(eslintrc, {
rules: {
'bar-rule': [2]
}
});
5 changes: 5 additions & 0 deletions test/fixtures/post-v8/eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
rules: {
"foo-rule": [2]
}
}
5 changes: 5 additions & 0 deletions test/fixtures/post-v8/no-path/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
rules: {
'foo-rule': [2]
}
};
File renamed without changes.
File renamed without changes.
30 changes: 30 additions & 0 deletions test/fixtures/prior-v8/eslint-flat-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = [
{
files: ["**/*.js"],
plugins: {
plugin: {
rules: {
"foo-rule": {},
"old-plugin-rule": { meta: { deprecated: true } },
"bar-rule": {},
},
},
},
rules: {
"foo-rule": [2],
"plugin/foo-rule": [2],
},
},
{
files: ["**/*.json"],
plugins: {
jsonPlugin: {
rules: { "foo-rule": {} },
},
},
rules: {
"jsonPlugin/foo-rule": [2],
},
},
];

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions test/fixtures/prior-v8/no-path/index.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
some files
7 changes: 7 additions & 0 deletions test/fixtures/prior-v8/no-path/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "fake-project",
"version": "0.0.0",
"description": "Simulating a project's package.json.",
"private": true,
"main": "./index.js"
}
Loading

0 comments on commit 4cc38cb

Please sign in to comment.