Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support ESLint v9 #9002

Merged
merged 30 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3cfccd8
feat: support ESLint 9
JoshuaKGoldberg Apr 26, 2024
6f4fdd7
Fix some eslint-plugin tests
JoshuaKGoldberg Apr 26, 2024
7c3a185
Re-add v8 and remove unnecessary peerDependencies
JoshuaKGoldberg Apr 28, 2024
eae61eb
Fix no-unused-vars test rule
JoshuaKGoldberg Apr 28, 2024
0cd79cb
Merge branch 'v8' into eslint-9
JoshuaKGoldberg Apr 29, 2024
4aeed8a
Merge branch 'v8' into eslint-9
JoshuaKGoldberg Apr 29, 2024
13f3964
Updated snapshots
JoshuaKGoldberg Apr 29, 2024
0948bf2
put back [email protected]
JoshuaKGoldberg Apr 30, 2024
8bcb0e2
Fixed linting by disabling plugins temporarily
JoshuaKGoldberg Apr 30, 2024
e9b8908
Update two more integration snapshots for no-unused-vars
JoshuaKGoldberg Apr 30, 2024
1fc6fa2
Ugh, missing "
JoshuaKGoldberg Apr 30, 2024
e053179
Remove legacy rule function form
JoshuaKGoldberg May 7, 2024
b9f681f
Merge branch 'v8'
JoshuaKGoldberg May 7, 2024
6b6e249
Fix legacy-config test to actually use legacy config
JoshuaKGoldberg May 8, 2024
bc6d611
Revert "Remove legacy rule function form"
JoshuaKGoldberg May 8, 2024
0451e84
Update ESLint 8/9 RuleCreateFunction comments
JoshuaKGoldberg May 8, 2024
129eb65
Start reverting the local dev changes
JoshuaKGoldberg May 9, 2024
88024e2
Some more reverts
JoshuaKGoldberg May 9, 2024
1cae50d
oopsies comment level
JoshuaKGoldberg May 9, 2024
2bb898a
yarn test -u the integration tests
JoshuaKGoldberg May 9, 2024
8d893a4
Merge branch 'v8' into eslint-9
JoshuaKGoldberg May 9, 2024
53193dd
regenerate yarn.lock
JoshuaKGoldberg May 9, 2024
ed41f48
yarn dedupe, and undo some eslint.config changes
JoshuaKGoldberg May 9, 2024
0594a7a
Remove extra node:
JoshuaKGoldberg May 9, 2024
5b4c85f
Finally revert nodeType changes
JoshuaKGoldberg May 9, 2024
175c292
one more deprecation fix
JoshuaKGoldberg May 9, 2024
9a7d27f
Update eslint-plugin schemas snapshot
JoshuaKGoldberg May 9, 2024
4a79978
Annoying tmp version update
JoshuaKGoldberg May 9, 2024
72d19bd
Add eslint_v9_tests
JoshuaKGoldberg May 9, 2024
ee1d91c
Fix yarn.lock
JoshuaKGoldberg May 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 23 additions & 15 deletions eslint.config.mjs
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ export default tseslint.config(
},
rules: {
// make sure we're not leveraging any deprecated APIs
'deprecation/deprecation': 'error',
// TODO: Bring this back in once it supports ESLint 9
// 'deprecation/deprecation': 'error',

// TODO(#7130): Investigate changing these in or removing these from presets
'@typescript-eslint/no-confusing-void-expression': 'off',
Expand Down Expand Up @@ -239,11 +240,13 @@ export default tseslint.config(
// disallow non-import statements appearing before import statements
'import/first': 'error',
// Require a newline after the last import/require in a group
'import/newline-after-import': 'error',
// TODO: Bring this back in once it supports ESLint 9
// 'import/newline-after-import': 'error',
// Forbid import of modules using absolute paths
'import/no-absolute-path': 'error',
// disallow AMD require/define
'import/no-amd': 'error',
// TODO: Bring this back in once it supports ESLint 9
// 'import/no-amd': 'error',
// forbid default exports - we want to standardize on named exports so that imported names are consistent
'import/no-default-export': 'error',
// disallow imports from duplicate paths
Expand All @@ -258,7 +261,8 @@ export default tseslint.config(
},
],
// Forbid mutable exports
'import/no-mutable-exports': 'error',
// TODO: Bring this back in once it supports ESLint 9
// 'import/no-mutable-exports': 'error',
// Prevent importing the default as if it were named
'import/no-named-default': 'error',
// Prohibit named exports
Expand Down Expand Up @@ -299,7 +303,7 @@ export default tseslint.config(
extends: [tseslint.configs.disableTypeChecked],
rules: {
// turn off other type-aware rules
'deprecation/deprecation': 'off',
// 'deprecation/deprecation': 'off',
'@typescript-eslint/internal/no-poorly-typed-ts-props': 'off',

// turn off rules that don't apply to JS code
Expand Down Expand Up @@ -498,21 +502,25 @@ 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),
// TODO: Bring this back in once it supports ESLint 9
// https://github.com/jsx-eslint/eslint-plugin-react/issues/3699
// ...compat.config(reactPlugin.configs.recommended),
// TODO: Bring this back in once it supports ESLint 9
// https://github.com/facebook/react/issues/28313
// ...compat.config(reactHooksPlugin.configs.recommended),
],
rules: {
'@typescript-eslint/internal/prefer-ast-types-enum': 'off',
'import/no-default-export': 'off',
'react/jsx-no-target-blank': 'off',
'react/no-unescaped-entities': 'off',
'react-hooks/exhaustive-deps': 'warn', // TODO: enable it later
},
settings: {
react: {
version: 'detect',
},
// 'react/jsx-no-target-blank': 'off',
// 'react/no-unescaped-entities': 'off',
// 'react-hooks/exhaustive-deps': 'warn', // TODO: enable it later
},
// settings: {
// react: {
// version: 'detect',
// },
// },
},
{
files: ['packages/website/src/**/*.{ts,tsx,cts,mts}'],
Expand Down
8 changes: 5 additions & 3 deletions package.json
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"@babel/eslint-parser": "^7.24.1",
"@babel/parser": "^7.24.4",
"@babel/types": "^7.24.0",
"@eslint/eslintrc": "^2.1.4",
"@eslint/eslintrc": "^3.0.2",
"@eslint/js": "^8.57.0",
"@nx/eslint": "18.2.3",
"@nx/jest": "18.2.3",
Expand All @@ -87,7 +87,7 @@
"cross-fetch": "^4.0.0",
"cspell": "^8.6.1",
"downlevel-dts": ">=0.11.0",
"eslint": "8.57.0",
"eslint": "9.1.1",
"eslint-plugin-deprecation": "^2.0.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-eslint-plugin": "^5.5.0",
Expand Down Expand Up @@ -124,6 +124,8 @@
"yargs": "17.7.2"
},
"resolutions": {
"@eslint/eslintrc": "^3.0.2",
"@eslint/js": "9.1.1",
"@jest/create-cache-key-function": "^29",
"@jest/reporters": "^29",
"@jest/test-result": "^29",
Expand All @@ -133,7 +135,7 @@
"@types/estree": "link:./tools/dummypkg",
"@types/node": "^20.0.0",
"@types/react": "^18.2.14",
"eslint": "8.57.0",
"eslint": "9.1.1",
"eslint-visitor-keys": "^3.4.1",
"jest-config": "^29",
"jest-resolve": "^29",
Expand Down

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

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

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

2 changes: 1 addition & 1 deletion packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
},
"peerDependencies": {
"@typescript-eslint/parser": "^7.0.0",
"eslint": "^8.57.0"
"eslint": "^8.57.0 || ^9.0.0"
},
"peerDependenciesMeta": {
"typescript": {
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-plugin/rules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ export type TypeScriptESLintRules = Record<
RuleModule<string, unknown[]>
>;
declare const rules: TypeScriptESLintRules;
// eslint-disable-next-line import/no-default-export
// TODO: Bring this back in once it supports ESLint 9
// (eslint-disable-next-line) import/no-default-export
export default rules;
3 changes: 3 additions & 0 deletions packages/eslint-plugin/src/rules/no-unused-vars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,9 @@ export default createRule<Options, MessageIds>({
};

context.report({
node: writeReferences.length
? writeReferences[writeReferences.length - 1].identifier
: unusedVar.identifiers[0],
loc,
messageId: 'unusedVar',
data: unusedVar.references.some(ref => ref.isWrite())
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/tests/docs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function renderLintResults(code: string, errors: Linter.LintMessage[]): string {
return output.join('\n').trim() + '\n';
}

const linter = new Linter();
const linter = new Linter({ configType: 'eslintrc' });
linter.defineParser('@typescript-eslint/parser', tseslintParser);

const eslintOutputSnapshotFolder = path.resolve(
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/tests/rules/array-type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1924,7 +1924,7 @@ interface FooInterface {
// -- eslint rule tester is not working with multi-pass
// https://github.com/eslint/eslint/issues/11187
describe('array-type (nested)', () => {
const linter = new TSESLint.Linter();
const linter = new TSESLint.Linter({ configType: 'eslintrc' });
linter.defineRule('array-type', rule);
linter.defineParser('@typescript-eslint/parser', parser);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable deprecation/deprecation -- TODO - migrate this test away from `batchedSingleLineTests` */
// TODO: Bring this back in once it supports ESLint 9
/* (eslint-disable) deprecation/deprecation -- TODO - migrate this test away from `batchedSingleLineTests` */

import { RuleTester } from '@typescript-eslint/rule-tester';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,25 @@ const ruleTester = new RuleTester({
},
});

ruleTester.defineRule('use-every-a', context => {
/**
* Mark a variable as used
*/
function useA(node: TSESTree.Node): void {
context.sourceCode.markVariableAsUsed('a', node);
}
return {
VariableDeclaration: useA,
ReturnStatement: useA,
};
ruleTester.defineRule('use-every-a', {
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
create: context => {
/**
* Mark a variable as used
*/
function useA(node: TSESTree.Node): void {
context.sourceCode.markVariableAsUsed('a', node);
}
return {
VariableDeclaration: useA,
ReturnStatement: useA,
};
},
defaultOptions: [],
meta: {
messages: {},
type: 'problem',
schema: [],
},
});

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,17 @@ const withMetaParserOptions = {
};

// this is used to ensure that the caching the utility does does not impact the results done by no-unused-vars
ruleTester.defineRule('collect-unused-vars', context => {
collectUnusedVariables(context);
return {};
ruleTester.defineRule('collect-unused-vars', {
create(context) {
collectUnusedVariables(context);
return {};
},
defaultOptions: [],
meta: {
messages: {},
type: 'problem',
schema: [],
},
});

ruleTester.run('no-unused-vars', rule, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable deprecation/deprecation -- TODO - migrate this test away from `batchedSingleLineTests` */
// TODO: Bring this back in once it supports ESLint 9
/* (eslint-disable) deprecation/deprecation -- TODO - migrate this test away from `batchedSingleLineTests` */

import { noFormat, RuleTester } from '@typescript-eslint/rule-tester';
import * as path from 'path';
Expand Down

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

23 changes: 23 additions & 0 deletions packages/integration-tests/fixtures/legacy-config/.eslintrc.js
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const eslint = require('@eslint/js');
const tseslint = require('typescript-eslint');

module.exports = tseslint.config({
extends: [
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
],
languageOptions: {
parser: tseslint.parser,
parserOptions: {
project: true,
tsconfigRootDir: __dirname,
},
},
plugins: {
'@typescript-eslint': tseslint.plugin,
},
rules: {
'@typescript-eslint/no-unsafe-argument': 'warn',
'@typescript-eslint/no-unsafe-return': 'warn',
},
});
8 changes: 8 additions & 0 deletions packages/integration-tests/fixtures/legacy-config/file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
async function unsafeLog(...values: any[]) {
for (const value of values) {
console.log(value.toUpperCase());
}
return values;
}

unsafeLog();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"noEmit": true,
"strict": true
},
"include": ["file.ts"]
}
30 changes: 0 additions & 30 deletions packages/integration-tests/fixtures/markdown/.eslintrc.js

This file was deleted.