Skip to content

Commit

Permalink
feat: support ESLint v9 (#9002)
Browse files Browse the repository at this point in the history
* feat: support ESLint 9

* Fix some eslint-plugin tests

* Re-add v8 and remove unnecessary peerDependencies

* Fix no-unused-vars test rule

* Updated snapshots

* put back tmp@0.2.1

* Fixed linting by disabling plugins temporarily

* Update two more integration snapshots for no-unused-vars

* Ugh, missing "

* Remove legacy rule function form

* Fix legacy-config test to actually use legacy config

* Revert "Remove legacy rule function form"

This reverts commit e053179.

* Update ESLint 8/9 RuleCreateFunction comments

* Start reverting the local dev changes

* Some more reverts

* oopsies comment level

* yarn test -u the integration tests

* regenerate yarn.lock

* yarn dedupe, and undo some eslint.config changes

* Remove extra node:

* Finally revert nodeType changes

* one more deprecation fix

* Update eslint-plugin schemas snapshot

* Annoying tmp version update

* Add eslint_v9_tests

* Fix yarn.lock
  • Loading branch information
JoshuaKGoldberg committed May 12, 2024
1 parent fd097ef commit b765f7b
Show file tree
Hide file tree
Showing 20 changed files with 76 additions and 140 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,25 @@ 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

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
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
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', {
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
2 changes: 1 addition & 1 deletion packages/parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"peerDependencies": {
"eslint": "^8.57.0"
"eslint": "^8.57.0 || ^9.0.0"
},
"dependencies": {
"@typescript-eslint/scope-manager": "7.8.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/rule-tester/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
},
"peerDependencies": {
"@eslint/eslintrc": ">=2",
"eslint": "^8.57.0"
"eslint": "^8.57.0 || ^9.0.0"
},
"devDependencies": {
"@types/lodash.merge": "4.6.9",
Expand Down
2 changes: 1 addition & 1 deletion packages/rule-tester/src/RuleTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ let defaultConfig = deepMerge(
export class RuleTester extends TestFramework {
readonly #testerConfig: TesterConfigWithDefaults;
readonly #rules: Record<string, AnyRuleCreateFunction | AnyRuleModule> = {};
readonly #linter: Linter = new Linter();
readonly #linter: Linter = new Linter({ configType: 'eslintrc' });

/**
* Creates a new instance of RuleTester.
Expand Down
3 changes: 0 additions & 3 deletions packages/type-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@
"rimraf": "*",
"typescript": "*"
},
"peerDependencies": {
"eslint": "^8.57.0"
},
"peerDependenciesMeta": {
"typescript": {
"optional": true
Expand Down
3 changes: 0 additions & 3 deletions packages/typescript-eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@
"test": "jest --coverage --passWithNoTests",
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"peerDependencies": {
"eslint": "^8.57.0"
},
"dependencies": {
"@typescript-eslint/eslint-plugin": "7.8.0",
"@typescript-eslint/parser": "7.8.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"semver": "^7.6.0"
},
"peerDependencies": {
"eslint": "^8.57.0"
"eslint": "^8.57.0 || ^9.0.0"
},
"devDependencies": {
"@typescript-eslint/parser": "7.8.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/ts-eslint/Linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ namespace Linter {
parserOptions?: ParserOptions;
}

// TODO - RuleCreateFunction is no longer supported in ESLint v9
// TODO - remove RuleCreateFunction once we no longer support ESLint 8
export type LegacyPluginRules = Record<
string,
AnyRuleCreateFunction | AnyRuleModule
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/ts-eslint/Rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ export type AnyRuleModuleWithMetaDocs = RuleModuleWithMetaDocs<
* @see {@link LooseParserModule}, {@link LooseProcessorModule}
*/
export type LooseRuleDefinition =
// TODO - ESLint v9 will remove support for RuleCreateFunction
// TODO - remove RuleCreateFunction once we no longer support ESLint 8
| LooseRuleCreateFunction
| {
meta?: object | undefined;
Expand Down
2 changes: 1 addition & 1 deletion packages/website-eslint/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ exports.astConverter = astConverter;
exports.esquery = esquery;

exports.createLinter = function () {
const linter = new Linter();
const linter = new Linter({ configType: 'eslintrc' });
for (const name in plugin.rules) {
linter.defineRule(`@typescript-eslint/${name}`, plugin.rules[name]);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/website-eslint/types/eslint.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ it just uses `any` for the import - marking it as an untyped export. So adding t
cannot use VSCode's cache ever - stubbing it out permanently.
*/
declare module 'eslint' {
export interface LinterOptions {
configType?: 'eslintrc';
}
export class Linter {
constructor(options: LinterOptions);
defineRule(name: string, rule: unknown): void;
}
}

0 comments on commit b765f7b

Please sign in to comment.