Skip to content

feat(deps): update to @typescript-eslint/* v6 #945

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

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -14,17 +14,6 @@ module.exports = {
rules: {
// Base
'max-lines-per-function': 'off',
'no-restricted-imports': [
'error',
{
patterns: [
{
group: ['@typescript-eslint/utils/dist/*'],
message: 'Import from `@typescript-eslint/utils` instead.',
},
],
},
],

// Import
'import/order': [
@@ -51,12 +40,12 @@ module.exports = {
files: ['**/*.ts?(x)'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.eslint.json',
tsconfigRootDir: __dirname,
project: ['./tsconfig.eslint.json'],
},
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:import/typescript',
],
rules: {
8 changes: 3 additions & 5 deletions lib/configs/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import { join } from 'path';

import { type TSESLint } from '@typescript-eslint/utils';
import type { TSESLint } from '@typescript-eslint/utils';

import {
importDefault,
SUPPORTED_TESTING_FRAMEWORKS,
SupportedTestingFramework,
} from '../utils';

export type LinterConfigRules = Pick<Required<TSESLint.Linter.Config>, 'rules'>;

const configsDir = __dirname;

const getConfigForFramework = (framework: SupportedTestingFramework) =>
importDefault<LinterConfigRules>(join(configsDir, framework));
importDefault<TSESLint.SharedConfig.RulesRecord>(join(configsDir, framework));

export default SUPPORTED_TESTING_FRAMEWORKS.reduce(
(allConfigs, framework) => ({
...allConfigs,
[framework]: getConfigForFramework(framework),
}),
{}
) as Record<SupportedTestingFramework, LinterConfigRules>;
) as Record<SupportedTestingFramework, TSESLint.SharedConfig.RulesRecord>;
Original file line number Diff line number Diff line change
@@ -28,7 +28,9 @@ import {
const SETTING_OPTION_OFF = 'off' as const;

export type TestingLibrarySettings = {
'testing-library/utils-module'?: string | typeof SETTING_OPTION_OFF;
'testing-library/utils-module'?:
| typeof SETTING_OPTION_OFF
| (string & NonNullable<unknown>);
'testing-library/custom-renders'?: string[] | typeof SETTING_OPTION_OFF;
'testing-library/custom-queries'?: string[] | typeof SETTING_OPTION_OFF;
};
2 changes: 1 addition & 1 deletion lib/create-testing-library-rule/index.ts
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ export function createTestingLibraryRule<
...meta.docs,
// We're using our own recommendedConfig meta to tell our build tools
// if the rule is recommended on a config basis
recommended: false,
recommended: undefined,
},
},
});
6 changes: 3 additions & 3 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ const plugin = {
// we don't have types for flat config yet
configs: {} as Record<
SupportedTestingFramework | `flat/${SupportedTestingFramework}`,
Pick<Required<TSESLint.Linter.Config>, 'rules'>
TSESLint.SharedConfig.RulesRecord
>,
rules,
};
@@ -35,9 +35,9 @@ plugin.configs = {
rules: config.rules,
},
])
) as Record<
) as unknown as Record<
`flat/${SupportedTestingFramework}`,
Pick<Required<TSESLint.Linter.Config>, 'rules'> & { plugins: unknown }
TSESLint.SharedConfig.RulesRecord & { plugins: unknown }
>),
};

8 changes: 4 additions & 4 deletions lib/node-utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { FunctionScope, ScopeType } from '@typescript-eslint/scope-manager';
import {
AST_NODE_TYPES,
ASTUtils,
TSESLint,
TSESLintScope,
TSESTree,
} from '@typescript-eslint/utils';

@@ -188,7 +188,7 @@ export function isPromiseAllSettled(node: TSESTree.CallExpression): boolean {
}

/**
* Determines whether a given node belongs to handled Promise.all or Promise.allSettled
* Determines whether a given node belongs to handled `Promise.all` or `Promise.allSettled`
* array expression.
*/
export function isPromisesArrayResolved(node: TSESTree.Node): boolean {
@@ -295,7 +295,7 @@ export function getVariableReferences(
return [];
}

interface InnermostFunctionScope extends TSESLintScope.FunctionScope {
interface InnermostFunctionScope extends FunctionScope {
block:
| TSESTree.ArrowFunctionExpression
| TSESTree.FunctionDeclaration
@@ -312,7 +312,7 @@ export function getInnermostFunctionScope(
);

if (
innermostScope.type === 'function' &&
innermostScope.type === ScopeType.function &&
ASTUtils.isFunction(innermostScope.block)
) {
return innermostScope as unknown as InnermostFunctionScope;
6 changes: 3 additions & 3 deletions lib/rules/await-async-events.ts
Original file line number Diff line number Diff line change
@@ -55,15 +55,15 @@ export default createTestingLibraryRule<Options, MessageIds>({
default: USER_EVENT_NAME,
oneOf: [
{
enum: EVENTS_SIMULATORS.concat(),
type: 'string',
enum: EVENTS_SIMULATORS,
},
{
type: 'array',
items: {
type: 'string',
enum: EVENTS_SIMULATORS,
enum: EVENTS_SIMULATORS.concat(),
},
type: 'array',
},
],
},
2 changes: 1 addition & 1 deletion lib/rules/no-debugging-utils.ts
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
utilsToCheckFor: {
type: 'object',
properties: DEBUG_UTILS.reduce<
Record<string, JSONSchema.JSONSchema7>
Record<string, JSONSchema.JSONSchema4>
>(
(obj, name) => ({
[name]: { type: 'boolean' },
2 changes: 1 addition & 1 deletion lib/rules/no-dom-import.ts
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ const DOM_TESTING_LIBRARY_MODULES = [
];

const CORRECT_MODULE_NAME_BY_FRAMEWORK: Record<
'angular' | 'marko' | string,
'angular' | 'marko' | (string & NonNullable<unknown>),
string | undefined
> = {
angular: '@testing-library/angular', // ATL is *always* called `@testing-library/angular`
1 change: 1 addition & 0 deletions lib/rules/no-render-in-lifecycle.ts
Original file line number Diff line number Diff line change
@@ -68,6 +68,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
properties: {
allowTestingFrameworkSetupHook: {
enum: TESTING_FRAMEWORK_SETUP_HOOKS,
type: 'string',
},
},
},
7 changes: 4 additions & 3 deletions lib/rules/prefer-explicit-assert.ts
Original file line number Diff line number Diff line change
@@ -21,10 +21,11 @@ type Options = [

const isAtTopLevel = (node: TSESTree.Node) =>
(!!node.parent?.parent &&
node.parent.parent.type === 'ExpressionStatement') ||
(node.parent?.parent?.type === 'AwaitExpression' &&
node.parent.parent.type === TSESTree.AST_NODE_TYPES.ExpressionStatement) ||
(node.parent?.parent?.type === TSESTree.AST_NODE_TYPES.AwaitExpression &&
!!node.parent.parent.parent &&
node.parent.parent.parent.type === 'ExpressionStatement');
node.parent.parent.parent.type ===
TSESTree.AST_NODE_TYPES.ExpressionStatement);

const isVariableDeclaration = (node: TSESTree.Node) => {
if (
48 changes: 1 addition & 47 deletions lib/utils/compat.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,4 @@
import { type TSESLint, type TSESTree } from '@typescript-eslint/utils';

declare module '@typescript-eslint/utils/dist/ts-eslint/Rule' {
export interface RuleContext<
// eslint-disable-next-line @typescript-eslint/no-unused-vars
TMessageIds extends string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
TOptions extends readonly unknown[],
> {
/**
* The filename associated with the source.
*/
filename: string;

/**
* A SourceCode object that you can use to work with the source that
* was passed to ESLint.
*/
sourceCode: Readonly<TSESLint.SourceCode>;
}
}

declare module '@typescript-eslint/utils/dist/ts-eslint/SourceCode' {
export interface SourceCode {
/**
* Returns the scope of the given node.
* This information can be used track references to variables.
* @since 8.37.0
*/
getScope(node: TSESTree.Node): TSESLint.Scope.Scope;
/**
* Returns an array of the ancestors of the given node, starting at
* the root of the AST and continuing through the direct parent of the current node.
* This array does not include the currently-traversed node itself.
* @since 8.38.0
*/
getAncestors(node: TSESTree.Node): TSESTree.Node[];
/**
* Returns a list of variables declared by the given node.
* This information can be used to track references to variables.
* @since 8.38.0
*/
getDeclaredVariables(
node: TSESTree.Node
): readonly TSESLint.Scope.Variable[];
}
}
import type { TSESLint, TSESTree } from '@typescript-eslint/utils';

/* istanbul ignore next */
export const getFilename = (
9 changes: 5 additions & 4 deletions lib/utils/types.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { type TSESLint } from '@typescript-eslint/utils';

type Recommended = 'error' | 'warn' | false;
type RecommendedConfig<TOptions extends readonly unknown[]> =
| TSESLint.RuleMetaDataDocs['recommended']
| [TSESLint.RuleMetaDataDocs['recommended'], ...TOptions];
| Recommended
| [Recommended, ...TOptions];

// These 2 types are copied from @typescript-eslint/utils' CreateRuleMeta
// These 2 types are copied from `@typescript-eslint/utils`' `CreateRuleMeta`
// and modified to our needs
export type TestingLibraryRuleMetaDocs<TOptions extends readonly unknown[]> =
Omit<TSESLint.RuleMetaDataDocs, 'recommended' | 'url'> & {
/**
* The recommendation level for the rule on a framework basis.
* Used by the build tools to generate the framework config.
* Set to false to not include it the config
* Set to `false` to not include it the config
*/
recommendedConfig: Record<
SupportedTestingFramework,
714 changes: 575 additions & 139 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -51,7 +51,8 @@
"type-check": "tsc --noEmit"
},
"dependencies": {
"@typescript-eslint/utils": "^5.62.0"
"@typescript-eslint/scope-manager": "^6.21.0",
"@typescript-eslint/utils": "^6.21.0"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be:

"@typescript-eslint/utils": "^8.12.0"

?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because this pull request is upgrading them to v6, not v8

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! I see there is a #947 v7 and presumably v8 will happen at some point.

},
"devDependencies": {
"@babel/core": "^7.25.8",
@@ -63,8 +64,8 @@
"@swc/jest": "^0.2.36",
"@types/jest": "^27.5.2",
"@types/node": "^20.16.12",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"del-cli": "^5.1.0",
"eslint": "^8.57.1",
"eslint-config-prettier": "^9.1.0",
112 changes: 1 addition & 111 deletions tests/lib/FlatCompatRuleTester.ts
Original file line number Diff line number Diff line change
@@ -4,117 +4,6 @@ import * as semver from 'semver';

export const usingFlatConfig = semver.major(eslintVersion) >= 9;

declare module '@typescript-eslint/utils/dist/ts-eslint' {
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace FlatConfig {
export interface LinterOptions {
/**
* A Boolean value indicating if inline configuration is allowed.
*/
noInlineConfig?: boolean;
/**
* A severity string indicating if and how unused disable and enable
* directives should be tracked and reported. For legacy compatibility, `true`
* is equivalent to `"warn"` and `false` is equivalent to `"off"`.
* @default "off"
*/
reportUnusedDisableDirectives?:
| TSESLint.Linter.Severity
| TSESLint.Linter.SeverityString
| boolean;
}

export interface Config {
/**
* An string to identify the configuration object. Used in error messages and inspection tools.
*/
name?: string;
/**
* An array of glob patterns indicating the files that the configuration object should apply to.
* If not specified, the configuration object applies to all files matched by any other configuration object.
*/
files?: (string | string[])[];
/**
* An array of glob patterns indicating the files that the configuration object should not apply to.
* If not specified, the configuration object applies to all files matched by files.
*/
ignores?: string[];
/**
* An object containing settings related to how JavaScript is configured for linting.
*/
languageOptions?: LanguageOptions;
/**
* An object containing settings related to the linting process.
*/
linterOptions?: LinterOptions;
/**
* An object containing a name-value mapping of plugin names to plugin objects.
* When `files` is specified, these plugins are only available to the matching files.
*/
plugins?: unknown;
/**
* Either an object containing `preprocess()` and `postprocess()` methods or
* a string indicating the name of a processor inside of a plugin
* (i.e., `"pluginName/processorName"`).
*/
processor?: string | TSESLint.Linter.Processor;
/**
* An object containing the configured rules.
* When `files` or `ignores` are specified, these rule configurations are only available to the matching files.
*/
rules?: TSESLint.Linter.RulesRecord;
/**
* An object containing name-value pairs of information that should be available to all rules.
*/
settings?: TSESLint.SharedConfigurationSettings;
}

export type ParserOptions = TSESLint.Linter.ParserOptions;

export interface LanguageOptions {
/**
* The version of ECMAScript to support.
* May be any year (i.e., `2022`) or version (i.e., `5`).
* Set to `"latest"` for the most recent supported version.
* @default "latest"
*/
ecmaVersion?: Required<TSESLint.ParserOptions>['ecmaVersion'];
/**
* An object specifying additional objects that should be added to the global scope during linting.
*/
globals?:
| Record<string, 'readonly' | 'writable' | 'off' | true>
| undefined;
/**
* An object containing a `parse()` method or a `parseForESLint()` method.
* @default
* ```
* // https://github.com/eslint/espree
* require('espree')
* ```
*/
parser?: unknown;
/**
* An object specifying additional options that are passed directly to the parser.
* The available options are parser-dependent.
*/
parserOptions?: ParserOptions | undefined;
/**
* The type of JavaScript source code.
* Possible values are `"script"` for traditional script files, `"module"` for ECMAScript modules (ESM), and `"commonjs"` for CommonJS files.
* @default
* ```
* // for `.js` and `.mjs` files
* "module"
* // for `.cjs` files
* "commonjs"
* ```
*/
sourceType?: Required<TSESLint.ParserOptions>['sourceType'];
}
}
}

export class FlatCompatRuleTester extends TSESLint.RuleTester {
public constructor(testerConfig?: TSESLint.RuleTesterConfig) {
super(FlatCompatRuleTester._flatCompat(testerConfig));
@@ -157,6 +46,7 @@ export class FlatCompatRuleTester extends TSESLint.RuleTester {

for (const [key, value] of Object.entries(config)) {
if (key === 'parser') {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
obj.languageOptions.parser = require(value as string);

continue;
2 changes: 1 addition & 1 deletion tests/lib/test-utils.ts
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ export const createRuleTester = (
parserOptions: Partial<TSESLint.ParserOptions> = {}
): TSESLint.RuleTester => {
return new TestingLibraryRuleTester({
parser: resolve('./node_modules/@typescript-eslint/parser'),
parser: resolve('./node_modules/@typescript-eslint/parser/dist'),
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',