diff --git a/.eslint-doc-generatorrc.js b/.eslint-doc-generatorrc.js index a3756beb..df9f4712 100644 --- a/.eslint-doc-generatorrc.js +++ b/.eslint-doc-generatorrc.js @@ -9,13 +9,6 @@ const config = { 'rules-recommended', 'tests', 'tests-recommended', - 'flat/recommended', - 'flat/all', - 'flat/all-type-checked', - 'flat/rules', - 'flat/rules-recommended', - 'flat/tests', - 'flat/tests-recommended', ], postprocess: async (content, path) => prettier.format(content, { diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 51902405..b46076ce 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,21 +34,10 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: - node-version: "lts/*" + node-version: 'lts/*' - run: npm install - run: npm run lint - eslint8: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: "lts/*" - - run: npm install - - run: npm install --save-dev eslint@8 - - run: npm test - test-remote: name: eslint-remote-tester runs-on: ubuntu-latest @@ -56,6 +45,6 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: - node-version: "lts/*" + node-version: 'lts/*' - run: npm install - run: npm run test:remote diff --git a/README.md b/README.md index f6eeb235..3b6e5000 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,6 @@ An ESLint plugin for linting ESLint plugins. Rules written in CJS, ESM, and Type - [Installation](#installation) - [Usage](#usage) - - [**.eslintrc.json**](#eslintrcjson) - - [`eslint.config.js` (requires eslint\>=v8.23.0)](#eslintconfigjs-requires-eslintv8230) - [Rules](#rules) - [Rules](#rules-1) - [Tests](#tests) @@ -42,25 +40,14 @@ Here's an example ESLint configuration that: - Enables the `recommended` configuration - Enables an optional/non-recommended rule -Note: you might need to set `sourceType` to `script` (most users) (use `module` for ESM/TypeScript). - -### **[.eslintrc.json](https://eslint.org/docs/latest/use/configure/configuration-files)** - -```json -{ - "extends": ["plugin:eslint-plugin/recommended"], - "rules": { - "eslint-plugin/require-meta-docs-description": "error" - } -} -``` - -### [`eslint.config.js`](https://eslint.org/docs/latest/use/configure/configuration-files-new) (requires eslint>=v8.23.0) +Note: you might need to set `sourceType` to `module` or `script` depending on your codebase. ```js -const eslintPlugin = require('eslint-plugin-eslint-plugin'); -module.exports = [ - eslintPlugin.configs['flat/recommended'], +// eslint.config.js +import eslintPlugin from 'eslint-plugin-eslint-plugin'; + +export default [ + eslintPlugin.configs.recommended, { rules: { 'eslint-plugin/require-meta-docs-description': 'error', @@ -141,54 +128,29 @@ The list of recommended rules will only change in a major release of this plugin ### Preset usage -Both flat and eslintrc configs are supported. For example, to enable the `recommended` preset, use: - -eslint.config.js +Example of applying the `recommended` config to all files. ```js -const eslintPlugin = require('eslint-plugin-eslint-plugin'); -module.exports = [eslintPlugin.configs['flat/recommended']]; -``` +// eslint.config.js +import eslintPlugin from 'eslint-plugin-eslint-plugin'; -.eslintrc.json - -```json -{ - "extends": ["plugin:eslint-plugin/recommended"] -} +export default [eslintPlugin.configs.recommended]; ``` Or to apply linting only to the appropriate rule or test files: -eslint.config.js - ```js -const eslintPlugin = require('eslint-plugin-eslint-plugin'); -module.exports = [ +// eslint.config.js +import eslintPlugin from 'eslint-plugin-eslint-plugin'; + +export default [ { files: ['lib/rules/*.{js,ts}'], - ...eslintPlugin.configs['flat/rules-recommended'], + ...eslintPlugin.configs['rules-recommended'], }, { files: ['tests/lib/rules/*.{js,ts}'], - ...eslintPlugin.configs['flat/tests-recommended'], + ...eslintPlugin.configs['tests-recommended'], }, ]; ``` - -.eslintrc.js - -```json -{ - "overrides": [ - { - "files": ["lib/rules/*.{js,ts}"], - "extends": ["plugin:eslint-plugin/rules-recommended"] - }, - { - "files": ["tests/lib/rules/*.{js,ts}"], - "extends": ["plugin:eslint-plugin/tests-recommended"] - } - ] -} -``` diff --git a/configs/all-type-checked.js b/configs/all-type-checked.js deleted file mode 100644 index 84309cba..00000000 --- a/configs/all-type-checked.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * @deprecated use 'flat/all-type-checked' instead - * @author 唯然 - */ - -import plugin from '../lib/index.js'; - -const config = plugin.configs['flat/all-type-checked']; - -export default config; diff --git a/configs/all.js b/configs/all.js deleted file mode 100644 index cf48e487..00000000 --- a/configs/all.js +++ /dev/null @@ -1,11 +0,0 @@ -/** - * @fileoverview the `all` config for `eslint.config.js` - * @deprecated use 'flat/all' instead - * @author 唯然 - */ - -import plugin from '../lib/index.js'; - -const config = plugin.configs['flat/all']; - -export default config; diff --git a/configs/recommended.js b/configs/recommended.js deleted file mode 100644 index 17c2ffad..00000000 --- a/configs/recommended.js +++ /dev/null @@ -1,11 +0,0 @@ -/** - * @fileoverview the `recommended` config for `eslint.config.js` - * @deprecated use 'flat/recommended' instead - * @author 唯然 - */ - -import plugin from '../lib/index.js'; - -const config = plugin.configs['flat/recommended']; - -export default config; diff --git a/configs/rules-recommended.js b/configs/rules-recommended.js deleted file mode 100644 index 8e79f61a..00000000 --- a/configs/rules-recommended.js +++ /dev/null @@ -1,11 +0,0 @@ -/** - * @fileoverview the `rules-recommended` config for `eslint.config.js` - * @deprecated use 'flat/rules-recommended' instead - * @author 唯然 - */ - -import plugin from '../lib/index.js'; - -const config = plugin.configs['flat/rules-recommended']; - -export default config; diff --git a/configs/rules.js b/configs/rules.js deleted file mode 100644 index f3414360..00000000 --- a/configs/rules.js +++ /dev/null @@ -1,11 +0,0 @@ -/** - * @fileoverview the `rules` config for `eslint.config.js` - * @deprecated use 'flat/rules' instead - * @author 唯然 - */ - -import plugin from '../lib/index.js'; - -const config = plugin.configs['flat/rules']; - -export default config; diff --git a/configs/tests-recommended.js b/configs/tests-recommended.js deleted file mode 100644 index 367f5d17..00000000 --- a/configs/tests-recommended.js +++ /dev/null @@ -1,11 +0,0 @@ -/** - * @fileoverview the `tests-recommended` config for `eslint.config.js` - * @deprecated use 'flat/tests-recommended' instead - * @author 唯然 - */ - -import plugin from '../lib/index.js'; - -const config = plugin.configs['flat/tests-recommended']; - -export default config; diff --git a/configs/tests.js b/configs/tests.js deleted file mode 100644 index 38ced25c..00000000 --- a/configs/tests.js +++ /dev/null @@ -1,11 +0,0 @@ -/** - * @fileoverview the `tests` config for `eslint.config.js` - * @deprecated use 'flat/tests' instead - * @author 唯然 - */ - -import plugin from '../lib/index.js'; - -const config = plugin.configs['flat/tests']; - -export default config; diff --git a/docs/rules/require-meta-docs-url.md b/docs/rules/require-meta-docs-url.md index 4bb71a41..4509fb85 100644 --- a/docs/rules/require-meta-docs-url.md +++ b/docs/rules/require-meta-docs-url.md @@ -96,29 +96,54 @@ module.exports = { } ``` +```js +// eslint.config.js +import eslintPlugin from 'eslint-plugin-eslint-plugin'; + +export default [ + { + plugins: { 'eslint-plugin': eslintPlugin }, + rules: { + 'eslint-plugin/require-meta-docs-url': [ + 'error', + { + pattern: + 'https://github.com/eslint-community/eslint-plugin-eslint-plugin/blob/master/docs/rules/{{name}}.md', + }, + ], + }, + }, +]; +``` + If you set the `pattern` option, this rule adds `meta.docs.url` property automatically when you execute `eslint --fix` command. ## Version specific URL -If you want to enforce version-specific URLs, it's feasible easily with `.eslintrc.js` and `npm version ` script. +If you want to enforce version-specific URLs, it's feasible easily with `eslint.config.js` and `npm version ` script. For example: -**.eslintrc.js**: +**eslint.config.js**: ```js -// const version = require("./package.json").version; - -module.exports = { - plugins: ['eslint-plugin'], - rules: { - 'eslint-plugin/require-meta-docs-url': [ - 'error', - { - pattern: `path/to/v${version}/docs/rules/{{name}}.md`, - }, - ], +import eslintPlugin from 'eslint-plugin-eslint-plugin'; +import packageMetadata from './package.json' with { type: 'json' }; + +const { version } = packageMetadata; + +export default [ + { + plugins: { 'eslint-plugin': eslintPlugin }, + rules: { + 'eslint-plugin/require-meta-docs-url': [ + 'error', + { + pattern: `path/to/v${version}/docs/rules/{{name}}.md`, + }, + ], + }, }, -}; +]; ``` **package.json**: diff --git a/eslint.config.js b/eslint.config.js index f34afb74..3bf9f756 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -4,7 +4,7 @@ import js from '@eslint/js'; import { FlatCompat } from '@eslint/eslintrc'; import markdown from 'eslint-plugin-markdown'; import pluginN from 'eslint-plugin-n'; -import eslintPluginConfig from 'eslint-plugin-eslint-plugin/configs/all'; +import eslintPlugin from './lib/index.js'; const dirname = path.dirname(fileURLToPath(import.meta.url)); const compat = new FlatCompat({ @@ -46,9 +46,9 @@ export default [ { // Apply eslint-plugin rules to our own rules/tests (but not docs). files: ['lib/**/*.js', 'tests/**/*.js'], - plugins: eslintPluginConfig.plugins, + plugins: { 'eslint-plugin': eslintPlugin }, rules: { - ...eslintPluginConfig.rules, + ...eslintPlugin.configs.all.rules, 'eslint-plugin/no-meta-schema-default': 'off', // TODO: enable once https://github.com/bmish/eslint-doc-generator/issues/513 is fixed and released 'eslint-plugin/report-message-format': ['error', '^[^a-z].*.$'], 'eslint-plugin/require-meta-docs-url': [ @@ -77,6 +77,8 @@ export default [ '@eslint-community/eslint-comments/require-description': 'off', + 'n/no-missing-import': 'off', + 'unicorn/filename-case': 'off', }, }, diff --git a/lib/index.js b/lib/index.js index 83f4a93e..f512a196 100644 --- a/lib/index.js +++ b/lib/index.js @@ -105,31 +105,14 @@ const plugin = { configs: {}, // assigned later }; -// eslintrc configs +// configs Object.assign( plugin.configs, Object.keys(configFilters).reduce((configs, configName) => { return Object.assign(configs, { [configName]: { - plugins: ['eslint-plugin'], - rules: Object.fromEntries( - Object.keys(allRules) - .filter((ruleName) => configFilters[configName](allRules[ruleName])) - .map((ruleName) => [`${PLUGIN_NAME}/${ruleName}`, 'error']), - ), - }, - }); - }, {}), -); - -// flat configs -Object.assign( - plugin.configs, - Object.keys(configFilters).reduce((configs, configName) => { - return Object.assign(configs, { - [`flat/${configName}`]: { - name: `eslint-plugin/flat/${configName}`, - plugins: { 'eslint-plugin': plugin }, + name: `${PLUGIN_NAME}/${configName}`, + plugins: { [PLUGIN_NAME]: plugin }, rules: Object.fromEntries( Object.keys(allRules) .filter((ruleName) => configFilters[configName](allRules[ruleName])) diff --git a/package.json b/package.json index 2ec7b244..5bd6c441 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,6 @@ "type": "module", "exports": { ".": "./lib/index.js", - "./configs/*": "./configs/*.js", "./package.json": "./package.json" }, "license": "MIT", @@ -24,8 +23,8 @@ "update:eslint-docs": "eslint-doc-generator" }, "files": [ - "lib/", - "configs/" + "CHANGELOG.md", + "lib/" ], "keywords": [ "eslint", @@ -79,7 +78,7 @@ "vitest": "^3.2.4" }, "peerDependencies": { - "eslint": ">=8.23.0" + "eslint": ">=9.0.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" diff --git a/tests/lib/rules/consistent-output.js b/tests/lib/rules/consistent-output.js index 60ac1899..e63d62f7 100644 --- a/tests/lib/rules/consistent-output.js +++ b/tests/lib/rules/consistent-output.js @@ -8,7 +8,7 @@ // ------------------------------------------------------------------------------ import rule from '../../../lib/rules/consistent-output.js'; -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; const ERROR = { messageId: 'missingOutput', type: 'ObjectExpression' }; diff --git a/tests/lib/rules/fixer-return.js b/tests/lib/rules/fixer-return.js index cc3798c5..bff61ee3 100644 --- a/tests/lib/rules/fixer-return.js +++ b/tests/lib/rules/fixer-return.js @@ -8,7 +8,7 @@ // ------------------------------------------------------------------------------ import rule from '../../../lib/rules/fixer-return.js'; -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; // ------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/meta-property-ordering.js b/tests/lib/rules/meta-property-ordering.js index 1a843e94..632dfe59 100644 --- a/tests/lib/rules/meta-property-ordering.js +++ b/tests/lib/rules/meta-property-ordering.js @@ -7,7 +7,7 @@ // ------------------------------------------------------------------------------ import rule from '../../../lib/rules/meta-property-ordering.js'; -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; // ------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-deprecated-context-methods.js b/tests/lib/rules/no-deprecated-context-methods.js index 7338f37e..14eaaccc 100644 --- a/tests/lib/rules/no-deprecated-context-methods.js +++ b/tests/lib/rules/no-deprecated-context-methods.js @@ -8,7 +8,7 @@ // ------------------------------------------------------------------------------ import rule from '../../../lib/rules/no-deprecated-context-methods.js'; -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; // ------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-deprecated-report-api.js b/tests/lib/rules/no-deprecated-report-api.js index ed1bd422..636b2c11 100644 --- a/tests/lib/rules/no-deprecated-report-api.js +++ b/tests/lib/rules/no-deprecated-report-api.js @@ -8,7 +8,7 @@ // ------------------------------------------------------------------------------ import rule from '../../../lib/rules/no-deprecated-report-api.js'; -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; // ------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-identical-tests.js b/tests/lib/rules/no-identical-tests.js index bcfcd8cd..169d9140 100644 --- a/tests/lib/rules/no-identical-tests.js +++ b/tests/lib/rules/no-identical-tests.js @@ -8,7 +8,7 @@ // ------------------------------------------------------------------------------ import rule from '../../../lib/rules/no-identical-tests.js'; -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; const ERROR_OBJECT_TEST = { messageId: 'identical', type: 'ObjectExpression' }; const ERROR_STRING_TEST = { messageId: 'identical', type: 'Literal' }; diff --git a/tests/lib/rules/no-meta-replaced-by.js b/tests/lib/rules/no-meta-replaced-by.js index 2d357a39..9ec810fa 100644 --- a/tests/lib/rules/no-meta-replaced-by.js +++ b/tests/lib/rules/no-meta-replaced-by.js @@ -7,7 +7,7 @@ // ------------------------------------------------------------------------------ import rule from '../../../lib/rules/no-meta-replaced-by.js'; -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; // ------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-meta-schema-default.js b/tests/lib/rules/no-meta-schema-default.js index 06376284..07dd50d1 100644 --- a/tests/lib/rules/no-meta-schema-default.js +++ b/tests/lib/rules/no-meta-schema-default.js @@ -3,7 +3,7 @@ // ------------------------------------------------------------------------------ import rule from '../../../lib/rules/no-meta-schema-default.js'; -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; // ------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-missing-message-ids.js b/tests/lib/rules/no-missing-message-ids.js index efee8a9d..aa0045a0 100644 --- a/tests/lib/rules/no-missing-message-ids.js +++ b/tests/lib/rules/no-missing-message-ids.js @@ -3,7 +3,7 @@ // ------------------------------------------------------------------------------ import rule from '../../../lib/rules/no-missing-message-ids.js'; -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; // ------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-missing-placeholders.js b/tests/lib/rules/no-missing-placeholders.js index 13767ec2..2791fee2 100644 --- a/tests/lib/rules/no-missing-placeholders.js +++ b/tests/lib/rules/no-missing-placeholders.js @@ -8,7 +8,7 @@ // ------------------------------------------------------------------------------ import rule from '../../../lib/rules/no-missing-placeholders.js'; -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; /** * Create an error for the given key diff --git a/tests/lib/rules/no-only-tests.js b/tests/lib/rules/no-only-tests.js index 25257c65..b7f52125 100644 --- a/tests/lib/rules/no-only-tests.js +++ b/tests/lib/rules/no-only-tests.js @@ -3,7 +3,7 @@ // ------------------------------------------------------------------------------ import rule from '../../../lib/rules/no-only-tests.js'; -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; // ------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-property-in-node.js b/tests/lib/rules/no-property-in-node.js index d5614cf7..8f2674d0 100644 --- a/tests/lib/rules/no-property-in-node.js +++ b/tests/lib/rules/no-property-in-node.js @@ -1,4 +1,4 @@ -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; import path from 'path'; import { fileURLToPath } from 'url'; import rule from '../../../lib/rules/no-property-in-node.js'; diff --git a/tests/lib/rules/no-unused-message-ids.js b/tests/lib/rules/no-unused-message-ids.js index 54184cdc..244651e1 100644 --- a/tests/lib/rules/no-unused-message-ids.js +++ b/tests/lib/rules/no-unused-message-ids.js @@ -3,7 +3,7 @@ // ------------------------------------------------------------------------------ import rule from '../../../lib/rules/no-unused-message-ids.js'; -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; // ------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/no-unused-placeholders.js b/tests/lib/rules/no-unused-placeholders.js index 87de5cb9..b9d55158 100644 --- a/tests/lib/rules/no-unused-placeholders.js +++ b/tests/lib/rules/no-unused-placeholders.js @@ -8,7 +8,7 @@ // ------------------------------------------------------------------------------ import rule from '../../../lib/rules/no-unused-placeholders.js'; -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; /** * Create an error for the given key diff --git a/tests/lib/rules/no-useless-token-range.js b/tests/lib/rules/no-useless-token-range.js index 0ad6b61f..7b6f44e7 100644 --- a/tests/lib/rules/no-useless-token-range.js +++ b/tests/lib/rules/no-useless-token-range.js @@ -8,7 +8,7 @@ // ------------------------------------------------------------------------------ import rule from '../../../lib/rules/no-useless-token-range.js'; -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; /** * Wraps a code sample as an eslint rule diff --git a/tests/lib/rules/prefer-message-ids.js b/tests/lib/rules/prefer-message-ids.js index 342fb501..9a45cb28 100644 --- a/tests/lib/rules/prefer-message-ids.js +++ b/tests/lib/rules/prefer-message-ids.js @@ -3,7 +3,7 @@ // ------------------------------------------------------------------------------ import rule from '../../../lib/rules/prefer-message-ids.js'; -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; // ------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/prefer-object-rule.js b/tests/lib/rules/prefer-object-rule.js index 0e1583f7..4c25013c 100644 --- a/tests/lib/rules/prefer-object-rule.js +++ b/tests/lib/rules/prefer-object-rule.js @@ -7,7 +7,7 @@ // ------------------------------------------------------------------------------ import rule from '../../../lib/rules/prefer-object-rule.js'; -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; // ------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/prefer-output-null.js b/tests/lib/rules/prefer-output-null.js index 22e7bfb4..082e41c4 100644 --- a/tests/lib/rules/prefer-output-null.js +++ b/tests/lib/rules/prefer-output-null.js @@ -8,7 +8,7 @@ // ------------------------------------------------------------------------------ import rule from '../../../lib/rules/prefer-output-null.js'; -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; const ERROR = { messageId: 'useOutputNull', type: 'Property' }; diff --git a/tests/lib/rules/prefer-placeholders.js b/tests/lib/rules/prefer-placeholders.js index 2da2c535..4b2f6447 100644 --- a/tests/lib/rules/prefer-placeholders.js +++ b/tests/lib/rules/prefer-placeholders.js @@ -8,7 +8,7 @@ // ------------------------------------------------------------------------------ import rule from '../../../lib/rules/prefer-placeholders.js'; -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; // ------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/prefer-replace-text.js b/tests/lib/rules/prefer-replace-text.js index e8dc8041..06117252 100644 --- a/tests/lib/rules/prefer-replace-text.js +++ b/tests/lib/rules/prefer-replace-text.js @@ -8,7 +8,7 @@ // ------------------------------------------------------------------------------ import rule from '../../../lib/rules/prefer-replace-text.js'; -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; // ------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/report-message-format.js b/tests/lib/rules/report-message-format.js index 8a1c7338..be260092 100644 --- a/tests/lib/rules/report-message-format.js +++ b/tests/lib/rules/report-message-format.js @@ -8,7 +8,7 @@ // ------------------------------------------------------------------------------ import rule from '../../../lib/rules/report-message-format.js'; -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; // ------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/require-meta-default-options.js b/tests/lib/rules/require-meta-default-options.js index b0e3df4f..d6ceb410 100644 --- a/tests/lib/rules/require-meta-default-options.js +++ b/tests/lib/rules/require-meta-default-options.js @@ -1,5 +1,5 @@ import rule from '../../../lib/rules/require-meta-default-options.js'; -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; import parser from '@typescript-eslint/parser'; const ruleTester = new RuleTester({ diff --git a/tests/lib/rules/require-meta-docs-description.js b/tests/lib/rules/require-meta-docs-description.js index d3aa09bd..28d49910 100644 --- a/tests/lib/rules/require-meta-docs-description.js +++ b/tests/lib/rules/require-meta-docs-description.js @@ -3,7 +3,7 @@ // ------------------------------------------------------------------------------ import rule from '../../../lib/rules/require-meta-docs-description.js'; -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; import parser from '@typescript-eslint/parser'; // ------------------------------------------------------------------------------ diff --git a/tests/lib/rules/require-meta-docs-recommended.js b/tests/lib/rules/require-meta-docs-recommended.js index b50a3b93..60a9d72a 100644 --- a/tests/lib/rules/require-meta-docs-recommended.js +++ b/tests/lib/rules/require-meta-docs-recommended.js @@ -1,5 +1,5 @@ import rule from '../../../lib/rules/require-meta-docs-recommended.js'; -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; import parser from '@typescript-eslint/parser'; const ruleTester = new RuleTester({ diff --git a/tests/lib/rules/require-meta-docs-url.js b/tests/lib/rules/require-meta-docs-url.js index a13d63b2..50895f05 100644 --- a/tests/lib/rules/require-meta-docs-url.js +++ b/tests/lib/rules/require-meta-docs-url.js @@ -8,7 +8,7 @@ // Requirements // ----------------------------------------------------------------------------- -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; import rule from '../../../lib/rules/require-meta-docs-url.js'; // ----------------------------------------------------------------------------- diff --git a/tests/lib/rules/require-meta-fixable.js b/tests/lib/rules/require-meta-fixable.js index a0d343f3..3bde53c7 100644 --- a/tests/lib/rules/require-meta-fixable.js +++ b/tests/lib/rules/require-meta-fixable.js @@ -8,7 +8,7 @@ // ------------------------------------------------------------------------------ import rule from '../../../lib/rules/require-meta-fixable.js'; -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; // ------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/require-meta-has-suggestions.js b/tests/lib/rules/require-meta-has-suggestions.js index 9c19d011..8bb7eb84 100644 --- a/tests/lib/rules/require-meta-has-suggestions.js +++ b/tests/lib/rules/require-meta-has-suggestions.js @@ -3,7 +3,7 @@ // ------------------------------------------------------------------------------ import rule from '../../../lib/rules/require-meta-has-suggestions.js'; -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; // ------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/require-meta-schema-description.js b/tests/lib/rules/require-meta-schema-description.js index 6fb5b741..fa0b414f 100644 --- a/tests/lib/rules/require-meta-schema-description.js +++ b/tests/lib/rules/require-meta-schema-description.js @@ -3,7 +3,7 @@ // ------------------------------------------------------------------------------ import rule from '../../../lib/rules/require-meta-schema-description.js'; -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; // ------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/require-meta-schema.js b/tests/lib/rules/require-meta-schema.js index aff9df9f..5c6c6af0 100644 --- a/tests/lib/rules/require-meta-schema.js +++ b/tests/lib/rules/require-meta-schema.js @@ -3,7 +3,7 @@ // ------------------------------------------------------------------------------ import rule from '../../../lib/rules/require-meta-schema.js'; -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; // ------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/require-meta-type.js b/tests/lib/rules/require-meta-type.js index ae52476f..7d44b041 100644 --- a/tests/lib/rules/require-meta-type.js +++ b/tests/lib/rules/require-meta-type.js @@ -8,7 +8,7 @@ // ------------------------------------------------------------------------------ import rule from '../../../lib/rules/require-meta-type.js'; -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; // ------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/test-case-property-ordering.js b/tests/lib/rules/test-case-property-ordering.js index 65b8970a..05fb8554 100644 --- a/tests/lib/rules/test-case-property-ordering.js +++ b/tests/lib/rules/test-case-property-ordering.js @@ -8,7 +8,7 @@ // ------------------------------------------------------------------------------ import rule from '../../../lib/rules/test-case-property-ordering.js'; -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; // ------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/test-case-shorthand-strings.js b/tests/lib/rules/test-case-shorthand-strings.js index f358d3ee..c65d0c18 100644 --- a/tests/lib/rules/test-case-shorthand-strings.js +++ b/tests/lib/rules/test-case-shorthand-strings.js @@ -8,7 +8,7 @@ // ------------------------------------------------------------------------------ import rule from '../../../lib/rules/test-case-shorthand-strings.js'; -import { RuleTester } from '../../utils/eslint-rule-tester.js'; +import { RuleTester } from 'eslint'; /** * Returns the code for some valid test cases diff --git a/tests/utils/eslint-rule-tester.js b/tests/utils/eslint-rule-tester.js deleted file mode 100644 index 5b3c5239..00000000 --- a/tests/utils/eslint-rule-tester.js +++ /dev/null @@ -1,21 +0,0 @@ -/** - * @fileoverview Helpers for tests. - * @author 唯然 - */ - -import { RuleTester as ESLintRuleTester } from 'eslint'; -import * as unsupportedApi from 'eslint/use-at-your-own-risk'; -import packageConfig from 'eslint/package.json' with { type: 'json' }; -import * as vitest from 'vitest'; - -const { version: eslintVersion } = packageConfig; - -const FlatRuleTester = unsupportedApi.FlatRuleTester; - -// greater than or equal to ESLint v9 -export const gteEslintV9 = +eslintVersion.split('.')[0] >= 9; - -export const RuleTester = gteEslintV9 ? ESLintRuleTester : FlatRuleTester; -RuleTester.describe = vitest.describe; -RuleTester.it = vitest.it; -RuleTester.itOnly = vitest.it.only; diff --git a/tests/utils/test-setup.js b/tests/utils/test-setup.js new file mode 100644 index 00000000..342265eb --- /dev/null +++ b/tests/utils/test-setup.js @@ -0,0 +1,6 @@ +import { RuleTester } from 'eslint'; +import * as vitest from 'vitest'; + +RuleTester.describe = vitest.describe; +RuleTester.it = vitest.it; +RuleTester.itOnly = vitest.it.only; diff --git a/vitest.config.ts b/vitest.config.ts index 64bc7458..56cb0fcc 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -4,6 +4,7 @@ export default defineConfig({ test: { include: ['tests/lib/**/*.js'], exclude: ['tests/lib/fixtures/**'], + setupFiles: ['tests/utils/test-setup.js'], clearMocks: true, coverage: { all: true,