This commit is contained in:
Alex
2023-10-03 19:00:25 -04:00
parent 01f291af94
commit 8a07010f29
15 changed files with 741 additions and 716 deletions

View File

@ -1,5 +1,9 @@
import type { ESLintConfig } from 'eslint-define-config';
import './redirect';
import type { ESLintConfig } from 'eslint-define-config';
import { typescriptRules } from './presets/typescript';
import { unicornRules } from './presets/unicorn';
import { eslintRules } from './presets/eslint';
import { reactRules } from './presets/react';
// @ts-expect-error
const { name } = (0, require)('./package.json');
@ -7,9 +11,9 @@ const unique = <T>(arr: T[]): T[] => [...new Set(arr)];
const ensureArray = <T>(value?: T | T[]): T[] =>
value == null ? [] : Array.isArray(value) ? value : [value];
const error = 'error';
const warn = 'warn';
const off = 'off';
export const error = 'error';
export const warn = 'warn';
export const off = 'off';
declare module 'eslint-define-config/src/rules/react/no-unknown-property.d.ts' {
export interface NoUnknownPropertyOption {
@ -27,6 +31,7 @@ export function extendConfig({
}: ESLintConfig = {}): ESLintConfig {
const hasReact = plugins?.includes('react');
const hasReactRefresh = plugins?.includes('react-refresh');
const hasUnicorn = plugins?.includes('unicorn');
const hasNext = ensureArray(_extends).some(name => name.includes(':@next/next'));
const result: ESLintConfig = {
@ -75,102 +80,21 @@ export function extendConfig({
...(overrides ?? []),
],
rules: {
'no-duplicate-imports': error,
'no-restricted-imports': [
error,
{
paths: [
{
name: 'crypto',
importNames: ['webcrypto'],
message: 'Use global `crypto` instead',
},
],
},
],
'no-restricted-globals': [error, 'event', 'name', 'length'],
'@typescript-eslint/ban-ts-comment': [
error,
{
'ts-expect-error': 'allow-with-description',
'ts-check': false,
'ts-ignore': 'allow-with-description',
'ts-nocheck': 'allow-with-description',
},
],
'@typescript-eslint/consistent-type-imports': [
error,
{ disallowTypeAnnotations: false, fixStyle: 'inline-type-imports' },
],
'@typescript-eslint/ban-types': [error, { extendDefaults: true }],
'@typescript-eslint/no-empty-interface': [error, { allowSingleExtends: true }],
'@typescript-eslint/no-explicit-any': off,
'@typescript-eslint/no-extraneous-class': error,
'@typescript-eslint/no-misused-promises': [error, { checksVoidReturn: false }],
'@typescript-eslint/no-namespace': off,
'@typescript-eslint/no-unnecessary-type-assertion': error,
'@typescript-eslint/no-unsafe-argument': off,
'@typescript-eslint/no-unsafe-assignment': off,
'@typescript-eslint/no-unsafe-call': off,
'@typescript-eslint/no-unsafe-member-access': off,
'@typescript-eslint/no-unsafe-return': off,
'@typescript-eslint/no-unused-vars': [
error,
{ ignoreRestSiblings: true, varsIgnorePattern: '^_' },
],
'@typescript-eslint/no-use-before-define': off,
'@typescript-eslint/no-var-requires': off,
'@typescript-eslint/unbound-method': off,
'@typescript-eslint/triple-slash-reference': off,
'arrow-body-style': [error, 'as-needed'],
'class-methods-use-this': off,
complexity: [warn, { max: 100 }],
curly: [error, 'multi-line', 'consistent'],
eqeqeq: [error, 'smart'],
'no-async-promise-executor': off,
'no-case-declarations': off,
'no-console': warn,
'no-constant-condition': [error, { checkLoops: false }],
'no-debugger': warn,
'no-empty': [error, { allowEmptyCatch: true }],
'no-inner-declarations': off,
'no-lonely-if': error,
'no-template-curly-in-string': error,
'no-var': error,
...eslintRules,
...typescriptRules,
'import/export': off,
'import/order': [error, { groups: ['builtin', 'external'] }],
'object-shorthand': [error, 'always', { ignoreConstructors: true }],
'one-var': [error, { var: 'never', let: 'never' }],
'prefer-arrow-callback': error,
'prefer-const': [error, { destructuring: 'all' }],
'prefer-destructuring': [
warn,
{ AssignmentExpression: { array: false, object: false } },
],
'prefer-object-spread': error,
'prefer-rest-params': warn,
'prefer-spread': warn,
'quote-props': [error, 'as-needed'],
'spaced-comment': [error, 'always', { markers: ['/', '#', '@'] }],
'sort-imports': [warn, { ignoreDeclarationSort: true }],
yoda: [error, 'never', { exceptRange: true }],
...(hasReact
? {
'react/display-name': off,
'react/no-children-prop': error,
'react/prop-types': off,
'react/react-in-jsx-scope': off,
'react/no-unknown-property': [
error,
{ extends: hasNext ? ['emotion', 'next'] : ['emotion'] },
],
}
: {}),
...(hasReactRefresh
? {
'react-refresh/only-export-components': [warn, { allowConstantExport: true }],
}
: {}),
...(hasReact && {
...reactRules,
'react/no-unknown-property': [
error,
{ extends: hasNext ? ['emotion', 'next'] : ['emotion'] },
],
}),
...(hasReactRefresh && {
'react-refresh/only-export-components': [warn, { allowConstantExport: true }],
}),
...(hasUnicorn && unicornRules),
...rules,
},
...rest,