2023-03-04 22:23:51 +08:00
|
|
|
const fs = require('node:fs')
|
|
|
|
const { join } = require('node:path')
|
2021-04-20 07:03:18 +08:00
|
|
|
const basic = require('@antfu/eslint-config-basic')
|
|
|
|
|
2022-12-13 01:01:40 +08:00
|
|
|
const tsconfig = process.env.ESLINT_TSCONFIG || 'tsconfig.eslint.json'
|
|
|
|
|
2019-07-18 04:11:55 +08:00
|
|
|
module.exports = {
|
|
|
|
extends: [
|
2021-04-20 05:45:40 +08:00
|
|
|
'@antfu/eslint-config-basic',
|
2022-03-31 22:19:07 +08:00
|
|
|
'plugin:import/typescript',
|
2021-04-20 07:03:18 +08:00
|
|
|
'plugin:@typescript-eslint/recommended',
|
2019-07-18 04:11:55 +08:00
|
|
|
],
|
2022-03-31 22:19:07 +08:00
|
|
|
settings: {
|
|
|
|
'import/resolver': {
|
|
|
|
node: { extensions: ['.js', '.jsx', '.mjs', '.ts', '.tsx', '.d.ts'] },
|
|
|
|
},
|
|
|
|
},
|
2022-11-29 20:02:35 +08:00
|
|
|
overrides: basic.overrides.concat(
|
2022-12-13 01:01:40 +08:00
|
|
|
!fs.existsSync(join(process.cwd(), tsconfig))
|
2022-11-29 20:02:35 +08:00
|
|
|
? []
|
|
|
|
: [{
|
|
|
|
parserOptions: {
|
|
|
|
tsconfigRootDir: process.cwd(),
|
2022-12-13 01:01:40 +08:00
|
|
|
project: [tsconfig],
|
2022-11-29 20:02:35 +08:00
|
|
|
},
|
|
|
|
parser: '@typescript-eslint/parser',
|
|
|
|
excludedFiles: ['**/*.md/*.*'],
|
2022-11-30 21:16:09 +08:00
|
|
|
files: ['*.ts', '*.tsx', '*.mts', '*.cts'],
|
2022-12-13 01:01:22 +08:00
|
|
|
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/recommended-requiring-type-checking.ts
|
2022-11-29 20:02:35 +08:00
|
|
|
rules: {
|
|
|
|
'no-throw-literal': 'off',
|
|
|
|
'@typescript-eslint/no-throw-literal': 'error',
|
|
|
|
'no-implied-eval': 'off',
|
|
|
|
'@typescript-eslint/no-implied-eval': 'error',
|
|
|
|
'dot-notation': 'off',
|
|
|
|
'@typescript-eslint/dot-notation': ['error', { allowKeywords: true }],
|
|
|
|
'@typescript-eslint/no-floating-promises': 'error',
|
|
|
|
'@typescript-eslint/no-misused-promises': 'error',
|
2022-12-13 01:01:22 +08:00
|
|
|
'@typescript-eslint/await-thenable': 'error',
|
|
|
|
'@typescript-eslint/no-for-in-array': 'error',
|
|
|
|
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
|
|
|
|
'@typescript-eslint/no-unsafe-argument': 'error',
|
|
|
|
'@typescript-eslint/no-unsafe-assignment': 'error',
|
|
|
|
'@typescript-eslint/no-unsafe-call': 'error',
|
|
|
|
'@typescript-eslint/no-unsafe-member-access': 'error',
|
|
|
|
'@typescript-eslint/no-unsafe-return': 'error',
|
|
|
|
'require-await': 'off',
|
|
|
|
'@typescript-eslint/require-await': 'error',
|
|
|
|
'@typescript-eslint/restrict-plus-operands': 'error',
|
|
|
|
'@typescript-eslint/restrict-template-expressions': 'error',
|
|
|
|
'@typescript-eslint/unbound-method': 'error',
|
2022-11-29 20:02:35 +08:00
|
|
|
},
|
2022-12-15 17:04:50 +08:00
|
|
|
}, {
|
|
|
|
// https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/unbound-method.md
|
|
|
|
files: ['**/__tests__/**/*.ts', '**/*.spec.ts', '**/*.test.ts'],
|
|
|
|
plugins: ['jest'],
|
|
|
|
rules: {
|
|
|
|
// you should turn the original rule off *only* for test files
|
|
|
|
'@typescript-eslint/unbound-method': 'off',
|
|
|
|
'jest/unbound-method': 'error',
|
|
|
|
},
|
2022-11-29 20:02:35 +08:00
|
|
|
}],
|
|
|
|
),
|
2019-07-18 04:11:55 +08:00
|
|
|
rules: {
|
2021-09-13 11:31:02 +08:00
|
|
|
'import/named': 'off',
|
|
|
|
|
2019-07-18 04:11:55 +08:00
|
|
|
// TS
|
2022-01-07 03:23:12 +08:00
|
|
|
'@typescript-eslint/ban-ts-comment': ['error', { 'ts-ignore': 'allow-with-description' }],
|
2019-07-18 04:11:55 +08:00
|
|
|
'@typescript-eslint/member-delimiter-style': ['error', { multiline: { delimiter: 'none' } }],
|
|
|
|
'@typescript-eslint/type-annotation-spacing': ['error', {}],
|
2021-12-12 08:17:49 +08:00
|
|
|
'@typescript-eslint/consistent-type-imports': ['error', { prefer: 'type-imports', disallowTypeAnnotations: false }],
|
2022-01-07 03:23:12 +08:00
|
|
|
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
|
|
|
|
'@typescript-eslint/prefer-ts-expect-error': 'error',
|
2023-04-10 23:39:06 +08:00
|
|
|
'@typescript-eslint/no-require-imports': 'error',
|
2021-12-12 08:17:49 +08:00
|
|
|
// Override JS
|
|
|
|
'no-useless-constructor': 'off',
|
2021-06-24 20:57:50 +08:00
|
|
|
'indent': 'off',
|
2022-04-17 12:49:48 +08:00
|
|
|
'@typescript-eslint/indent': ['error', 2, {
|
2022-04-17 13:17:35 +08:00
|
|
|
SwitchCase: 1,
|
|
|
|
VariableDeclarator: 1,
|
|
|
|
outerIIFEBody: 1,
|
|
|
|
MemberExpression: 1,
|
|
|
|
FunctionDeclaration: { parameters: 1, body: 1 },
|
|
|
|
FunctionExpression: { parameters: 1, body: 1 },
|
|
|
|
CallExpression: { arguments: 1 },
|
|
|
|
ArrayExpression: 1,
|
|
|
|
ObjectExpression: 1,
|
|
|
|
ImportDeclaration: 1,
|
|
|
|
flatTernaryExpressions: false,
|
|
|
|
ignoreComments: false,
|
2022-04-17 12:49:48 +08:00
|
|
|
ignoredNodes: [
|
2022-04-17 13:17:35 +08:00
|
|
|
'TemplateLiteral *',
|
|
|
|
'JSXElement',
|
|
|
|
'JSXElement > *',
|
2022-04-17 12:49:48 +08:00
|
|
|
'JSXAttribute',
|
2022-04-17 13:17:35 +08:00
|
|
|
'JSXIdentifier',
|
|
|
|
'JSXNamespacedName',
|
|
|
|
'JSXMemberExpression',
|
|
|
|
'JSXSpreadAttribute',
|
|
|
|
'JSXExpressionContainer',
|
|
|
|
'JSXOpeningElement',
|
|
|
|
'JSXClosingElement',
|
|
|
|
'JSXFragment',
|
|
|
|
'JSXOpeningFragment',
|
|
|
|
'JSXClosingFragment',
|
|
|
|
'JSXText',
|
|
|
|
'JSXEmptyExpression',
|
|
|
|
'JSXSpreadChild',
|
2022-04-17 12:49:48 +08:00
|
|
|
'TSTypeParameterInstantiation',
|
2022-09-19 10:25:42 +08:00
|
|
|
'FunctionExpression > .params[decorators.length > 0]',
|
|
|
|
'FunctionExpression > .params > :matches(Decorator, :not(:first-child))',
|
|
|
|
'ClassBody.body > PropertyDefinition[decorators.length > 0] > .key',
|
2022-04-17 12:49:48 +08:00
|
|
|
],
|
2022-04-17 13:17:35 +08:00
|
|
|
offsetTernaryExpressions: true,
|
2022-04-17 12:49:48 +08:00
|
|
|
}],
|
2023-04-18 19:42:48 +08:00
|
|
|
'no-invalid-this': 'off',
|
|
|
|
'@typescript-eslint/no-invalid-this': 'error',
|
2020-10-21 14:38:36 +08:00
|
|
|
'no-redeclare': 'off',
|
|
|
|
'@typescript-eslint/no-redeclare': 'error',
|
2021-12-12 08:17:49 +08:00
|
|
|
'no-use-before-define': 'off',
|
2021-12-12 08:20:58 +08:00
|
|
|
'@typescript-eslint/no-use-before-define': ['error', { functions: false, classes: false, variables: true }],
|
2022-01-07 03:23:12 +08:00
|
|
|
'brace-style': 'off',
|
|
|
|
'@typescript-eslint/brace-style': ['error', 'stroustrup', { allowSingleLine: true }],
|
|
|
|
'comma-dangle': 'off',
|
|
|
|
'@typescript-eslint/comma-dangle': ['error', 'always-multiline'],
|
|
|
|
'object-curly-spacing': 'off',
|
|
|
|
'@typescript-eslint/object-curly-spacing': ['error', 'always'],
|
2022-05-01 08:53:21 +08:00
|
|
|
'semi': 'off',
|
|
|
|
'@typescript-eslint/semi': ['error', 'never'],
|
|
|
|
'quotes': 'off',
|
|
|
|
'@typescript-eslint/quotes': ['error', 'single'],
|
|
|
|
'space-before-blocks': 'off',
|
|
|
|
'@typescript-eslint/space-before-blocks': ['error', 'always'],
|
|
|
|
'space-before-function-paren': 'off',
|
|
|
|
'@typescript-eslint/space-before-function-paren': [
|
|
|
|
'error',
|
|
|
|
{
|
|
|
|
anonymous: 'always',
|
|
|
|
named: 'never',
|
|
|
|
asyncArrow: 'always',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
'space-infix-ops': 'off',
|
|
|
|
'@typescript-eslint/space-infix-ops': 'error',
|
|
|
|
'keyword-spacing': 'off',
|
|
|
|
'@typescript-eslint/keyword-spacing': ['error', { before: true, after: true }],
|
|
|
|
'comma-spacing': 'off',
|
|
|
|
'@typescript-eslint/comma-spacing': ['error', { before: false, after: true }],
|
|
|
|
'no-extra-parens': 'off',
|
|
|
|
'@typescript-eslint/no-extra-parens': ['error', 'functions'],
|
|
|
|
'no-dupe-class-members': 'off',
|
|
|
|
'@typescript-eslint/no-dupe-class-members': 'error',
|
|
|
|
'no-loss-of-precision': 'off',
|
|
|
|
'@typescript-eslint/no-loss-of-precision': 'error',
|
|
|
|
'lines-between-class-members': 'off',
|
|
|
|
'@typescript-eslint/lines-between-class-members': ['error', 'always', { exceptAfterSingleLine: true }],
|
2022-09-19 10:28:57 +08:00
|
|
|
|
2022-11-01 03:34:15 +08:00
|
|
|
// antfu
|
|
|
|
'antfu/generic-spacing': 'error',
|
2023-05-19 16:29:54 +08:00
|
|
|
'antfu/no-cjs-exports': 'error',
|
|
|
|
'antfu/no-ts-export-equal': 'error',
|
2023-06-28 20:05:23 +08:00
|
|
|
'antfu/no-const-enum': 'error',
|
2022-11-01 03:34:15 +08:00
|
|
|
|
2020-08-12 19:24:32 +08:00
|
|
|
// off
|
2022-06-03 22:08:48 +08:00
|
|
|
'@typescript-eslint/consistent-indexed-object-style': 'off',
|
2022-05-03 00:10:59 +08:00
|
|
|
'@typescript-eslint/naming-convention': 'off',
|
2019-07-18 04:11:55 +08:00
|
|
|
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
|
|
'@typescript-eslint/explicit-member-accessibility': 'off',
|
|
|
|
'@typescript-eslint/no-explicit-any': 'off',
|
2022-05-03 00:10:59 +08:00
|
|
|
'@typescript-eslint/parameter-properties': 'off',
|
2019-07-19 14:41:36 +08:00
|
|
|
'@typescript-eslint/no-empty-interface': 'off',
|
2019-08-23 00:19:43 +08:00
|
|
|
'@typescript-eslint/ban-ts-ignore': 'off',
|
2020-06-04 12:49:19 +08:00
|
|
|
'@typescript-eslint/no-empty-function': 'off',
|
|
|
|
'@typescript-eslint/no-non-null-assertion': 'off',
|
|
|
|
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
2022-05-13 23:15:22 +08:00
|
|
|
'@typescript-eslint/triple-slash-reference': 'off',
|
2023-01-29 22:15:30 +08:00
|
|
|
// handled by unused-imports/no-unused-imports
|
|
|
|
'@typescript-eslint/no-unused-vars': 'off',
|
2020-08-12 20:08:06 +08:00
|
|
|
},
|
2019-07-18 04:11:55 +08:00
|
|
|
}
|