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