Skip to content

Commit

Permalink
chore: use eslint 9 internally (typescript-eslint#9119)
Browse files Browse the repository at this point in the history
* eslint 9

* add compat

* add fixup

* fixup react

* add more fixups

* add issue comment

* lint and empty types

* fix types

* remove eslint9 ci test

* rename

* update no-restricted-imports snapshot

* update build script

* change quote style

* revert renaming

* begin migrating config files

* migrate markdown to v9

* migrate recommended-does-not-require-program

* migrate eslint.config.js

* migrate vue-sfc, except for TS errors

* remove flatconfig boolean

* remove config file option

* remove deprecated rules

* correct issue

* revert style change

* add clarifying comment

* remove unnecessary suppression

* remove unnecessary suppression

* remove unused suppression
  • Loading branch information
abrahamguo authored Jul 6, 2024
1 parent 0d70d62 commit 86811d7
Show file tree
Hide file tree
Showing 27 changed files with 224 additions and 208 deletions.
19 changes: 0 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,25 +134,6 @@ jobs:
run: yarn stylelint
working-directory: packages/website

eslint_v9_tests:
name: Run tests on ESLint v9
needs: [build]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install
uses: ./.github/actions/prepare-install
with:
node-version: ${{ env.PRIMARY_NODE_VERSION }}
- name: Build
uses: ./.github/actions/prepare-build
- run: yarn add eslint@9
- name: Run tests
run: yarn test
env:
CI: true

integration_tests:
name: Run integration tests on primary Node.js version
needs: [build]
Expand Down
18 changes: 12 additions & 6 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import url from 'node:url';

import { fixupConfigRules, fixupPluginRules } from '@eslint/compat';
import { FlatCompat } from '@eslint/eslintrc';
import eslint from '@eslint/js';
import tseslintInternalPlugin from '@typescript-eslint/eslint-plugin-internal';
Expand Down Expand Up @@ -29,15 +30,20 @@ export default tseslint.config(
plugins: {
['@typescript-eslint']: tseslint.plugin,
['@typescript-eslint/internal']: tseslintInternalPlugin,
['deprecation']: deprecationPlugin,
// https://github.com/gund/eslint-plugin-deprecation/issues/78
// https://github.com/typescript-eslint/typescript-eslint/issues/8988
['deprecation']: fixupPluginRules(deprecationPlugin),
['eslint-comments']: eslintCommentsPlugin,
['eslint-plugin']: eslintPluginPlugin,
['import']: importPlugin,
// https://github.com/import-js/eslint-plugin-import/issues/2948
['import']: fixupPluginRules(importPlugin),
['jest']: jestPlugin,
['jsdoc']: jsdocPlugin,
['jsx-a11y']: jsxA11yPlugin,
['react-hooks']: reactHooksPlugin,
['react']: reactPlugin,
// https://github.com/facebook/react/issues/28313
['react-hooks']: fixupPluginRules(reactHooksPlugin),
// https://github.com/jsx-eslint/eslint-plugin-react/issues/3699
['react']: fixupPluginRules(reactPlugin),
['simple-import-sort']: simpleImportSortPlugin,
['unicorn']: unicornPlugin,
},
Expand Down Expand Up @@ -512,8 +518,8 @@ export default tseslint.config(
files: ['packages/website/**/*.{ts,tsx,mts,cts,js,jsx}'],
extends: [
...compat.config(jsxA11yPlugin.configs.recommended),
...compat.config(reactPlugin.configs.recommended),
...compat.config(reactHooksPlugin.configs.recommended),
...fixupConfigRules(compat.config(reactPlugin.configs.recommended)),
...fixupConfigRules(compat.config(reactHooksPlugin.configs.recommended)),
],
rules: {
'@typescript-eslint/internal/prefer-ast-types-enum': 'off',
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"@babel/eslint-parser": "^7.24.1",
"@babel/parser": "^7.24.4",
"@babel/types": "^7.24.0",
"@eslint/compat": "^1.0.1",
"@eslint/eslintrc": "^2.1.4",
"@eslint/js": "^8.57.0",
"@jest/types": "29.6.3",
Expand All @@ -85,7 +86,7 @@
"cross-fetch": "^4.0.0",
"cspell": "^8.6.1",
"downlevel-dts": ">=0.11.0",
"eslint": "8.57.0",
"eslint": "^9.3.0",
"eslint-plugin-deprecation": "^2.0.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-eslint-plugin": "^5.5.0",
Expand Down Expand Up @@ -129,7 +130,7 @@
"@types/estree": "link:./tools/dummypkg",
"@types/node": "^20.0.0",
"@types/react": "^18.2.14",
"eslint": "8.57.0",
"eslint": "^9",
"eslint-visitor-keys": "^3.4.1",
"jest-config": "^29",
"jest-resolve": "^29",
Expand Down
1 change: 0 additions & 1 deletion packages/eslint-plugin/rules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,4 @@ export type TypeScriptESLintRules = Record<
>;

declare const rules: TypeScriptESLintRules;
// eslint-disable-next-line import/no-default-export
export default rules;
1 change: 0 additions & 1 deletion packages/eslint-plugin/src/rules/prefer-regexp-exec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/prefer-literal-enum-member */
import type { TSESTree } from '@typescript-eslint/utils';
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
import * as tsutils from 'ts-api-utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,6 @@ const RawBaseCases = (operator: '&&' | '||') =>
] as const;

export const identity: MutateFn = c => c;
/*
eslint-disable-next-line eslint-plugin/prefer-message-ids, eslint-plugin/prefer-object-rule, eslint-plugin/require-meta-type, eslint-plugin/require-meta-schema --
TODO - bug in hte rules - https://github.com/eslint-community/eslint-plugin-eslint-plugin/issues/455
*/
export const BaseCases: BaseCaseCreator = ({
operator,
mutateCode = identity,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 0 additions & 30 deletions packages/integration-tests/fixtures/markdown/.eslintrc.js

This file was deleted.

15 changes: 15 additions & 0 deletions packages/integration-tests/fixtures/markdown/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import markdown from 'eslint-plugin-markdown';
import tseslint from 'typescript-eslint';

export default tseslint.config(
tseslint.configs.base,
// this will also ensure that eslint will force lint the markdown files
{ plugins: { markdown }, files: ['**/*.md'], processor: 'markdown/markdown' },
{
files: ['**/*.md/*.{js,ts,jsx,tsx,javascript,node}'],
rules: {
'@typescript-eslint/no-explicit-any': 'error',
'no-console': 'error',
},
},
);
1 change: 1 addition & 0 deletions packages/integration-tests/fixtures/markdown/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"type": "module",
"devDependencies": {
"eslint-plugin-markdown": "latest"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';

// This integration test exists to make sure that the recommended config does
// not require a program to be specified to ensure a fast and simple initial
// setup. Users can add on one of our other configs if they want to opt in to
// more expensive checks.
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
plugins: ['@typescript-eslint'],
};
export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
);
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"type": "module",
"devDependencies": {}
}
21 changes: 0 additions & 21 deletions packages/integration-tests/fixtures/vue-jsx/.eslintrc.js

This file was deleted.

13 changes: 13 additions & 0 deletions packages/integration-tests/fixtures/vue-jsx/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import tseslint from 'typescript-eslint';
import pluginVue from 'eslint-plugin-vue';

export default tseslint.config(
tseslint.configs.base,
...pluginVue.configs['flat/essential'],
{
languageOptions: {
parserOptions: { ecmaFeatures: { jsx: true }, parser: tseslint.parser },
},
rules: { '@typescript-eslint/no-explicit-any': 'error' },
},
);
1 change: 1 addition & 0 deletions packages/integration-tests/fixtures/vue-jsx/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"type": "module",
"devDependencies": {
"vue-eslint-parser": "latest",
"eslint-plugin-vue": "latest",
Expand Down
21 changes: 0 additions & 21 deletions packages/integration-tests/fixtures/vue-sfc/.eslintrc.js

This file was deleted.

20 changes: 20 additions & 0 deletions packages/integration-tests/fixtures/vue-sfc/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pluginVue from 'eslint-plugin-vue';
import tseslint from 'typescript-eslint';

export default tseslint.config(
tseslint.configs.base,
...pluginVue.configs['flat/essential'],
{
languageOptions: {
parserOptions: {
parser: tseslint.parser,
project: '/usr/linked/tsconfig.json',
},
},
rules: {
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'semi-spacing': 'error',
},
},
);
1 change: 1 addition & 0 deletions packages/integration-tests/fixtures/vue-sfc/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"type": "module",
"devDependencies": {
"vue-eslint-parser": "latest",
"eslint-plugin-vue": "latest",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,7 @@ exports[`recommended-does-not-require-program eslint should work successfully 1`
"output": "const foo: unknown = true;
",
"suppressedMessages": [],
"usedDeprecatedRules": [
{
"replacedBy": [],
"ruleId": "no-extra-semi",
},
{
"replacedBy": [],
"ruleId": "no-mixed-spaces-and-tabs",
},
],
"usedDeprecatedRules": [],
"warningCount": 0,
},
]
Expand Down
2 changes: 1 addition & 1 deletion packages/integration-tests/tests/flat-config-types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ for (const additionalFlags of [
},
);
}
eslintIntegrationTest(__filename, 'eslint.config.js', true);
eslintIntegrationTest(__filename, 'eslint.config.js');
3 changes: 0 additions & 3 deletions packages/integration-tests/tools/integration-test-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ function integrationTest(
export function eslintIntegrationTest(
testFilename: string,
filesGlob: string,
flatConfig = false,
): void {
integrationTest('eslint', testFilename, async testFolder => {
// lint, outputting to a JSON file
Expand All @@ -143,8 +142,6 @@ export function eslintIntegrationTest(
'json',
'--output-file',
outFile,
'--config',
flatConfig ? './eslint.config.js' : './.eslintrc.js',
'--fix-dry-run',
filesGlob,
],
Expand Down
Loading

0 comments on commit 86811d7

Please sign in to comment.