Files
cinny/eslint.config.js
T

99 lines
3.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',
'@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 } : {}),
})),
),
{ files: ['*.ts'], rules: { 'no-undef': 'off' } },
];