119 lines
4.2 KiB
JavaScript
119 lines
4.2 KiB
JavaScript
import { createRequire } from 'node:module';
|
|
import { fixupConfigRules } from '@eslint/compat';
|
|
import globals from 'globals';
|
|
import js from '@eslint/js';
|
|
import airbnb from 'eslint-config-airbnb';
|
|
import prettier from 'eslint-config-prettier';
|
|
import tsParser from '@typescript-eslint/parser';
|
|
import tsPlugin from '@typescript-eslint/eslint-plugin';
|
|
import importPlugin from 'eslint-plugin-import';
|
|
import jsxAllyPlugin from 'eslint-plugin-jsx-a11y';
|
|
import reactPlugin from 'eslint-plugin-react';
|
|
import reactHooksPlugin from 'eslint-plugin-react-hooks';
|
|
|
|
const require = createRequire(import.meta.url);
|
|
|
|
// Config entries without `files` only match .js/.mjs, so every entry needs the same file set.
|
|
const files = ['**/*.js', '**/*.mjs', '**/*.cjs', '**/*.ts', '**/*.tsx'];
|
|
|
|
// eslint-config-airbnb 19 is legacy-only: `extends` are paths to rule modules and flat config
|
|
// rejects `extends`/`env`/`parserOptions`, so take their rules and set the env here instead.
|
|
const airbnbRules = (config) =>
|
|
(config.extends || []).flatMap((p) => airbnbRules(require(p))).concat(config);
|
|
|
|
// Plugins are registered once (redefining a plugin is an error) and fixed up so the legacy
|
|
// rules that call context.getFilename still work.
|
|
export default [
|
|
...fixupConfigRules([
|
|
{
|
|
files,
|
|
plugins: {
|
|
react: reactPlugin,
|
|
'react-hooks': reactHooksPlugin,
|
|
'@typescript-eslint': tsPlugin,
|
|
import: importPlugin,
|
|
'jsx-a11y': jsxAllyPlugin,
|
|
},
|
|
languageOptions: {
|
|
parser: tsParser,
|
|
ecmaVersion: 'latest',
|
|
sourceType: 'module',
|
|
globals: { ...globals.browser, ...globals.es2021, JSX: 'readonly' },
|
|
},
|
|
},
|
|
]),
|
|
...[
|
|
js.configs.recommended,
|
|
reactPlugin.configs.flat.recommended,
|
|
reactHooksPlugin.configs.flat.recommended,
|
|
tsPlugin.configs['flat/eslint-recommended'],
|
|
tsPlugin.configs['flat/recommended'],
|
|
...airbnbRules(airbnb),
|
|
prettier,
|
|
{
|
|
rules: {
|
|
'linebreak-style': 0,
|
|
'no-underscore-dangle': 0,
|
|
'no-shadow': 'off',
|
|
'no-console': 'off',
|
|
|
|
// The build uses the automatic JSX runtime, so this rule asks for imports the code never needs.
|
|
'react/react-in-jsx-scope': 'off',
|
|
|
|
'import/prefer-default-export': 'off',
|
|
'import/extensions': 'off',
|
|
'import/no-unresolved': 'off',
|
|
'import/no-extraneous-dependencies': [
|
|
'error',
|
|
{
|
|
devDependencies: true,
|
|
},
|
|
],
|
|
|
|
'react/no-unstable-nested-components': ['error', { allowAsProps: true }],
|
|
'react/jsx-filename-extension': [
|
|
'error',
|
|
{
|
|
extensions: ['.tsx', '.jsx'],
|
|
},
|
|
],
|
|
|
|
'react/require-default-props': 'off',
|
|
'react/jsx-props-no-spreading': 'off',
|
|
'react-hooks/rules-of-hooks': 'error',
|
|
'react-hooks/exhaustive-deps': 'error',
|
|
|
|
// The build does not run React Compiler, so these rules report advice about a compiler
|
|
// that never runs. Keep the two rules above, which catch real bugs.
|
|
'react-hooks/set-state-in-effect': 'off',
|
|
'react-hooks/set-state-in-render': 'off',
|
|
'react-hooks/refs': 'off',
|
|
'react-hooks/immutability': 'off',
|
|
'react-hooks/incompatible-library': 'off',
|
|
'react-hooks/preserve-manual-memoization': 'off',
|
|
'react-hooks/purity': 'off',
|
|
'react-hooks/use-memo': 'off',
|
|
|
|
// Genuine shift and mask work in discordCollectibles.ts and cryptE2ERoomKeys.js.
|
|
'no-bitwise': 'off',
|
|
|
|
'@typescript-eslint/no-unused-vars': 'error',
|
|
'@typescript-eslint/no-shadow': 'error',
|
|
},
|
|
},
|
|
].flatMap((config) =>
|
|
(Array.isArray(config) ? config : [config]).map((config) => ({
|
|
files,
|
|
rules: config.rules || {},
|
|
...(config.settings ? { settings: config.settings } : {}),
|
|
})),
|
|
),
|
|
// Type-only references (React.DragEvent, PermissionState) are not runtime globals, so no-undef
|
|
// has to be off for the TS files too, not just *.ts. The base no-unused-vars also double-fires on
|
|
// type-signature params and enum members, which @typescript-eslint/no-unused-vars handles instead.
|
|
{
|
|
files: ['**/*.ts', '**/*.tsx'],
|
|
rules: { 'no-undef': 'off', 'no-unused-vars': 'off' },
|
|
},
|
|
];
|