Skip to content

Commit

Permalink
feat(deps): update to @typescript-eslint/* v6 (#945)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDeBoey authored Oct 30, 2024
1 parent 33bde4f commit f07ee64
Show file tree
Hide file tree
Showing 17 changed files with 613 additions and 340 deletions.
15 changes: 2 additions & 13 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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': [
Expand All @@ -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: {
Expand Down
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
Expand Up @@ -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;
};
Expand Down
2 changes: 1 addition & 1 deletion lib/create-testing-library-rule/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
});
Expand Down
6 changes: 3 additions & 3 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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 }
>),
};

Expand Down
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';

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -295,7 +295,7 @@ export function getVariableReferences(
return [];
}

interface InnermostFunctionScope extends TSESLintScope.FunctionScope {
interface InnermostFunctionScope extends FunctionScope {
block:
| TSESTree.ArrowFunctionExpression
| TSESTree.FunctionDeclaration
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/await-async-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
],
},
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-debugging-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-dom-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
1 change: 1 addition & 0 deletions lib/rules/no-render-in-lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
properties: {
allowTestingFrameworkSetupHook: {
enum: TESTING_FRAMEWORK_SETUP_HOOKS,
type: 'string',
},
},
},
Expand Down
7 changes: 4 additions & 3 deletions lib/rules/prefer-explicit-assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
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 = (
Expand Down
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,
Expand Down
Loading

0 comments on commit f07ee64

Please sign in to comment.