-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
executable file
·148 lines (137 loc) · 4.82 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
* Copyright (c) 2018-present, SF, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
"use strict";
// Inspired by https://github.com/airbnb/javascript but less opinionated.
// We use eslint-loader so even warnings are very visible.
// This is why we only use "WARNING" level for potential errors,
// and we don"t use "ERROR" level at all.
// In the future, we might create a separate list of rules for production.
// It would probably be more strict.
// The ESLint browser environment defines all browser globals as valid,
// even though most people don"t know some of them exist (e.g. `name` or `status`).
// This is dangerous as it hides accidentally undefined variables.
// We blacklist the globals that we deem potentially confusing.
// To use them, explicitly reference them, e.g. `window.name` or `window.status`.
module.exports = {
parser: 'babel-eslint',
extends: [
'sf-js',
'plugin:jsx-a11y/recommended',
'plugin:react/recommended',
'plugin:prettier/recommended',
'prettier/react',
], // 兼容 prettier
plugins: ['jsx-a11y', 'react', 'prettier'],
env: {
browser: true,
commonjs: true,
es6: true,
jest: true,
node: true,
},
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
},
settings: {
react: {
version: 'detect',
},
},
rules: {
// https://github.com/yannickcr/eslint-plugin-react/tree/master/docs/rules
'react/forbid-foreign-prop-types': ['warn', { allowInPropTypes: true }],
'react/jsx-pascal-case': [
'warn',
{
allowAllCaps: true,
ignore: [],
},
],
'react/no-typos': 'error',
'react/style-prop-object': 'warn',
'react/no-multi-comp': ['warn', { ignoreStateless: true }],
'react/prefer-es6-class': ['warn', 'always'],
'react/no-this-in-sfc': 'error',
'react/self-closing-comp': 'error',
'react/sort-comp': [
'error',
{
order: ['static-methods', 'lifecycle', 'everything-else', 'render'],
groups: {
lifecycle: [
'displayName',
'propTypes',
'contextTypes',
'childContextTypes',
'mixins',
'statics',
'defaultProps',
'constructor',
'getDefaultProps',
'state',
'getInitialState',
'getChildContext',
'getDerivedStateFromProps',
'componentWillMount',
'UNSAFE_componentWillMount',
'componentDidMount',
'componentWillReceiveProps',
'UNSAFE_componentWillReceiveProps',
'shouldComponentUpdate',
'componentWillUpdate',
'UNSAFE_componentWillUpdate',
'getSnapshotBeforeUpdate',
'componentDidUpdate',
'componentDidCatch',
'componentWillUnmount',
],
},
},
],
// "react/jsx-first-prop-new-line": ["error", "multiline-multiprop"],
'react/jsx-boolean-value': 'warn',
'react/jsx-indent': 'off', // 不关闭可能会与prettier冲突
'react/jsx-indent-props': 'off',
'react/jsx-closing-bracket-location': 'warn',
'react/jsx-closing-tag-location': 'warn',
'react/void-dom-elements-no-children': 'error',
'react/jsx-equals-spacing': ['error', 'never'],
'react/jsx-no-bind': ['warn', { allowArrowFunctions: true, allowFunctions: true }],
// "react/jsx-max-props-per-line": ["error", { "maximum": 1, "when": "always" }],
'react/jsx-one-expression-per-line': 'off', // 不关闭会与prettier冲突
'react/prop-types': 'off',
'react/jsx-curly-spacing': 'off',
// https://github.com/evcohen/eslint-plugin-jsx-a11y
'jsx-a11y/click-events-have-key-events': 'off',
'jsx-a11y/nteractive-supports-focus': 'off',
'jsx-a11y/no-interactive-element-to-noninteractive-role': 'warn',
'jsx-a11y/no-noninteractive-element-to-interactive-role': 'warn',
'jsx-a11y/media-has-caption': 'off',
'jsx-a11y/mouse-events-have-key-events': 'off',
'jsx-a11y/no-noninteractive-element-interactions': 'off',
'jsx-a11y/no-onchange': 'off',
'jsx-a11y/no-static-element-interactions': 'off',
'jsx-a11y/no-access-key': 'off',
'jsx-a11y/anchor-has-content': 'warn',
// https://github.com/gajus/eslint-plugin-flowtype
'prettier/prettier': [
'error',
{
printWidth: 100, // 一行的字符数,如果超过会进行换行。默认80
singleQuote: true, // 字符串是否使用单引号。默认false使用双引号
trailingComma: 'all', // 是否使用尾逗号,三个可选之’<none/es5/all>"
jsxBracketSameLine: false, // 尖括号换行
jsxSingleQuote: true, // jsx中使用单引号
endOfLine: 'lf',
},
],
},
};