Merge branch 'MDL-75381-400' of https://github.com/paulholden/moodle into MOODLE_400_...
[moodle.git] / .eslintrc
blob8b60ac062456f2c1a74aefbc8b20d81dfb010e50
2   'plugins': [
3     'babel',
4     'promise',
5     'jsdoc',
6   ],
7   'env': {
8     'browser': true,
9     // Enable ES6+ features by default.
10     // See http://eslint.org/docs/user-guide/configuring#specifying-environments
11     // Note: The YUI override must exactly match this when disabling the ES6+ version because those features are not supported by Shifter.
12     'es2020': true,
13     'amd': true
14   },
15   'globals': {
16     'M': true,
17     'Y': true
18   },
19   'rules': {
20     // See http://eslint.org/docs/rules/ for all rules and explanations of all
21     // rules.
23     // === Possible Errors ===
24     'comma-dangle': 'off',
25     'no-compare-neg-zero': 'error',
26     'no-cond-assign': 'error',
27     'no-console': 'error',
28     'no-constant-condition': 'error',
29     'no-control-regex': 'error',
30     'no-debugger': 'error',
31     'no-dupe-args': 'error',
32     'no-dupe-keys': 'error',
33     'no-duplicate-case': 'error',
34     'no-empty': 'warn',
35     'no-empty-character-class': 'error',
36     'no-ex-assign': 'error',
37     'no-extra-boolean-cast': 'error',
38     'no-extra-parens': 'off',
39     'no-extra-semi': 'error',
40     'no-func-assign': 'error',
41     'no-inner-declarations': 'error',
42     'no-invalid-regexp': 'error',
43     'no-irregular-whitespace': 'error',
44     'no-obj-calls': 'error',
45     'no-prototype-builtins': 'off',
46     'no-regex-spaces': 'error',
47     'no-sparse-arrays': 'error',
48     'no-unexpected-multiline': 'error',
49     'no-unreachable': 'warn',
50     'no-unsafe-finally': 'error',
51     'no-unsafe-negation': 'error',
52     'use-isnan': 'error',
53     'valid-jsdoc': ['warn', { 'requireReturn': false, 'requireParamDescription': false, 'requireReturnDescription': false }],
54     'valid-typeof': 'error',
56     // === Best Practices ===
57     // (these mostly match our jshint config)
58     'array-callback-return': 'warn',
59     'block-scoped-var': 'warn',
60     'complexity': 'warn',
61     'consistent-return': 'warn',
62     'curly': 'error',
63     'dot-notation': 'warn',
64     'no-alert': 'warn',
65     'no-caller': 'error',
66     'no-case-declarations': 'error',
67     'no-div-regex': 'error',
68     'no-empty-pattern': 'error',
69     'no-empty-function': 'warn',
70     'no-eq-null': 'error',
71     'no-eval': 'error',
72     'no-extend-native': 'error',
73     'no-extra-bind': 'warn',
74     'no-fallthrough': 'error',
75     'no-floating-decimal': 'warn',
76     'no-global-assign': 'warn',
77     'no-implied-eval': 'error',
78     'no-invalid-this': 'error',
79     'no-iterator': 'error',
80     'no-labels': 'error',
81     'no-loop-func': 'error',
82     'no-multi-spaces': 'warn',
83     'no-multi-str': 'error',
84     'no-new-func': 'error',
85     'no-new-wrappers': 'error',
86     'no-octal': 'error',
87     'no-octal-escape': 'error',
88     'no-proto': 'error',
89     'no-redeclare': 'warn',
90     'no-return-assign': 'error',
91     'no-script-url': 'error',
92     'no-self-assign': 'error',
93     'no-self-compare': 'error',
94     'no-sequences': 'warn',
95     'no-throw-literal': 'warn',
96     'no-unmodified-loop-condition': 'error',
97     'no-unused-expressions': 'error',
98     'no-unused-labels': 'error',
99     'no-useless-call': 'warn',
100     'no-useless-escape': 'warn',
101     'no-with': 'error',
102     'wrap-iife': ['error', 'any'],
104     // === Variables ===
105     'no-delete-var': 'error',
106     'no-undef': 'error',
107     'no-undef-init': 'error',
108     'no-unused-vars': ['error', { 'caughtErrors': 'none' }],
110     // === Stylistic Issues ===
111     'array-bracket-spacing': 'warn',
112     'block-spacing': 'warn',
113     'brace-style': ['warn', '1tbs'],
114     'camelcase': 'warn',
115     'capitalized-comments': ['warn', 'always', { 'ignoreConsecutiveComments': true }],
116     'comma-spacing': ['warn', { 'before': false, 'after': true }],
117     'comma-style': ['warn', 'last'],
118     'computed-property-spacing': 'error',
119     'consistent-this': 'off',
120     'eol-last': 'off',
121     'func-call-spacing': ['warn', 'never'],
122     'func-names': 'off',
123     'func-style': 'off',
124     // indent currently not doing well with our wrapping style, so disabled.
125     'indent': ['off', 4, { 'SwitchCase': 1 }],
126     'key-spacing': ['warn', { 'beforeColon': false, 'afterColon': true, 'mode': minimum }],
127     'keyword-spacing': 'warn',
128     'linebreak-style': ['error', 'unix'],
129     'lines-around-comment': 'off',
130     'max-len': ['error', 132],
131     'max-lines': 'off',
132     'max-depth': 'warn',
133     'max-nested-callbacks': ['warn', 5],
134     'max-params': 'off',
135     'max-statements': 'off',
136     'max-statements-per-line': ['warn', { max: 2 }],
137     'new-cap': ['warn', { 'properties': false }],
138     'new-parens': 'warn',
139     'newline-after-var': 'off',
140     'newline-before-return': 'off',
141     'newline-per-chained-call': 'off',
142     'no-array-constructor': 'off',
143     'no-bitwise': 'error',
144     'no-continue': 'off',
145     'no-inline-comments': 'off',
146     'no-lonely-if': 'off',
147     'no-mixed-operators': 'off',
148     'no-mixed-spaces-and-tabs': 'error',
149     'no-multiple-empty-lines': 'warn',
150     'no-negated-condition': 'off',
151     'no-nested-ternary': 'warn',
152     'no-new-object': 'off',
153     'no-plusplus': 'off',
154     'no-tabs': 'error',
155     'no-ternary': 'off',
156     'no-trailing-spaces': 'error',
157     'no-underscore-dangle': 'off',
158     'no-unneeded-ternary': 'off',
159     'no-whitespace-before-property': 'warn',
160     'object-curly-newline': 'off',
161     'object-curly-spacing': 'warn',
162     'object-property-newline': 'off',
163     'one-var': 'off',
164     'one-var-declaration-per-line': ['warn', 'initializations'],
165     'operator-assignment': 'off',
166     'operator-linebreak': 'off',
167     'padded-blocks': 'off',
168     'quote-props': ['warn', 'as-needed', {'unnecessary': false, 'keywords': true, 'numbers': true}],
169     'quotes': 'off',
170     'require-jsdoc': 'warn',
171     'semi': 'error',
172     'semi-spacing': ['warn', {'before': false, 'after': true}],
173     'sort-vars': 'off',
174     'space-before-blocks': 'warn',
175     'space-before-function-paren': ['warn', 'never'],
176     'space-in-parens': 'warn',
177     'space-infix-ops': 'warn',
178     'space-unary-ops': 'warn',
179     'spaced-comment': 'warn',
180     'unicode-bom': 'error',
181     'wrap-regex': 'off',
183     // === Promises ===
184     'promise/always-return': 'warn',
185     'promise/no-return-wrap': 'warn',
186     'promise/param-names': 'warn',
187     'promise/catch-or-return': ['warn', {terminationMethod: ['catch', 'fail']}],
188     'promise/no-native': 'warn',
189     'promise/no-promise-in-callback': 'warn',
190     'promise/no-callback-in-promise': 'warn',
191     'promise/avoid-new': 'warn',
193     // === Deprecations ===
194     "no-restricted-properties": ['warn', {
195         'object': 'M',
196         'property': 'str',
197         'message': 'Use AMD module "core/str" or M.util.get_string()'
198     }],
199   },
200   overrides: [
201     {
202       files: ["**/yui/src/**/*.js"],
203       'env': {
204         // Disable ES6+ for YUI files.
205         'es2020': false,
206       },
207       // Disable some rules which we can't safely define for YUI rollups.
208       rules: {
209         'no-undef': 'off',
210         'no-unused-vars': 'off',
211         'no-unused-expressions': 'off',
213         // === JSDocs ===
214         "jsdoc/check-access": 'off',
215         "jsdoc/check-alignment": 'off',
216         "jsdoc/check-param-names": 'off',
217         "jsdoc/check-property-names": 'off',
218         "jsdoc/empty-tags": 'off',
219         "jsdoc/implements-on-classes": 'off',
220         "jsdoc/multiline-blocks": 'off',
221         "jsdoc/require-jsdoc": 'off',
222         "jsdoc/require-param": 'off',
223         "jsdoc/require-param-name": 'off',
224         "jsdoc/require-param-type": 'off',
225         "jsdoc/require-property": 'off',
226         "jsdoc/require-property-name": 'off',
227         "jsdoc/require-property-type": 'off',
228       }
229     },
230     {
231       files: ["**/amd/src/*.js", "**/amd/src/**/*.js", "Gruntfile.js", ".grunt/*.js", ".grunt/tasks/*.js", "jsdoc.conf.js"],
232       // We're using babel transpiling so use their parser
233       // for linting.
234       parser: '@babel/eslint-parser',
235       // Check AMD with some slightly stricter rules.
236       rules: {
237         'no-unused-vars': 'error',
238         'no-implicit-globals': 'error',
239         // Disable all of the rules that have babel versions.
240         'new-cap': 'off',
241         // Not using this rule for the time being because it isn't
242         // compatible with jQuery and ES6.
243         'no-invalid-this': 'off',
244         'object-curly-spacing': 'off',
245         'quotes': 'off',
246         'semi': 'off',
247         'no-unused-expressions': 'off',
248         // Enable all of the babel version of these rules.
249         'babel/new-cap': ['warn', { 'properties': false }],
250         // Not using this rule for the time being because it isn't
251         // compatible with jQuery and ES6.
252         'babel/no-invalid-this': 'off',
253         'babel/object-curly-spacing': 'warn',
254         // This is off in the original style int.
255         'babel/quotes': 'off',
256         'babel/semi': 'error',
257         'babel/no-unused-expressions': 'error',
258         // === Promises ===
259         // We have Promise now that we're using ES6.
260         'promise/no-native': 'off',
261         'promise/avoid-new': 'off',
263         // === JSDocs ===
264         "jsdoc/check-access": [
265           'error',
266         ],
267         "jsdoc/check-alignment": 1, // Recommended.
268         "jsdoc/check-param-names": [
269           'error',
270         ],
271         "jsdoc/check-property-names": [
272           'error',
273         ],
274         "jsdoc/empty-tags": [
275           'error',
276         ],
277         "jsdoc/implements-on-classes": [
278           'error',
279         ],
280         "jsdoc/multiline-blocks": [
281           'error',
282         ],
283         "jsdoc/require-jsdoc": [
284           'error',
285         ],
286         "jsdoc/require-param": [
287           'error',
288         ],
289         "jsdoc/require-param-name": [
290           'error',
291         ],
292         "jsdoc/require-param-type": [
293           'error',
294         ],
295         "jsdoc/require-property": [
296           'error',
297         ],
298         "jsdoc/require-property-name": [
299           'error',
300         ],
301         "jsdoc/require-property-type": [
302           'error',
303         ],
304       },
305       parserOptions: {
306         'sourceType': 'module',
307         'requireConfigFile': false,
308       }
309     }
310   ]