-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 124c633
Showing
32 changed files
with
7,268 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
/** JS 和 TS 公用的规则 */ | ||
const publicConfig = { | ||
plugins: ['prettier'], | ||
rules: { | ||
// 启用 prettier | ||
'prettier/prettier': ['warn', { singleQuote: true, trailingComma: 'all' }], | ||
|
||
// 允许在顶层外使用 require | ||
'global-require': 'off', | ||
// eslint-plugin-jsdoc 还无法识别出 TS 定义的接口 | ||
'jsdoc/no-undefined-types': 'off', | ||
// 不强制要求 jsdoc | ||
'jsdoc/require-jsdoc': 'off', | ||
// TS 不需要写明类型注释 | ||
'jsdoc/require-param-type': 'off', | ||
'jsdoc/require-returns-type': 'off', | ||
// 允许使用其他的 jsdoc 标签,以便使用 typescript-json-schema | ||
'jsdoc/check-tag-names': 'off', | ||
// 禁用将对象参数解构为多行 | ||
'jsdoc/require-param': ['warn', { checkDestructured: false }], | ||
'jsdoc/check-param-names': ['warn', { checkDestructured: false }], | ||
// 允许不写返回值的描述 | ||
'jsdoc/require-returns': 'off', | ||
|
||
// 允许使用下划线命名 | ||
'no-underscore-dangle': 'off', | ||
// 允许 console | ||
'no-console': 'off', | ||
|
||
// 允许 any 类型的分配 | ||
'no-unsafe-assignment': 'off', | ||
// 允许在 while 的条件语句里使用括号来赋值 | ||
'no-cond-assign': ['off', '"except-parens"'], | ||
|
||
// 不检查导入模块的扩展名 | ||
'import/extensions': 'off', | ||
// 禁止提醒将唯一 export 改为 default export | ||
'import/prefer-default-export': 'off', | ||
// 允许使用 require | ||
'import/no-dynamic-require': 'off', | ||
}, | ||
}; | ||
|
||
// eslint-disable-next-line jsdoc/require-param | ||
/** 与公用规则合并 */ | ||
const buildConfig = ({ plugins = [], rules = {}, ...otherConfig }) => ({ | ||
...otherConfig, | ||
plugins: [...publicConfig.plugins, ...plugins], | ||
rules: { ...publicConfig.rules, ...rules }, | ||
}); | ||
|
||
module.exports = { | ||
root: true, | ||
env: { | ||
es2021: true, | ||
node: true, | ||
}, | ||
ignorePatterns: ['dist', 'node_modules'], | ||
overrides: [ | ||
buildConfig({ | ||
files: ['*.ts', '*.tsx'], | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
tsconfigRootDir: __dirname, | ||
project: ['./packages/*/tsconfig.json'], | ||
}, | ||
plugins: ['@typescript-eslint', 'jsdoc'], | ||
extends: [ | ||
'airbnb', | ||
'airbnb/hooks', | ||
'plugin:jsdoc/recommended', | ||
'plugin:import/typescript', | ||
// 'plugin:react/recommended', | ||
'plugin:react/jsx-runtime', | ||
// 'plugin:react-hooks/recommended', | ||
'plugin:@typescript-eslint/eslint-recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:@typescript-eslint/recommended-requiring-type-checking', | ||
'plugin:prettier/recommended', | ||
], | ||
rules: { | ||
// 使用 TS 的规则 | ||
'no-use-before-define': 'off', | ||
'@typescript-eslint/no-use-before-define': ['error'], | ||
'no-shadow': 'off', | ||
'@typescript-eslint/no-shadow': ['error'], | ||
'no-unused-vars': 'off', | ||
'@typescript-eslint/no-unused-vars': [ | ||
'warn', | ||
{ varsIgnorePattern: 'React' }, | ||
], | ||
|
||
// 自动将直接 import 的类型改为用 import type 导入 | ||
'@typescript-eslint/consistent-type-imports': ['warn', {}], | ||
|
||
// 允许使用 require 导入模块。方便 Bluebird 对其进行包装 | ||
'@typescript-eslint/no-var-requires': 'off', | ||
// 允许不声明函数返回类型 | ||
'@typescript-eslint/explicit-function-return-type': 'off', | ||
// 允许使用未注释的空函数 | ||
'@typescript-eslint/no-empty-function': 'off', | ||
// 允许匿名的异步立即执行函数 | ||
'@typescript-eslint/no-floating-promises': [ | ||
'warn', | ||
{ ignoreIIFE: true }, | ||
], | ||
// 允许不显式写出导出函数的返回类型 | ||
'@typescript-eslint/explicit-module-boundary-types': 'off', | ||
// 禁止提醒非空断言 | ||
'@typescript-eslint/no-non-null-assertion': 'off', | ||
// 禁止提醒在模板表达式中使用了非字符串类型 | ||
'@typescript-eslint/restrict-template-expressions': 'off', | ||
// 禁用 TS 的 camelcase,用 JS 的就够了 | ||
'@typescript-eslint/camelcase': 'off', | ||
// 允许在 TS 允许且我已经正确处理的地方使用 Promise | ||
'@typescript-eslint/no-misused-promises': 'off', | ||
|
||
// 禁止提醒使用了 any | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
'@typescript-eslint/no-unsafe-argument': 'off', | ||
// 允许访问 any 类型属性 | ||
'@typescript-eslint/no-unsafe-member-access': 'off', | ||
// 允许调用 any 类型变量 | ||
'@typescript-eslint/no-unsafe-call': 'off', | ||
// 允许分配 any 类型变量 | ||
'@typescript-eslint/no-unsafe-assignment': 'off', | ||
|
||
// | ||
// React 适配 | ||
// | ||
|
||
// 使此规则支持 TS | ||
'react/jsx-filename-extension': [ | ||
'warn', | ||
{ extensions: ['.tsx', '.jsx'] }, | ||
], | ||
'react/function-component-definition': [ | ||
'warn', | ||
{ namedComponents: 'arrow-function' }, | ||
], | ||
// 有 TS 不需要这个 | ||
'react/prop-types': 'off', | ||
// 允许使用对象解构来传输 props | ||
'react/jsx-props-no-spreading': 'off', | ||
}, | ||
}), | ||
buildConfig({ | ||
files: ['*.js'], | ||
extends: ['eslint:recommended', 'airbnb', 'plugin:prettier/recommended'], | ||
rules: { | ||
// 禁止提醒使用了 dev 的包 | ||
'import/no-extraneous-dependencies': 'off', | ||
}, | ||
}), | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"folders": [ | ||
{ | ||
"path": ".", | ||
"name": "root" | ||
}, | ||
{ | ||
"path": "packages/userscript", | ||
"name": "userscript" | ||
}, | ||
{ | ||
"path": "packages/ui-component", | ||
"name": "ui-component" | ||
}, | ||
], | ||
} |
Oops, something went wrong.