1 |
|
2 | const restrictedProperties = [
|
3 | {
|
4 | object: 'arguments',
|
5 | property: 'callee',
|
6 | message: 'arguments.callee is deprecated',
|
7 | },
|
8 | {
|
9 | property: '__defineGetter__',
|
10 | message: 'Please use Object.defineProperty instead.',
|
11 | },
|
12 | {
|
13 | property: '__defineSetter__',
|
14 | message: 'Please use Object.defineProperty instead.',
|
15 | },
|
16 | {
|
17 | object: 'Math',
|
18 | property: 'pow',
|
19 | message: 'Use the exponentiation operator (**) instead.',
|
20 | },
|
21 | ];
|
22 | const restrictedSyntax = [
|
23 | {
|
24 | selector: 'ForInStatement',
|
25 | message:
|
26 | 'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
|
27 | },
|
28 | {
|
29 | selector: 'ForOfStatement',
|
30 | message:
|
31 | 'iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations.',
|
32 | },
|
33 | {
|
34 | selector: 'LabeledStatement',
|
35 | message:
|
36 | 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
|
37 | },
|
38 | {
|
39 | selector: 'WithStatement',
|
40 | message:
|
41 | '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
|
42 | },
|
43 | ];
|
44 |
|
45 | module.exports = {
|
46 | rules: {
|
47 | 'array-bracket-spacing': ['error', 'never'],
|
48 | 'array-callback-return': 'error',
|
49 | 'block-scoped-var': 'error',
|
50 | 'computed-property-spacing': ['error', 'never'],
|
51 | 'consistent-return': 'error',
|
52 | 'consistent-this': 'off',
|
53 | 'default-case': ['error', { commentPattern: '^no default$' }],
|
54 | 'dot-notation': ['error', { allowKeywords: true }],
|
55 | 'guard-for-in': 'error',
|
56 | 'id-blacklist': 'off',
|
57 | 'id-length': 'off',
|
58 | 'id-match': 'off',
|
59 | 'linebreak-style': ['error', 'unix'],
|
60 | 'lines-around-comment': 'off',
|
61 | 'lines-around-directive': ['error', { before: 'always', after: 'always' }],
|
62 | 'max-depth': ['off', 4],
|
63 | 'max-len': [
|
64 | 'error',
|
65 | 100,
|
66 | 2,
|
67 | {
|
68 | ignoreUrls: true,
|
69 | ignoreComments: false,
|
70 | ignoreRegExpLiterals: true,
|
71 | ignoreStrings: true,
|
72 | ignoreTemplateLiterals: true,
|
73 | },
|
74 | ],
|
75 | 'max-lines': [
|
76 | 'off',
|
77 | { max: 300, skipBlankLines: true, skipComments: true },
|
78 | ],
|
79 | 'max-nested-callbacks': 'off',
|
80 | 'max-params': ['off', 3],
|
81 | 'max-statements-per-line': ['off', { max: 1 }],
|
82 | 'max-statements': ['off', 10],
|
83 | 'multiline-ternary': ['off', 'never'],
|
84 | 'newline-after-var': 'off',
|
85 | 'newline-before-return': 'off',
|
86 | 'newline-per-chained-call': ['error', { ignoreChainWithDepth: 4 }],
|
87 | 'no-alert': 'warn',
|
88 | 'no-await-in-loop': 'error',
|
89 | 'no-bitwise': 'error',
|
90 | 'no-case-declarations': 'error',
|
91 | 'no-console': 'warn',
|
92 | 'no-continue': 'error',
|
93 | 'no-div-regex': 'off',
|
94 | 'no-else-return': 'error',
|
95 | 'no-empty': 'error',
|
96 | 'no-eq-null': 'off',
|
97 | 'no-extra-semi': 'error',
|
98 | 'no-implicit-coercion': 'error',
|
99 | 'no-implicit-globals': 'off',
|
100 | 'no-inline-comments': 'off',
|
101 | 'no-invalid-this': 'off',
|
102 | 'no-lonely-if': 'error',
|
103 | 'no-magic-numbers': [
|
104 | 'off',
|
105 | {
|
106 | ignore: [],
|
107 | ignoreArrayIndexes: true,
|
108 | enforceConst: true,
|
109 | detectObjects: false,
|
110 | },
|
111 | ],
|
112 | 'no-unexpected-multiline': 'off',
|
113 | 'no-negated-condition': 'off',
|
114 | 'no-param-reassign': 'error',
|
115 | 'no-plusplus': ['error', { allowForLoopAfterthoughts: true }],
|
116 | 'no-restricted-properties': ['error'].concat(restrictedProperties),
|
117 | 'no-restricted-syntax': ['error'].concat(restrictedSyntax),
|
118 | 'no-script-url': 'error',
|
119 | 'no-spaced-func': 'error',
|
120 | 'no-unused-labels': 'error',
|
121 | 'no-useless-concat': 'error',
|
122 | 'no-var': 'error',
|
123 | 'no-warning-comments': [
|
124 | 'off',
|
125 | { terms: ['todo', 'fixme', 'xxx'], location: 'start' },
|
126 | ],
|
127 | 'object-curly-spacing': ['error', 'always'],
|
128 | 'object-shorthand': 'error',
|
129 | 'prefer-const': 'error',
|
130 | 'prefer-template': 'error',
|
131 | 'quote-props': ['error', 'as-needed', { unnecessary: false }],
|
132 | radix: 'error',
|
133 | 'require-await': 'off',
|
134 | 'vars-on-top': 'error',
|
135 |
|
136 | 'import/no-unresolved': [
|
137 | 'error',
|
138 | { caseSensitive: true, commonjs: true, amd: true },
|
139 | ],
|
140 |
|
141 | 'standard/array-bracket-even-spacing': 'off',
|
142 | 'standard/computed-property-even-spacing': 'off',
|
143 | 'standard/object-curly-even-spacing': 'off',
|
144 | },
|
145 | };
|