Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .eslint-doc-generatorrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const prettier = require('prettier');

const prettierConfig = require('./.prettierrc.js');

/** @type {import('eslint-doc-generator').GenerateOptions} */
Expand Down
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

79 changes: 0 additions & 79 deletions .eslintrc.js

This file was deleted.

114 changes: 114 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// @ts-check

import js from '@eslint/js';
import { defineConfig, globalIgnores } from 'eslint/config';
import prettierConfig from 'eslint-config-prettier/flat';
import { importX } from 'eslint-plugin-import-x';
import jest from 'eslint-plugin-jest';
import * as jestFormatting from 'eslint-plugin-jest-formatting';
import globals from 'globals';
import tseslint from 'typescript-eslint';

const config = defineConfig(
js.configs.recommended,
tseslint.configs.recommendedTypeChecked,
importX.flatConfigs.recommended,
importX.flatConfigs.typescript,
{
name: 'Language options',
files: ['**/*.{js,mjs,cjs,ts,mts}'],
languageOptions: {
globals: {
...globals.node,
},
ecmaVersion: 'latest',
sourceType: 'module',
parser: tseslint.parser,
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
{
name: 'Rules overrides for all files',
rules: {
// Base
'max-lines-per-function': 'off',
'no-console': 'warn',

// TypeScript
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-unused-vars': [
'warn',
{
argsIgnorePattern: '^_',
},
],
'@typescript-eslint/no-use-before-define': 'off',

// Import
'import-x/order': [
'warn',
{
groups: [
'builtin',
'external',
'internal',
['parent', 'sibling', 'index'],
'object',
'type',
],
'newlines-between': 'always',

alphabetize: {
order: 'asc',
caseInsensitive: false,
},
},
],
'import-x/first': 'error',
'import-x/no-empty-named-blocks': 'error',
'import-x/no-extraneous-dependencies': 'error',
'import-x/no-mutable-exports': 'error',
'import-x/no-named-default': 'error',
'import-x/no-relative-packages': 'warn',
},
},
{
name: 'Rule overrides only for TypeScript files',
files: ['**/*.{ts,mts}'],
rules: {
// Rules enabled by `import-x/recommended` but are better handled by
// TypeScript and typescript-eslint.
'import-x/default': 'off',
'import-x/export': 'off',
'import-x/namespace': 'off',
'import-x/no-unresolved': 'off',
},
},
{
name: 'Jest config',
files: ['**/*.test.ts', '**/*.test.js'],
...jest.configs['flat/recommended'],
...jestFormatting.configs['flat/recommended'],
},
{
name: 'Plain JS',
files: ['**/*.{js,mjs,cjs}'],
extends: [tseslint.configs.disableTypeChecked],
},
{
name: 'Config files',
files: ['**/*rc*.{js,mjs,cjs}', '**/*.config.{js,cjs,mjs,ts}'],
rules: {
'@typescript-eslint/no-require-imports': 'off',
'import-x/no-named-as-default-member': 'off',
},
},
globalIgnores(['**/coverage/', '**/dist/']),
prettierConfig // must always be the last one
);

export default config;
9 changes: 3 additions & 6 deletions lib/configs/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { join } from 'path';

import type { TSESLint } from '@typescript-eslint/utils';
import { importDefault, SUPPORTED_TESTING_FRAMEWORKS } from '../utils';

import {
importDefault,
SUPPORTED_TESTING_FRAMEWORKS,
SupportedTestingFramework,
} from '../utils';
import type { SupportedTestingFramework } from '../utils';
import type { TSESLint } from '@typescript-eslint/utils';

const configsDir = __dirname;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ASTUtils, TSESLint, TSESTree } from '@typescript-eslint/utils';
import { ASTUtils } from '@typescript-eslint/utils';

import {
findClosestVariableDeclaratorNode,
Expand All @@ -9,7 +9,6 @@ import {
getPropertyIdentifierNode,
getReferenceNode,
hasImportMatch,
ImportModuleNode,
isCallExpression,
isImportDeclaration,
isImportDefaultSpecifier,
Expand All @@ -31,6 +30,9 @@ import {
isTestingLibraryModule,
} from '../utils/is-testing-library-module';

import type { ImportModuleNode } from '../node-utils';
import type { TSESLint, TSESTree } from '@typescript-eslint/utils';

const SETTING_OPTION_OFF = 'off';

export type TestingLibrarySettings = {
Expand Down Expand Up @@ -490,7 +492,6 @@ export function detectTestingLibraryUtils<
/**
* Determines whether a given node is fireEvent method or not
*/
// eslint-disable-next-line complexity
const isFireEventMethod: IsFireEventMethodFn = (node) => {
const fireEventUtil =
findImportedTestingLibraryUtilSpecifier(FIRE_EVENT_NAME);
Expand Down Expand Up @@ -527,7 +528,6 @@ export function detectTestingLibraryUtils<

// we know it's defined at this point, but TS seems to think it is not
// so here I'm enforcing it once in order to avoid using "!" operator every time
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const definedParentMemberExpression = parentMemberExpression!;

// check fireEvent.click() usage
Expand Down
10 changes: 5 additions & 5 deletions lib/create-testing-library-rule/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ESLintUtils } from '@typescript-eslint/utils';

import {
getDocsUrl,
import { getDocsUrl } from '../utils';
import { detectTestingLibraryUtils } from './detect-testing-library-utils';

import type {
TestingLibraryPluginDocs,
TestingLibraryPluginRuleModule,
} from '../utils';

import {
import type {
DetectionOptions,
detectTestingLibraryUtils,
EnhancedRuleCreate,
} from './detect-testing-library-utils';

Expand Down
6 changes: 3 additions & 3 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { TSESLint } from '@typescript-eslint/utils';

import configs from './configs';
import rules from './rules';
import { SupportedTestingFramework } from './utils';

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

// we can't natively import package.json as tsc will copy it into dist/
const {
Expand Down
14 changes: 5 additions & 9 deletions lib/node-utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { FunctionScope, ScopeType } from '@typescript-eslint/scope-manager';
import {
AST_NODE_TYPES,
ASTUtils,
TSESLint,
TSESTree,
} from '@typescript-eslint/utils';
import { ScopeType } from '@typescript-eslint/scope-manager';
import { AST_NODE_TYPES, ASTUtils } from '@typescript-eslint/utils';

import { getDeclaredVariables, getScope } from '../utils';

import {
isArrayExpression,
isArrowFunctionExpression,
Expand All @@ -28,6 +22,9 @@ import {
isVariableDeclaration,
} from './is-node-of-type';

import type { FunctionScope } from '@typescript-eslint/scope-manager';
import type { TSESLint, TSESTree } from '@typescript-eslint/utils';

export * from './is-node-of-type';

const ValidLeftHandSideExpressions = [
Expand Down Expand Up @@ -301,7 +298,6 @@ export function getVariableReferences(
node: TSESTree.Node
): TSESLint.Scope.Reference[] {
if (ASTUtils.isVariableDeclarator(node)) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
return getDeclaredVariables(context, node)[0]?.references?.slice(1) ?? [];
}

Expand Down
4 changes: 3 additions & 1 deletion lib/rules/await-async-events.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ASTUtils, TSESLint, TSESTree } from '@typescript-eslint/utils';
import { ASTUtils } from '@typescript-eslint/utils';

import { createTestingLibraryRule } from '../create-testing-library-rule';
import {
Expand All @@ -12,6 +12,8 @@ import {
} from '../node-utils';
import { EVENTS_SIMULATORS } from '../utils';

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

export const RULE_NAME = 'await-async-events';
export type MessageIds = 'awaitAsyncEvent' | 'awaitAsyncEventWrapper';
const FIRE_EVENT_NAME = 'fireEvent';
Expand Down
4 changes: 3 additions & 1 deletion lib/rules/await-async-queries.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ASTUtils, TSESTree } from '@typescript-eslint/utils';
import { ASTUtils } from '@typescript-eslint/utils';

import { createTestingLibraryRule } from '../create-testing-library-rule';
import {
Expand All @@ -10,6 +10,8 @@ import {
isPromiseHandled,
} from '../node-utils';

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

export const RULE_NAME = 'await-async-queries';
export type MessageIds = 'asyncQueryWrapper' | 'awaitAsyncQuery';
type Options = [];
Expand Down
4 changes: 3 additions & 1 deletion lib/rules/await-async-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TSESTree, ASTUtils } from '@typescript-eslint/utils';
import { ASTUtils } from '@typescript-eslint/utils';

import { createTestingLibraryRule } from '../create-testing-library-rule';
import {
Expand All @@ -13,6 +13,8 @@ import {
isProperty,
} from '../node-utils';

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

export const RULE_NAME = 'await-async-utils';
export type MessageIds = 'asyncUtilWrapper' | 'awaitAsyncUtil';
type Options = [];
Expand Down
4 changes: 3 additions & 1 deletion lib/rules/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { readdirSync } from 'fs';
import { join, parse } from 'path';

import { importDefault, TestingLibraryPluginRuleModule } from '../utils';
import { importDefault } from '../utils';

import type { TestingLibraryPluginRuleModule } from '../utils';

const rulesDir = __dirname;
const excludedFiles = ['index'];
Expand Down
4 changes: 3 additions & 1 deletion lib/rules/no-await-sync-events.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ASTUtils, TSESTree } from '@typescript-eslint/utils';
import { ASTUtils } from '@typescript-eslint/utils';

import { createTestingLibraryRule } from '../create-testing-library-rule';
import {
Expand All @@ -9,6 +9,8 @@ import {
isProperty,
} from '../node-utils';

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

const USER_EVENT_ASYNC_EXCEPTIONS = ['type', 'keyboard'];
const FIRE_EVENT_OPTION = 'fire-event';
const USER_EVENT_OPTION = 'user-event';
Expand Down
Loading