Skip to content

Commit e927a9c

Browse files
committed
添加eslint
1 parent 6bb4ecc commit e927a9c

17 files changed

+1409
-241
lines changed

.eslintignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
scripts
2+
postcss.config.js
3+
redux.devtool.ts
4+
mock-server
5+
dist
6+
src/store/natur-persist
7+
natur-persist
8+
natur-service.ts
9+
_natur-service.ts

.eslintrc.js

+249
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
// http://eslint.org/docs/user-guide/configuring
2+
3+
module.exports = {
4+
root: true,
5+
env: {
6+
browser: true,
7+
// "commonjs": true,
8+
es6: true,
9+
},
10+
extends: [
11+
// "eslint:recommended",
12+
// "plugin:react/recommended"
13+
'airbnb',
14+
],
15+
// extends: "eslint:recommended",
16+
globals: {
17+
$: true,
18+
process: true,
19+
__dirname: true,
20+
},
21+
parser: 'babel-eslint',
22+
parserOptions: {
23+
// es6的module模式
24+
sourceType: 'module',
25+
ecmaFeatures: {
26+
experimentalObjectRestSpread: true,
27+
jsx: true,
28+
},
29+
ecmaVersion: 11, // es2020
30+
},
31+
settings: {
32+
'import/ignore': ['node_modules', 'DynamicForm', '.s?css', '@w*'],
33+
},
34+
plugins: ['react', 'react-hooks', 'import', 'jsx-a11y'],
35+
36+
overrides: [
37+
{
38+
files: ['**/*.ts', '**/*.tsx'],
39+
parser: '@typescript-eslint/parser',
40+
parserOptions: {
41+
ecmaVersion: 11,
42+
sourceType: 'module',
43+
ecmaFeatures: {
44+
jsx: true,
45+
},
46+
// typescript-eslint specific options
47+
warnOnUnsupportedTypeScriptVersion: true,
48+
},
49+
plugins: ['@typescript-eslint'],
50+
// If adding a typescript-eslint version of an existing ESLint rule,
51+
// make sure to disable the ESLint rule here.
52+
rules: {
53+
// TypeScript's `noFallthroughCasesInSwitch` option is more robust (#6906)
54+
'default-case': 'off',
55+
// 'tsc' already handles this (https://github.com/typescript-eslint/typescript-eslint/issues/291)
56+
'no-dupe-class-members': 'off',
57+
// Add TypeScript specific rules (and turn off ESLint equivalents)
58+
// '@typescript-eslint/no-angle-bracket-type-assertion': 'warn',
59+
'no-array-constructor': 'off',
60+
'@typescript-eslint/no-array-constructor': 'warn',
61+
'@typescript-eslint/no-namespace': 'error',
62+
'no-unused-vars': 1,
63+
'@typescript-eslint/no-unused-vars': [
64+
'warn',
65+
{
66+
args: 'none',
67+
ignoreRestSiblings: true,
68+
},
69+
],
70+
'no-useless-constructor': 'off',
71+
'@typescript-eslint/no-useless-constructor': 'warn',
72+
},
73+
},
74+
],
75+
rules: {
76+
'import/no-unresolved': 0,
77+
'import/extensions': 0,
78+
'import/order': 0,
79+
'import/prefer-default-export': 0,
80+
81+
'react/prop-types': 0,
82+
'react/jsx-filename-extension': 0,
83+
'react/prefer-stateless-function': 0,
84+
'react/jsx-indent': [2, 'tab'],
85+
'react/jsx-indent-props': [2, 'tab'],
86+
'react/jsx-tag-spacing': 0,
87+
'react/jsx-props-no-spreading': 0,
88+
'react/require-default-props': 0,
89+
// // @off 同构应用需要在 didMount 里写 setState
90+
'react/no-did-mount-set-state': 0,
91+
'react/button-has-type': 0,
92+
'react-hooks/rules-of-hooks': 'error', // Checks rules of Hooks
93+
'react-hooks/exhaustive-deps': 'warn', // Checks effect dependencies
94+
'react/react-in-jsx-scope': 0,
95+
96+
'jsx-a11y/anchor-is-valid': 0,
97+
'jsx-a11y/click-events-have-key-events': 0,
98+
'jsx-a11y/mouse-events-have-key-events': 0,
99+
'jsx-a11y/no-noninteractive-element-interactions': 0,
100+
'jsx-a11y/no-static-element-interactions': 0,
101+
'jsx-a11y/aria-role': 0,
102+
'jsx-a11y/alt-text': 0,
103+
'jsx-a11y/heading-has-content': 0,
104+
'jsx-a11y/anchor-has-content': 0,
105+
106+
'no-return-assign': 0,
107+
'consistent-return': 0,
108+
'no-console': 0,
109+
'no-plusplus': 0,
110+
'linebreak-style': 0,
111+
'no-unused-expressions': 0,
112+
// 0、1、2分别表示不开启检查、警告、错误
113+
indent: [2, 'tab', { SwitchCase: 1 }], // tab缩进
114+
// 圈复杂度
115+
complexity: [2, 9],
116+
'max-params': [2, 7],
117+
'max-depth': [2, 4],
118+
'no-multiple-empty-lines': 0,
119+
'max-len': [
120+
'error',
121+
{
122+
code: 150,
123+
tabWidth: 4,
124+
ignoreComments: true,
125+
ignoreUrls: true,
126+
ignoreStrings: true,
127+
ignoreTemplateLiterals: true,
128+
ignoreRegExpLiterals: true,
129+
},
130+
],
131+
'no-tabs': 0,
132+
'object-curly-newline': [
133+
0,
134+
{
135+
ObjectExpression: 'always',
136+
ObjectPattern: { multiline: true },
137+
ImportDeclaration: 'never',
138+
ExportDeclaration: {
139+
multiline: true,
140+
},
141+
},
142+
],
143+
'object-curly-spacing': 0,
144+
145+
'arrow-parens': [2, 'as-needed'],
146+
// 最大回调层数
147+
'max-nested-callbacks': [2, 3],
148+
'no-unused-vars': [
149+
1,
150+
{
151+
argsIgnorePattern: '^React',
152+
varsIgnorePattern: '[Rr]eact|[Ss]tyle',
153+
},
154+
],
155+
'no-extra-boolean-cast': 0,
156+
'array-callback-return': 0,
157+
'no-param-reassign': 0,
158+
'jsx-quotes': [0, 'prefer-double'], // 强制在JSX属性(jsx-quotes)中一致使用双引号
159+
'no-underscore-dangle': 0,
160+
'quote-props': 0,
161+
// "no-native-reassign": 2,//不能重写native对象
162+
// // if while function 后面的{必须与if在同一行,java风格。
163+
// "brace-style": [2, "1tbs", { "allowSingleLine": true }],
164+
// // 双峰驼命名格式
165+
// "camelcase": 2,
166+
// // 以方括号取对象属性时,[ 后面和 ] 前面是否需要空格, 可选参数 never, always
167+
// "computed-property-spacing": [2,"never"],
168+
// //允许箭头函数可以省略小括号
169+
// 'arrow-parens': 0,
170+
// 'no-extra-semi': 2, // 不允许多余的分号
171+
// //允许使用async-await函数
172+
// 'generator-star-spacing': 0,
173+
// //在开发环境开启debugger功能,生产环境禁止使用debugger
174+
// 'no-debugger': process.env.NODE_ENV === 'development' ? 0 : 2,
175+
// "quotes": [2, "single"], //单引号
176+
// "no-var": 2, //对var警告
177+
// "semi": ["error", "always"], //不强制使用分号
178+
// "no-irregular-whitespace": 0, //不规则的空白不允许
179+
// "no-alert": 2, //禁止使用alert confirm prompt
180+
// "no-lone-blocks": 0, //禁止不必要的嵌套块
181+
// "no-class-assign": 2, //禁止给类赋值
182+
// "no-cond-assign": 2, //禁止在条件表达式中使用赋值语句
183+
// "no-const-assign": 2, //禁止修改const声明的变量
184+
// "no-delete-var": 2, //不能对var声明的变量使用delete操作符
185+
// "no-dupe-keys": 2, //在创建对象字面量时不允许键重复
186+
// "no-duplicate-case": 2, //switch中的case标签不能重复
187+
// "no-dupe-args": 2, //函数参数不能重复
188+
// "no-empty": 2, //块语句中的内容不能为空
189+
// "no-func-assign": 2, //禁止重复的函数声明
190+
// "no-invalid-this": 0, //禁止无效的this,只能用在构造器,类,对象字面量
191+
// "no-redeclare": 2, //禁止重复声明变量
192+
// "no-spaced-func": 2, //函数调用时 函数名与()之间不能有空格
193+
// "no-this-before-super": 0, //在调用super()之前不能使用this或super
194+
// "no-undef": 2, //不能有未定义的变量
195+
// "no-use-before-define": 2, //未定义前不能使用
196+
// // "camelcase": 0, //强制驼峰法命名
197+
// "no-mixed-spaces-and-tabs": 0, //禁止混用tab和空格
198+
// "prefer-arrow-callback": 0, //比较喜欢箭头回调
199+
// "arrow-spacing": 0, //=>的前/后括号
200+
//
201+
// // 禁止在 componentDidMount 里面使用 setState
202+
203+
// // 禁止在 componentDidUpdate 里面使用 setState
204+
// 'react/no-did-update-set-state': 2,
205+
// // 禁止拼写错误
206+
207+
// 'react/no-typos': 2,
208+
// // 禁止使用字符串 ref
209+
// 'react/no-string-refs': 2,
210+
// // @fixable 禁止出现 HTML 中的属性,如 class
211+
// 'react/no-unknown-property': 2,
212+
// // 禁止出现未使用的 propTypes
213+
// // @off 不强制要求写 propTypes
214+
// 'react/no-unused-prop-types': 2,
215+
// // 出现 jsx 的地方必须 import React
216+
// // @off 已经在 no-undef 中限制了
217+
// 'react/react-in-jsx-scope': 0,
218+
// // 非 required 的 prop 必须有 defaultProps
219+
// // @off 不强制要求写 propTypes
220+
// 'react/require-default-props': 0,
221+
// // render 方法中必须有返回值
222+
// 'react/require-render-return': 2,
223+
// // @fixable 组件内没有 children 时,必须使用自闭和写法
224+
// // @off 没必要限制
225+
// 'react/self-closing-comp': 0,
226+
// // style 属性的取值必须是 object
227+
// 'react/style-prop-object': 2,
228+
// // HTML 中的自闭和标签禁止有 children
229+
// 'react/void-dom-elements-no-children': 2,
230+
// // 数组中的 jsx 必须有 key
231+
// 'react/jsx-key': 2,
232+
// // 禁止在 jsx 中使用像注释的字符串
233+
// 'react/jsx-no-comment-textnodes': 2,
234+
// // 禁止出现重复的 props
235+
// 'react/jsx-no-duplicate-props': 2,
236+
// // 禁止使用未定义的 jsx elemet
237+
// 'react/jsx-no-undef': 2,
238+
// // jsx 文件必须 import React
239+
// 'react/jsx-uses-react': 2,
240+
// // 定义了的 jsx element 必须使用
241+
// 'react/jsx-uses-vars': 2,
242+
// // @fixable 多行的 jsx 必须有括号包起来
243+
// // @off 没必要限制
244+
// 'react/jsx-wrap-multilines': 2,
245+
// "react/no-array-index-key": 2, // 遍历出来的节点必须加key
246+
// "react/no-children-prop": 2, // 禁止使用children作为prop
247+
// "react/no-direct-mutation-state": 2, // 禁止直接this.state = 方式修改state 必须使用setState
248+
},
249+
};

.vscode/launch.json

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
// 使用 IntelliSense 了解相关属性。
3+
// 悬停以查看现有属性的描述。
4+
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Chrome",
9+
"type": "chrome",
10+
"request": "launch",
11+
"url": "http://localhost:8080",
12+
"webRoot": "${workspaceFolder}",
13+
"sourceMaps":true,
14+
// "sourceMapPathOverrides": {
15+
// "webpack:///src/*": "${webRoot}/*"
16+
// }
17+
},
18+
{
19+
"type": "node",
20+
"request": "launch",
21+
"name": "auto-get-module",
22+
"program": "${workspaceFolder}/scripts/auto-get-module/index.js"
23+
},
24+
{
25+
"type": "node",
26+
"request": "launch",
27+
"name": "npm run dev",
28+
"runtimeExecutable": "npm",
29+
"runtimeArgs": [
30+
"run-script",
31+
"dev"
32+
],
33+
"port": 8080
34+
},
35+
36+
{
37+
"type": "node",
38+
"request": "launch",
39+
"name": "build",
40+
"program": "${workspaceFolder}/scripts/build.js"
41+
},
42+
{
43+
"type": "node",
44+
"request": "launch",
45+
"name": "build_dll",
46+
"program": "${workspaceFolder}/scripts/build_dll.js"
47+
},
48+
{
49+
"type": "node",
50+
"request": "launch",
51+
"name": "create page",
52+
"program": "${workspaceFolder}/scripts/create-module/index.js"
53+
},
54+
]
55+
}

.vscode/settings.json

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"git.ignoreLimitWarning": true,
3+
"editor.fontSize": 18,
4+
"prettier.singleQuote": true,
5+
"prettier.useTabs": true,
6+
"prettier.trailingComma": "all",
7+
"javascript.implicitProjectConfig.experimentalDecorators": true,
8+
"emmet.includeLanguages": {
9+
"javascript": "javascriptreact"
10+
},
11+
"files.associations": {
12+
"*.html": "html"
13+
},
14+
"emmet.showExpandedAbbreviation": "always",
15+
"emmet.triggerExpansionOnTab": true,
16+
"editor.foldingStrategy": "indentation",
17+
"eslint.autoFixOnSave": true,
18+
"files.autoSave": "off",
19+
"eslint.validate": [
20+
"html",
21+
{
22+
"language": "javascript",
23+
"autoFix": true
24+
},
25+
{
26+
"language": "javascriptreact",
27+
"autoFix": true
28+
},
29+
{
30+
"language": "typescript",
31+
"autoFix": true
32+
},
33+
{
34+
"language": "typescriptreact",
35+
"autoFix": true
36+
}
37+
],
38+
"diffEditor.ignoreTrimWhitespace": true,
39+
"css.validate": false,
40+
"scss.validate": false,
41+
"less.validate": false,
42+
"stylelint.enable": true,
43+
"editor.codeActionsOnSave": {
44+
"source.fixAll.eslint": true,
45+
"source.fixAll.stylelint": true
46+
},
47+
"stylelint.autoFixOnSave": true
48+
}

0 commit comments

Comments
 (0)