diff --git a/.flowconfig b/.flowconfig index 46e35fd4e..e01587181 100644 --- a/.flowconfig +++ b/.flowconfig @@ -3,5 +3,6 @@ /lib/.* /docs/.* /reports/.* +/examples/.* [options] suppress_type=$FlowFixMe diff --git a/.github/workflows/node-4+.yml b/.github/workflows/node-4+.yml index d5c908cab..a21d5c9d3 100644 --- a/.github/workflows/node-4+.yml +++ b/.github/workflows/node-4+.yml @@ -25,6 +25,7 @@ jobs: matrix: node-version: ${{ fromJson(needs.matrix.outputs.latest) }} eslint: + - 9 - 8 - 7 - 6 @@ -32,6 +33,32 @@ jobs: - 4 - 3 exclude: + - node-version: 16 + eslint: 9 + - node-version: 15 + eslint: 9 + - node-version: 14 + eslint: 9 + - node-version: 13 + eslint: 9 + - node-version: 12 + eslint: 9 + - node-version: 11 + eslint: 9 + - node-version: 10 + eslint: 9 + - node-version: 9 + eslint: 9 + - node-version: 8 + eslint: 9 + - node-version: 7 + eslint: 9 + - node-version: 6 + eslint: 9 + - node-version: 5 + eslint: 9 + - node-version: 4 + eslint: 9 - node-version: 15 eslint: 8 - node-version: 13 @@ -90,7 +117,7 @@ jobs: steps: - uses: actions/checkout@v4 with: - fetch-depth: 0 + fetch-depth: 0 - uses: ljharb/actions/node/install@main name: 'nvm install ${{ matrix.node-version }} && npm install' env: diff --git a/__tests__/__util__/nodeReexports/assert.js b/__tests__/__util__/nodeReexports/assert.js new file mode 100644 index 000000000..78f8d741f --- /dev/null +++ b/__tests__/__util__/nodeReexports/assert.js @@ -0,0 +1,3 @@ +import assert from 'assert'; + +export default assert; diff --git a/__tests__/__util__/nodeReexports/fs-promises.js b/__tests__/__util__/nodeReexports/fs-promises.js new file mode 100644 index 000000000..c0d0215b9 --- /dev/null +++ b/__tests__/__util__/nodeReexports/fs-promises.js @@ -0,0 +1,3 @@ +import fs from 'fs/promises'; + +export default fs; diff --git a/__tests__/__util__/nodeReexports/fs.js b/__tests__/__util__/nodeReexports/fs.js new file mode 100644 index 000000000..6b9cf6a67 --- /dev/null +++ b/__tests__/__util__/nodeReexports/fs.js @@ -0,0 +1,3 @@ +import fs from 'fs'; + +export default fs; diff --git a/__tests__/__util__/nodeReexports/path.js b/__tests__/__util__/nodeReexports/path.js new file mode 100644 index 000000000..7b411d509 --- /dev/null +++ b/__tests__/__util__/nodeReexports/path.js @@ -0,0 +1,3 @@ +import path from 'path'; + +export default path; diff --git a/__tests__/__util__/nodeReexports/url.js b/__tests__/__util__/nodeReexports/url.js new file mode 100644 index 000000000..e851de2b4 --- /dev/null +++ b/__tests__/__util__/nodeReexports/url.js @@ -0,0 +1,3 @@ +import url from 'url'; + +export default url; diff --git a/__tests__/__util__/nodeReexports/util.js b/__tests__/__util__/nodeReexports/util.js new file mode 100644 index 000000000..1e9ac4b66 --- /dev/null +++ b/__tests__/__util__/nodeReexports/util.js @@ -0,0 +1,3 @@ +import util from 'util'; + +export default util; diff --git a/__tests__/__util__/parserOptionsMapper.js b/__tests__/__util__/parserOptionsMapper.js index 74db94a78..790e54625 100644 --- a/__tests__/__util__/parserOptionsMapper.js +++ b/__tests__/__util__/parserOptionsMapper.js @@ -1,26 +1,53 @@ +import { version as eslintVersion } from 'eslint/package.json'; +import semver from 'semver'; + +const usingLegacy = semver.major(eslintVersion) < 9; + const defaultParserOptions = { - ecmaVersion: 2018, ecmaFeatures: { experimentalObjectRestSpread: true, jsx: true, }, }; +const defaultLegacyParserOptions = { + ...defaultParserOptions, + ecmaVersion: 2018, +}; + +const defaultLanguageOptions = { + ecmaVersion: 'latest', + parserOptions: { + ...defaultParserOptions, + }, +}; + export default function parserOptionsMapper({ code, errors, options = [], - parserOptions = {}, - settings, + languageOptions = {}, + settings = {}, }) { - return { - code, - errors, - options, - parserOptions: { - ...defaultParserOptions, - ...parserOptions, - }, - settings, - }; + return usingLegacy + ? { + code, + errors, + options, + parserOptions: { + ...defaultLegacyParserOptions, + ...languageOptions, + }, + settings, + } + : { + code, + errors, + options, + languageOptions: { + ...defaultLanguageOptions, + ...languageOptions, + }, + settings, + }; } diff --git a/__tests__/src/rules/img-redundant-alt-test.js b/__tests__/src/rules/img-redundant-alt-test.js index 3bd5fcbbe..73bb14f02 100644 --- a/__tests__/src/rules/img-redundant-alt-test.js +++ b/__tests__/src/rules/img-redundant-alt-test.js @@ -67,8 +67,8 @@ ruleTester.run('img-redundant-alt', rule, { { code: '{imageAlt}' }, { code: '{imageAlt.name}' }, semver.satisfies(eslintVersion, '>= 6') ? [ - { code: '{imageAlt?.name}', parserOptions: { ecmaVersion: 2020 } }, - { code: 'Doing cool things', parserOptions: { ecmaVersion: 2020 } }, + { code: '{imageAlt?.name}', languageOptions: { ecmaVersion: 2020 } }, + { code: 'Doing cool things', languageOptions: { ecmaVersion: 2020 } }, ] : [], { code: 'Photography;' }, { code: 'ImageMagick;' }, diff --git a/__tests__/src/util/parserOptionsMapper-test.js b/__tests__/src/util/parserOptionsMapper-test.js index d3d1ef9d2..d22b6b647 100644 --- a/__tests__/src/util/parserOptionsMapper-test.js +++ b/__tests__/src/util/parserOptionsMapper-test.js @@ -1,6 +1,10 @@ +import { version as eslintVersion } from 'eslint/package.json'; import expect from 'expect'; +import semver from 'semver'; import parserOptionsMapper from '../../__util__/parserOptionsMapper'; +const usingLegacy = semver.major(eslintVersion) < 9; + describe('parserOptionsMapper', () => { it('should return an test case object', () => { const testCase = { @@ -8,39 +12,77 @@ describe('parserOptionsMapper', () => { errors: [], options: {}, }; - expect(parserOptionsMapper(testCase)).toEqual({ - code: '
', - errors: [], - options: {}, - parserOptions: { - ecmaVersion: 2018, - ecmaFeatures: { - experimentalObjectRestSpread: true, - jsx: true, + + const expectedResult = usingLegacy + ? { + code: '
', + errors: [], + options: {}, + parserOptions: { + ecmaVersion: 2018, + ecmaFeatures: { + experimentalObjectRestSpread: true, + jsx: true, + }, }, - }, - }); + settings: {}, + } + : { + code: '
', + errors: [], + options: {}, + languageOptions: { + ecmaVersion: 'latest', + parserOptions: { + ecmaFeatures: { + experimentalObjectRestSpread: true, + jsx: true, + }, + }, + }, + settings: {}, + }; + expect(parserOptionsMapper(testCase)).toEqual(expectedResult); }); it('should allow for overriding parserOptions', () => { const testCase = { code: '
', errors: [], options: {}, - parserOptions: { + languageOptions: { ecmaVersion: 5, }, }; - expect(parserOptionsMapper(testCase)).toEqual({ - code: '
', - errors: [], - options: {}, - parserOptions: { - ecmaVersion: 5, - ecmaFeatures: { - experimentalObjectRestSpread: true, - jsx: true, + + const expectedResult = usingLegacy + ? { + code: '
', + errors: [], + options: {}, + parserOptions: { + ecmaVersion: 5, + ecmaFeatures: { + experimentalObjectRestSpread: true, + jsx: true, + }, }, - }, - }); + settings: {}, + } + : { + code: '
', + errors: [], + options: {}, + languageOptions: { + ecmaVersion: 5, + parserOptions: { + ecmaFeatures: { + experimentalObjectRestSpread: true, + jsx: true, + }, + }, + }, + settings: {}, + }; + expect(parserOptionsMapper(testCase)).toEqual(expectedResult); }); }); diff --git a/examples/flat-cjs/package.json b/examples/flat-cjs/package.json index d89c7f081..80a71d9a9 100644 --- a/examples/flat-cjs/package.json +++ b/examples/flat-cjs/package.json @@ -11,9 +11,9 @@ "react-dom": "^18.2.0" }, "devDependencies": { - "@eslint/js": "^9.5.0", + "@eslint/js": "^9.9.1", "cross-env": "^7.0.3", - "eslint": "^8.57.0", + "eslint": "^9.9.1", "eslint-plugin-jsx-a11y": "file:../..", "globals": "^15.6.0" } diff --git a/examples/flat-esm/package.json b/examples/flat-esm/package.json index cf10c8170..484a40a9c 100644 --- a/examples/flat-esm/package.json +++ b/examples/flat-esm/package.json @@ -11,9 +11,9 @@ "react-dom": "^18.2.0" }, "devDependencies": { - "@eslint/js": "^9.5.0", + "@eslint/js": "^9.9.1", "cross-env": "^7.0.3", - "eslint": "^8.57.0", + "eslint": "^9.9.1", "eslint-plugin-jsx-a11y": "file:../..", "globals": "^15.6.0" } diff --git a/examples/legacy/package.json b/examples/legacy/package.json index 35be81484..bbd8b1bc8 100644 --- a/examples/legacy/package.json +++ b/examples/legacy/package.json @@ -12,7 +12,7 @@ }, "devDependencies": { "cross-env": "^7.0.3", - "eslint": "^8.57.0", + "eslint": "^9.9.1", "eslint-plugin-jsx-a11y": "file:../.." } } diff --git a/package.json b/package.json index 24f497068..d4d8aff01 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "create": "node ./scripts/create-rule", "flow": "flow", "lint:fix": "npm run lint -- --fix", - "lint": "eslint --ext=js,mjs,cjs,ts,tsx .", + "lint": "npx eslint@8 --ext=js,mjs,cjs,ts,tsx .", "prepublish": "not-in-publish || npm run prepublishOnly", "prepublishOnly": "safe-publish-latest && npm run lint && npm run flow && npm run jest", "pretest": "npm run lint:fix && npm run flow", @@ -34,7 +34,7 @@ "test-example:legacy": "cd examples/legacy && npm install && npm run lint", "test-example:flat-esm": "cd examples/flat-esm && npm install && npm run lint", "test-example:flat-cjs": "cd examples/flat-cjs && npm install && npm run lint", - "jest": "jest --coverage __tests__/**/*", + "jest": "jest --coverage __tests__", "pregenerate-list-of-rules": "npm run build", "generate-list-of-rules": "eslint-doc-generator --rule-doc-title-format prefix-name --rule-doc-section-options false --config-emoji recommended,☑️ --ignore-config flat/recommended --ignore-config flat/strict", "generate-list-of-rules:check": "npm run generate-list-of-rules -- --check", @@ -51,7 +51,8 @@ "babel-jest": "^24.9.0", "babel-plugin-add-module-exports": "^1.0.4", "babel-preset-airbnb": "^5.0.0", - "eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8", + "core-js": "^3.38.1", + "eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8 || ^9", "eslint-config-airbnb-base": "^15.0.0", "eslint-doc-generator": "^1.7.1", "eslint-plugin-eslint-plugin": "^4.3.0", @@ -96,7 +97,7 @@ "string.prototype.includes": "^2.0.0" }, "peerDependencies": { - "eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8" + "eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8 || ^9" }, "jest": { "coverageReporters": [ @@ -111,7 +112,18 @@ "testPathIgnorePatterns": [ "__tests__/__util__/" ], - "testEnvironment": "node" + "testEnvironment": "node", + "moduleNameMapper": { + "@eslint/config-array": "/node_modules/@eslint/config-array/dist/cjs/index.cjs", + "@eslint/object-schema": "/node_modules/@eslint/object-schema/dist/cjs/index.cjs", + "node:assert": "/__tests__/__util__/nodeReexports/assert.js", + "node:fs/promises": "/__tests__/__util__/nodeReexports/fs-promises.js", + "node:fs": "/__tests__/__util__/nodeReexports/fs.js", + "node:path": "/__tests__/__util__/nodeReexports/path.js", + "node:url": "/__tests__/__util__/nodeReexports/url.js", + "node:util": "/__tests__/__util__/nodeReexports/util.js" + }, + "setupFilesAfterEnv": ["/setup.jest.js"] }, "auto-changelog": { "output": "CHANGELOG.md", @@ -132,7 +144,8 @@ "/flow", "scripts/", "CONTRIBUTING.md", - "/examples" + "/examples", + "setup.jest.js" ] } } diff --git a/setup.jest.js b/setup.jest.js new file mode 100644 index 000000000..d906eae00 --- /dev/null +++ b/setup.jest.js @@ -0,0 +1,2 @@ +// eslint-disable-next-line import/no-extraneous-dependencies +import 'core-js/stable/structured-clone';