feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
200
frontend/config/eslint-config/rules/common-standard.js
Normal file
200
frontend/config/eslint-config/rules/common-standard.js
Normal file
@@ -0,0 +1,200 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
const JSON5 = require('json5');
|
||||
|
||||
const noRestrictedSyntaxRule = [
|
||||
'error',
|
||||
{
|
||||
selector: 'LabeledStatement',
|
||||
message:
|
||||
'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
|
||||
},
|
||||
{
|
||||
selector: 'WithStatement',
|
||||
message:
|
||||
'`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
|
||||
},
|
||||
];
|
||||
|
||||
const readBlockList = () =>
|
||||
JSON5.parse(
|
||||
fs.readFileSync(
|
||||
// fixme @fanwenjie.fe
|
||||
path.resolve(__dirname, '../../../disallowed_3rd_libraries.json'),
|
||||
'utf-8',
|
||||
),
|
||||
);
|
||||
|
||||
/** @type {(import('eslint').Linter.Config)[]} */
|
||||
module.exports = [
|
||||
// NOTE: 不能和下一项配置合并
|
||||
{
|
||||
ignores: [
|
||||
'**/*.d.ts',
|
||||
'**/.storybook/**',
|
||||
'**/storybook-static/**',
|
||||
'**/coverage/**',
|
||||
'**/node_modules/**',
|
||||
'**/build/**',
|
||||
'**/__dist__/**',
|
||||
'**/dist/**',
|
||||
'**/es/**',
|
||||
'**/lib/**',
|
||||
'**/.codebase/**',
|
||||
'**/.changeset/**',
|
||||
'**/config/**',
|
||||
'**/common/scripts/**',
|
||||
'**/output/**',
|
||||
'**/output_resource/**',
|
||||
'**/__tests__/fixtures/**',
|
||||
'**/__tests__/outputs/**',
|
||||
'error-log-str.js',
|
||||
'*.bundle.js',
|
||||
'*.min.js',
|
||||
'*.js.map',
|
||||
'**/*.log',
|
||||
'**/tsconfig.tsbuildinfo',
|
||||
'**/.jscpd',
|
||||
],
|
||||
},
|
||||
{
|
||||
plugins: {
|
||||
'@coze-arch': require('@coze-arch/eslint-plugin'),
|
||||
'@coze-arch/zustand': require('@coze-arch/eslint-plugin/zustand'),
|
||||
},
|
||||
},
|
||||
...require('@coze-arch/eslint-plugin').configs.recommended,
|
||||
require('@coze-arch/eslint-plugin/zustand').configs.recommended,
|
||||
{
|
||||
files: ['**/*.?(m|c)?(j|t)s?(x)'], // 排除规则对package.json生效
|
||||
plugins: {
|
||||
prettier: require('eslint-plugin-prettier'),
|
||||
'@babel': require('@babel/eslint-plugin'),
|
||||
import: require('eslint-plugin-import'),
|
||||
unicorn: require('eslint-plugin-unicorn'),
|
||||
'@typescript-eslint': require('@typescript-eslint/eslint-plugin'),
|
||||
'@stylistic/ts': require('@stylistic/eslint-plugin-ts'),
|
||||
'eslint-comments': require('eslint-plugin-eslint-comments'),
|
||||
},
|
||||
rules: {
|
||||
'@coze-arch/package-disallow-deps': ['error', readBlockList()],
|
||||
'no-restricted-syntax': noRestrictedSyntaxRule,
|
||||
'prettier/prettier': [
|
||||
'warn',
|
||||
require('../.prettierrc'),
|
||||
{ usePrettierrc: false },
|
||||
],
|
||||
'no-empty': 'error',
|
||||
'import/no-duplicates': 'error',
|
||||
'unicorn/no-static-only-class': 'error',
|
||||
curly: 'error',
|
||||
'no-mixed-spaces-and-tabs': 'error',
|
||||
'max-statements-per-line': 'error',
|
||||
'rest-spread-spacing': 'error',
|
||||
'max-len': [
|
||||
'warn',
|
||||
{
|
||||
code: 120,
|
||||
tabWidth: 2,
|
||||
ignoreUrls: true,
|
||||
ignoreStrings: true,
|
||||
},
|
||||
],
|
||||
'no-unexpected-multiline': 'error',
|
||||
'no-irregular-whitespace': [
|
||||
'error',
|
||||
{
|
||||
skipStrings: true,
|
||||
skipComments: true,
|
||||
},
|
||||
],
|
||||
'no-var': 'error',
|
||||
'prefer-const': 'error',
|
||||
'no-inner-declarations': ['error', 'both'],
|
||||
'no-self-assign': 'error',
|
||||
'prefer-destructuring': [
|
||||
'warn',
|
||||
{
|
||||
object: true,
|
||||
array: false,
|
||||
},
|
||||
],
|
||||
'no-sparse-arrays': 'error',
|
||||
'no-new-object': 'error',
|
||||
'object-shorthand': 'error',
|
||||
'no-empty-pattern': 'error',
|
||||
'no-unsafe-optional-chaining': 'error',
|
||||
'no-class-assign': 'error',
|
||||
'arrow-body-style': 'error',
|
||||
'no-async-promise-executor': 'error',
|
||||
'prefer-promise-reject-errors': 'error',
|
||||
// TODO: complexity is stricter after we updated to eslint 9.
|
||||
complexity: ['warn', 15],
|
||||
'max-params': [
|
||||
'error',
|
||||
{
|
||||
max: 3,
|
||||
},
|
||||
],
|
||||
'no-extra-bind': 'error',
|
||||
'no-prototype-builtins': 'error',
|
||||
'new-parens': 'error',
|
||||
'prefer-template': 'warn',
|
||||
'no-multi-str': 'error',
|
||||
'use-isnan': 'error',
|
||||
'no-floating-decimal': 'error',
|
||||
'guard-for-in': 'warn',
|
||||
'for-direction': 'error',
|
||||
'no-unmodified-loop-condition': 'error',
|
||||
'no-unsafe-finally': 'error',
|
||||
'no-cond-assign': ['error', 'always'],
|
||||
'no-constant-condition': [
|
||||
'error',
|
||||
{
|
||||
checkLoops: false,
|
||||
},
|
||||
],
|
||||
'no-dupe-else-if': 'error',
|
||||
'no-extra-boolean-cast': [
|
||||
'error',
|
||||
{
|
||||
enforceForLogicalOperands: true,
|
||||
},
|
||||
],
|
||||
'no-useless-catch': 'error',
|
||||
'no-ex-assign': 'error',
|
||||
'no-fallthrough': 'error',
|
||||
'default-case': 'error',
|
||||
'default-case-last': 'error',
|
||||
'no-duplicate-case': 'error',
|
||||
'no-case-declarations': 'error',
|
||||
eqeqeq: 'error',
|
||||
'no-compare-neg-zero': 'error',
|
||||
'no-invalid-regexp': 'error',
|
||||
'no-control-regex': 'error',
|
||||
'no-empty-character-class': 'error',
|
||||
'no-with': 'error',
|
||||
'no-eval': 'error',
|
||||
'no-new-wrappers': 'error',
|
||||
'no-global-assign': 'error',
|
||||
'no-debugger': 'error',
|
||||
'no-caller': 'error',
|
||||
'prefer-rest-params': 'error',
|
||||
'no-implicit-coercion': [
|
||||
'error',
|
||||
{
|
||||
allow: ['!!'],
|
||||
},
|
||||
],
|
||||
'array-bracket-newline': ['error', 'consistent'],
|
||||
'eslint-comments/require-description': 'warn',
|
||||
'eslint-comments/no-unused-disable': 'error',
|
||||
'max-lines': [
|
||||
'error',
|
||||
{ max: 500, skipComments: true, skipBlankLines: true },
|
||||
],
|
||||
'no-unused-labels': 'error',
|
||||
},
|
||||
},
|
||||
];
|
||||
80
frontend/config/eslint-config/rules/import.js
Normal file
80
frontend/config/eslint-config/rules/import.js
Normal file
@@ -0,0 +1,80 @@
|
||||
const importPlugin = require('eslint-plugin-import');
|
||||
|
||||
/** @type {(import('eslint').Linter.Config)[]} */
|
||||
module.exports = [
|
||||
{
|
||||
files: ['**/*.?(m|c)?(j|t)s?(x)'],
|
||||
settings: {
|
||||
// TODO: 全局保留一份配置
|
||||
'import/resolver': {
|
||||
node: {
|
||||
moduleDirectory: ['node_modules', 'src'],
|
||||
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
||||
},
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
'import/no-cycle': ['error', { ignoreExternal: true }],
|
||||
'import/prefer-default-export': 'off',
|
||||
'import/no-extraneous-dependencies': [
|
||||
'error',
|
||||
{
|
||||
devDependencies: true,
|
||||
},
|
||||
],
|
||||
'import/no-relative-packages': 'error',
|
||||
'import/extensions': 'off',
|
||||
'import/order': [
|
||||
'warn',
|
||||
{
|
||||
groups: [
|
||||
'builtin',
|
||||
'external',
|
||||
['internal', 'parent', 'sibling', 'index'],
|
||||
'unknown',
|
||||
],
|
||||
pathGroups: [
|
||||
{
|
||||
pattern: 'react*',
|
||||
group: 'builtin',
|
||||
position: 'before',
|
||||
},
|
||||
{
|
||||
pattern: '@/**',
|
||||
group: 'internal',
|
||||
position: 'before',
|
||||
},
|
||||
{
|
||||
pattern: './*.+(css|sass|less|scss|pcss|styl)',
|
||||
patternOptions: { dot: true, nocomment: true },
|
||||
group: 'unknown',
|
||||
position: 'after',
|
||||
},
|
||||
],
|
||||
alphabetize: {
|
||||
order:
|
||||
'desc' /* sort in ascending order. Options: ['ignore', 'asc', 'desc'] */,
|
||||
caseInsensitive: true /* ignore case. Options: [true, false] */,
|
||||
},
|
||||
pathGroupsExcludedImportTypes: ['builtin'],
|
||||
'newlines-between': 'always',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ['**/*.?(m|c)ts?(x)'],
|
||||
...importPlugin.configs.typescript,
|
||||
settings: {
|
||||
'import/resolver': {
|
||||
typescript: true,
|
||||
node: true,
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
// TODO: 目前由于 edenx 会动态生成一些插件模块,因此启动会报错
|
||||
// 后续需要修复问题,启动下述规则
|
||||
// "import/no-unresolved": "error"
|
||||
},
|
||||
},
|
||||
];
|
||||
163
frontend/config/eslint-config/rules/js-standard.js
Normal file
163
frontend/config/eslint-config/rules/js-standard.js
Normal file
@@ -0,0 +1,163 @@
|
||||
const babelOptions = {
|
||||
plugins: [
|
||||
[
|
||||
require.resolve('@babel/plugin-proposal-decorators'),
|
||||
{
|
||||
legacy: true,
|
||||
},
|
||||
],
|
||||
[
|
||||
require.resolve('@babel/plugin-proposal-class-properties'),
|
||||
{
|
||||
loose: true,
|
||||
},
|
||||
],
|
||||
require.resolve('@babel/plugin-proposal-object-rest-spread'),
|
||||
require.resolve('@babel/plugin-proposal-optional-catch-binding'),
|
||||
require.resolve('@babel/plugin-proposal-async-generator-functions'),
|
||||
require.resolve('@babel/plugin-proposal-export-namespace-from'),
|
||||
require.resolve('@babel/plugin-proposal-export-default-from'),
|
||||
require.resolve('@babel/plugin-proposal-nullish-coalescing-operator'),
|
||||
require.resolve('@babel/plugin-proposal-optional-chaining'),
|
||||
[
|
||||
require.resolve('@babel/plugin-proposal-pipeline-operator'),
|
||||
{
|
||||
proposal: 'minimal',
|
||||
},
|
||||
],
|
||||
require.resolve('@babel/plugin-proposal-do-expressions'),
|
||||
require.resolve('@babel/plugin-proposal-function-bind'),
|
||||
require.resolve('@babel/plugin-syntax-dynamic-import'),
|
||||
require.resolve('@babel/plugin-syntax-jsx'),
|
||||
],
|
||||
};
|
||||
|
||||
/** @type {(import('eslint').Linter.Config)[]} */
|
||||
module.exports = [
|
||||
{
|
||||
files: ['**/*.?(m|c)js?(x)'],
|
||||
rules: {
|
||||
'no-import-assign': 'error',
|
||||
'no-extra-semi': 'error',
|
||||
'no-undef': 'error',
|
||||
'no-unused-vars': [
|
||||
'error',
|
||||
{
|
||||
argsIgnorePattern: '^_',
|
||||
},
|
||||
],
|
||||
'comma-dangle': ['error', 'always-multiline'],
|
||||
'no-array-constructor': 'error',
|
||||
'dot-notation': 'error',
|
||||
'constructor-super': 'error',
|
||||
'no-this-before-super': 'error',
|
||||
'no-useless-constructor': 'error',
|
||||
'getter-return': [
|
||||
'error',
|
||||
{
|
||||
allowImplicit: true,
|
||||
},
|
||||
],
|
||||
'no-setter-return': 'error',
|
||||
'no-dupe-class-members': 'error',
|
||||
'default-param-last': 'error',
|
||||
'no-func-assign': 'error',
|
||||
'no-unsafe-negation': 'error',
|
||||
'valid-typeof': 'error',
|
||||
'no-empty-function': 'error',
|
||||
quotes: [
|
||||
'error',
|
||||
'single',
|
||||
{
|
||||
avoidEscape: true,
|
||||
},
|
||||
],
|
||||
'no-loss-of-precision': 'error',
|
||||
'no-magic-numbers': [
|
||||
'warn',
|
||||
{
|
||||
ignoreArrayIndexes: true,
|
||||
ignoreDefaultValues: true,
|
||||
enforceConst: true,
|
||||
ignore: [0, 1, -1],
|
||||
ignoreClassFieldInitialValues: true,
|
||||
},
|
||||
],
|
||||
'no-unreachable': 'error',
|
||||
'no-throw-literal': 'error',
|
||||
'no-implied-eval': 'error',
|
||||
'no-new-symbol': 'error',
|
||||
'no-obj-calls': 'error',
|
||||
camelcase: [
|
||||
'error',
|
||||
{
|
||||
properties: 'never',
|
||||
allow: ['^UNSAFE_'],
|
||||
ignoreDestructuring: true,
|
||||
},
|
||||
],
|
||||
'unicorn/filename-case': [
|
||||
'error',
|
||||
{
|
||||
cases: {
|
||||
kebabCase: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
'max-lines-per-function': [
|
||||
'error',
|
||||
{
|
||||
max: 300,
|
||||
IIFEs: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
languageOptions: {
|
||||
parser: require('@babel/eslint-parser'),
|
||||
parserOptions: {
|
||||
ecmaVersion: 11,
|
||||
sourceType: 'module',
|
||||
ecmaFeatures: {
|
||||
jsx: true,
|
||||
legacyDecorators: true,
|
||||
},
|
||||
requireConfigFile: false,
|
||||
babelOptions,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
// for jsx
|
||||
files: ['**/*.?(m|c)jsx'],
|
||||
rules: {
|
||||
'react/jsx-uses-react': 'error',
|
||||
'react/jsx-uses-vars': 'error',
|
||||
'unicorn/filename-case': [
|
||||
'warn',
|
||||
{
|
||||
cases: {
|
||||
kebabCase: true,
|
||||
snakeCase: true,
|
||||
pascalCase: true,
|
||||
},
|
||||
ignore: ['^(?!.*?\\.jsx$)(?!.*?\\.tsx$).+'],
|
||||
},
|
||||
],
|
||||
'max-lines-per-function': [
|
||||
'warn',
|
||||
{
|
||||
max: 300,
|
||||
IIFEs: true,
|
||||
},
|
||||
],
|
||||
'max-lines': [
|
||||
'error',
|
||||
{
|
||||
max: 500,
|
||||
skipComments: true,
|
||||
skipBlankLines: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
];
|
||||
53
frontend/config/eslint-config/rules/test-standard.js
Normal file
53
frontend/config/eslint-config/rules/test-standard.js
Normal file
@@ -0,0 +1,53 @@
|
||||
const globals = require('globals');
|
||||
|
||||
/** @type {(import('eslint').Linter.Config)[]} */
|
||||
module.exports = [
|
||||
{
|
||||
files: [
|
||||
'**/*.{test,spec}.?(m|c){js,ts}?(x)',
|
||||
'**/{tests,__tests__,__test__}/**/*.?(m|c){js,ts}?(x)',
|
||||
],
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...globals.jest,
|
||||
vi: 'readonly',
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
'max-lines': 'off',
|
||||
'max-lines-per-function': 'off',
|
||||
'no-magic-numbers': 'off',
|
||||
'no-restricted-syntax': 'off',
|
||||
'import/no-named-as-default-member': 'off',
|
||||
'@coze-arch/max-line-per-function': 'off',
|
||||
'@coze-arch/no-deep-relative-import': 'off',
|
||||
'@typescript-eslint/consistent-type-assertions': 'off',
|
||||
},
|
||||
},
|
||||
{
|
||||
files: [
|
||||
'**/*.{test,spec}.?(m|c)ts?(x)',
|
||||
'**/{tests,__tests__,__test__}/**/*.?(m|c)ts?(x)',
|
||||
],
|
||||
rules: {
|
||||
'@stylistic/ts/member-delimiter-style': [
|
||||
'warn',
|
||||
{
|
||||
multiline: {
|
||||
delimiter: 'semi',
|
||||
requireLast: true,
|
||||
},
|
||||
singleline: {
|
||||
delimiter: 'semi',
|
||||
requireLast: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
'@typescript-eslint/no-non-null-assertion': 'off',
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'@typescript-eslint/no-magic-numbers': 'off',
|
||||
'@typescript-eslint/no-empty-function': 'off',
|
||||
'@coze-arch/no-batch-import-or-export': 'off',
|
||||
},
|
||||
},
|
||||
];
|
||||
371
frontend/config/eslint-config/rules/ts-standard.js
Normal file
371
frontend/config/eslint-config/rules/ts-standard.js
Normal file
@@ -0,0 +1,371 @@
|
||||
/** @type {(import('eslint').Linter.Config)[]} */
|
||||
module.exports = [
|
||||
{
|
||||
files: ['**/*.?(m|c)ts?(x)'],
|
||||
rules: {
|
||||
'@typescript-eslint/no-var-requires': 'off',
|
||||
'@typescript-eslint/prefer-namespace-keyword': 'off',
|
||||
'@typescript-eslint/dot-notation': 'error',
|
||||
'@typescript-eslint/require-await': 'error',
|
||||
|
||||
'max-lines': [
|
||||
'error',
|
||||
{
|
||||
max: 500,
|
||||
skipComments: true,
|
||||
skipBlankLines: true,
|
||||
},
|
||||
],
|
||||
'@typescript-eslint/no-array-constructor': 'error',
|
||||
'@typescript-eslint/prefer-for-of': 'warn',
|
||||
'@typescript-eslint/prefer-literal-enum-member': 'error',
|
||||
'@typescript-eslint/no-duplicate-enum-values': 'error',
|
||||
'@typescript-eslint/adjacent-overload-signatures': 'error',
|
||||
'@typescript-eslint/unified-signatures': 'error',
|
||||
'@typescript-eslint/no-this-alias': 'error',
|
||||
'@typescript-eslint/method-signature-style': 'error',
|
||||
'@typescript-eslint/no-misused-new': 'error',
|
||||
'@typescript-eslint/consistent-type-assertions': [
|
||||
'error',
|
||||
{
|
||||
assertionStyle: 'as',
|
||||
objectLiteralTypeAssertions: 'never',
|
||||
},
|
||||
],
|
||||
'@typescript-eslint/no-non-null-assertion': 'error',
|
||||
'@typescript-eslint/no-extra-non-null-assertion': 'error',
|
||||
'@typescript-eslint/no-non-null-asserted-optional-chain': 'error',
|
||||
'@typescript-eslint/no-non-null-asserted-nullish-coalescing': 'error',
|
||||
'@typescript-eslint/ban-ts-comment': [
|
||||
'error',
|
||||
{
|
||||
'ts-expect-error': 'allow-with-description',
|
||||
},
|
||||
],
|
||||
'@typescript-eslint/prefer-ts-expect-error': 'error',
|
||||
'@typescript-eslint/no-inferrable-types': 'error',
|
||||
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||
'@typescript-eslint/prefer-as-const': 'error',
|
||||
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
|
||||
'@typescript-eslint/no-empty-interface': 'error',
|
||||
'@typescript-eslint/no-explicit-any': 'error',
|
||||
'@typescript-eslint/no-unnecessary-type-constraint': 'error',
|
||||
'@typescript-eslint/no-invalid-void-type': 'error',
|
||||
'@typescript-eslint/no-namespace': 'error',
|
||||
'@typescript-eslint/no-require-imports': 'error',
|
||||
'@typescript-eslint/consistent-type-imports': 'error',
|
||||
'@typescript-eslint/no-unused-vars': [
|
||||
'error',
|
||||
{
|
||||
vars: 'all',
|
||||
args: 'none', // function arguments should not force to match this rule.
|
||||
argsIgnorePattern: '^_', // 规范允许下划线
|
||||
ignoreRestSiblings: true, //使用rest语法(如 `var { foo, ...rest } = data`) 忽略foo。
|
||||
destructuredArrayIgnorePattern: '^_', //结构数组允许使用_
|
||||
caughtErrors: 'none',
|
||||
// "caughtErrorsIgnorePattern": "^e$"
|
||||
},
|
||||
],
|
||||
'@stylistic/ts/quotes': [
|
||||
'error',
|
||||
'single',
|
||||
{
|
||||
avoidEscape: true,
|
||||
},
|
||||
],
|
||||
'@typescript-eslint/no-magic-numbers': [
|
||||
'warn',
|
||||
{
|
||||
ignoreArrayIndexes: true,
|
||||
ignoreDefaultValues: true,
|
||||
ignoreEnums: true,
|
||||
ignoreNumericLiteralTypes: true,
|
||||
enforceConst: true,
|
||||
ignore: [-1, 0, 1],
|
||||
ignoreTypeIndexes: true,
|
||||
ignoreReadonlyClassProperties: true,
|
||||
ignoreClassFieldInitialValues: true,
|
||||
},
|
||||
],
|
||||
'@stylistic/ts/no-extra-semi': 'error',
|
||||
'@typescript-eslint/no-dupe-class-members': 'error',
|
||||
'@typescript-eslint/no-useless-constructor': 'error',
|
||||
'@typescript-eslint/default-param-last': 'error',
|
||||
'@typescript-eslint/no-loss-of-precision': 'error',
|
||||
'@stylistic/ts/comma-dangle': [
|
||||
'error',
|
||||
{
|
||||
arrays: 'always-multiline',
|
||||
objects: 'always-multiline',
|
||||
imports: 'always-multiline',
|
||||
exports: 'always-multiline',
|
||||
enums: 'always-multiline',
|
||||
generics: 'ignore',
|
||||
tuples: 'always-multiline',
|
||||
functions: 'always-multiline',
|
||||
},
|
||||
],
|
||||
'@typescript-eslint/no-empty-function': 'error',
|
||||
'@typescript-eslint/no-extraneous-class': 'error',
|
||||
'no-import-assign': 'off',
|
||||
'no-undef': 'off',
|
||||
'dot-notation': 'off',
|
||||
'constructor-super': 'off',
|
||||
'no-this-before-super': 'off',
|
||||
'getter-return': 'off',
|
||||
'no-setter-return': 'off',
|
||||
'no-func-assign': 'off',
|
||||
'no-unsafe-negation': 'off',
|
||||
'valid-typeof': 'off',
|
||||
'no-unreachable': 'off',
|
||||
'no-throw-literal': 'off',
|
||||
'no-implied-eval': 'off',
|
||||
'no-new-symbol': 'off',
|
||||
'no-obj-calls': 'off',
|
||||
camelcase: 'off',
|
||||
'no-const-assign': 'off',
|
||||
'no-dupe-args': 'off',
|
||||
'no-dupe-class-members': 'off',
|
||||
'no-dupe-keys': 'off',
|
||||
'no-redeclare': 'off',
|
||||
'no-array-constructor': 'off',
|
||||
'no-empty-function': 'off',
|
||||
'no-extra-semi': 'off',
|
||||
'no-loss-of-precision': 'off',
|
||||
'no-unused-vars': 'off',
|
||||
'default-param-last': 'off',
|
||||
'no-useless-constructor': 'off',
|
||||
quotes: 'off',
|
||||
'comma-dangle': 'off',
|
||||
indent: 'off',
|
||||
'no-magic-numbers': 'off',
|
||||
'@typescript-eslint/naming-convention': [
|
||||
'error',
|
||||
{
|
||||
selector: ['default', 'variableLike'],
|
||||
format: ['camelCase', 'UPPER_CASE'],
|
||||
},
|
||||
{
|
||||
selector: ['class', 'interface', 'typeLike'],
|
||||
format: ['PascalCase'],
|
||||
},
|
||||
{
|
||||
selector: ['variable'],
|
||||
format: ['UPPER_CASE', 'camelCase'],
|
||||
modifiers: ['global', 'exported'],
|
||||
},
|
||||
{
|
||||
selector: 'objectLiteralProperty',
|
||||
format: null,
|
||||
},
|
||||
{
|
||||
selector: 'enumMember',
|
||||
format: ['UPPER_CASE', 'PascalCase'],
|
||||
},
|
||||
{
|
||||
selector: 'typeProperty',
|
||||
format: ['camelCase', 'snake_case'],
|
||||
},
|
||||
{
|
||||
selector: 'function',
|
||||
format: ['camelCase'],
|
||||
leadingUnderscore: 'forbid',
|
||||
trailingUnderscore: 'forbid',
|
||||
},
|
||||
{
|
||||
selector: 'parameter',
|
||||
format: ['camelCase'],
|
||||
leadingUnderscore: 'allow',
|
||||
trailingUnderscore: 'forbid',
|
||||
},
|
||||
{
|
||||
selector: 'variable',
|
||||
modifiers: ['destructured'],
|
||||
format: [
|
||||
'camelCase',
|
||||
'PascalCase',
|
||||
'snake_case',
|
||||
'strictCamelCase',
|
||||
'StrictPascalCase',
|
||||
'UPPER_CASE',
|
||||
],
|
||||
},
|
||||
{
|
||||
selector: 'import',
|
||||
format: ['camelCase', 'PascalCase', 'UPPER_CASE'],
|
||||
},
|
||||
],
|
||||
'unicorn/filename-case': [
|
||||
'error',
|
||||
{
|
||||
cases: {
|
||||
kebabCase: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
'max-lines-per-function': [
|
||||
'warn',
|
||||
{
|
||||
max: 120,
|
||||
IIFEs: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
languageOptions: {
|
||||
parser: require('@typescript-eslint/parser'),
|
||||
parserOptions: {
|
||||
ecmaVersion: 11,
|
||||
projectService: true,
|
||||
sourceType: 'module',
|
||||
ecmaFeatures: {
|
||||
jsx: true,
|
||||
legacyDecorators: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ['**/*.?(m|c)tsx'],
|
||||
rules: {
|
||||
'@typescript-eslint/naming-convention': [
|
||||
'error',
|
||||
{
|
||||
selector: ['default', 'variableLike'],
|
||||
format: ['camelCase', 'UPPER_CASE'],
|
||||
},
|
||||
{
|
||||
selector: ['class', 'interface', 'typeLike'],
|
||||
format: ['PascalCase'],
|
||||
},
|
||||
{
|
||||
selector: ['variable'],
|
||||
format: ['UPPER_CASE', 'camelCase', 'PascalCase'],
|
||||
modifiers: ['global', 'exported'],
|
||||
},
|
||||
{
|
||||
selector: 'objectLiteralProperty',
|
||||
format: null,
|
||||
},
|
||||
{
|
||||
selector: 'enumMember',
|
||||
format: ['UPPER_CASE', 'PascalCase'],
|
||||
},
|
||||
{
|
||||
selector: 'typeProperty',
|
||||
format: ['camelCase', 'snake_case'],
|
||||
},
|
||||
{
|
||||
selector: 'parameter',
|
||||
format: ['camelCase'],
|
||||
leadingUnderscore: 'allow',
|
||||
trailingUnderscore: 'forbid',
|
||||
},
|
||||
{
|
||||
selector: 'parameter',
|
||||
format: ['camelCase', 'snake_case'],
|
||||
modifiers: ['destructured'],
|
||||
},
|
||||
{
|
||||
selector: 'variable',
|
||||
modifiers: ['destructured'],
|
||||
format: [
|
||||
'camelCase',
|
||||
'PascalCase',
|
||||
'snake_case',
|
||||
'strictCamelCase',
|
||||
'StrictPascalCase',
|
||||
'UPPER_CASE',
|
||||
],
|
||||
},
|
||||
{
|
||||
selector: 'import',
|
||||
format: ['camelCase', 'PascalCase', 'UPPER_CASE'],
|
||||
},
|
||||
{
|
||||
selector: 'function',
|
||||
format: ['camelCase', 'PascalCase'],
|
||||
leadingUnderscore: 'forbid',
|
||||
trailingUnderscore: 'forbid',
|
||||
},
|
||||
{
|
||||
selector: 'variable',
|
||||
format: ['camelCase', 'PascalCase', 'UPPER_CASE'],
|
||||
leadingUnderscore: 'allow',
|
||||
},
|
||||
],
|
||||
'unicorn/filename-case': [
|
||||
'warn',
|
||||
{
|
||||
cases: {
|
||||
kebabCase: true,
|
||||
snakeCase: true,
|
||||
pascalCase: true,
|
||||
},
|
||||
ignore: ['^(?!.*?\\.jsx$)(?!.*?\\.tsx$).+'],
|
||||
},
|
||||
],
|
||||
'max-lines-per-function': [
|
||||
'warn',
|
||||
{
|
||||
max: 300,
|
||||
IIFEs: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
// TODO: 之前overides的内容,后需可考虑直接合入上面标准配置
|
||||
{
|
||||
files: ['**/*.?(m|c)ts?(x)'],
|
||||
rules: {
|
||||
'@typescript-eslint/consistent-type-imports': [
|
||||
'error',
|
||||
{
|
||||
fixStyle: 'inline-type-imports',
|
||||
},
|
||||
],
|
||||
// 这些规则都是从 packages/config/.eslintrc.react.js 复制迁移过来
|
||||
// 后续在做调整
|
||||
'@typescript-eslint/no-redundant-type-constituents': 0,
|
||||
'@typescript-eslint/no-throw-literal': 'off',
|
||||
'@typescript-eslint/no-unnecessary-condition': 0,
|
||||
'@typescript-eslint/prefer-optional-chain': 0,
|
||||
'@typescript-eslint/indent': 0,
|
||||
'@babel/new-cap': 'off',
|
||||
'@typescript-eslint/explicit-function-return-type': 'off',
|
||||
'no-shadow': 'off',
|
||||
'@typescript-eslint/no-shadow': 'error',
|
||||
// TODO: 后续开启
|
||||
// 'import/no-cycle': 'error',
|
||||
|
||||
'@typescript-eslint/prefer-string-starts-ends-with': 0,
|
||||
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 0,
|
||||
'@typescript-eslint/no-implied-eval': 0, // warning
|
||||
|
||||
// TODO: 打开下面这些配置
|
||||
// fix: https://stackoverflow.com/questions/63961803/eslint-says-all-enums-in-typescript-app-are-already-declared-in-the-upper-scope
|
||||
// 'no-shadow': 'off',
|
||||
// '@typescript-eslint/no-shadow': ['error'],
|
||||
// '@typescript-eslint/consistent-type-imports': [
|
||||
// 'error',
|
||||
// {
|
||||
// fixStyle: 'inline-type-imports',
|
||||
// },
|
||||
// ],
|
||||
// according to: https://typescript-eslint.io/linting/troubleshooting/#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors
|
||||
// 'no-undef': 'off',
|
||||
// 'no-unused-vars': 'off',
|
||||
// '@typescript-eslint/no-unused-vars': [
|
||||
// 'error',
|
||||
// {
|
||||
// vars: 'all',
|
||||
// args: 'none', // function arguments should not force to match this rule.
|
||||
// ignoreRestSiblings: false,
|
||||
// },
|
||||
// ],
|
||||
// complexity: ['error', { max: 15 }],
|
||||
// 后面统一使用CustomError后 再开启
|
||||
'@coze-arch/no-new-error': 'off',
|
||||
},
|
||||
},
|
||||
];
|
||||
Reference in New Issue
Block a user