blob: 18adb3d9a80794efcc6c62062e2e23a45d849237 [file] [log] [blame]
Tim van der Lipped6c33c42020-03-10 16:57:221const path = require('path');
2const rulesDirPlugin = require('eslint-plugin-rulesdir')
3rulesDirPlugin.RULES_DIR = path.join(__dirname, 'scripts', 'eslint_rules', 'lib');
4
Blink Reformat4c46d092018-04-07 15:32:375module.exports = {
Tim van der Lippe1d6e57a2019-09-30 11:55:346 'root': true,
Blink Reformat4c46d092018-04-07 15:32:377
Tim van der Lippe1d6e57a2019-09-30 11:55:348 'env': {'browser': true, 'es6': true},
Blink Reformat4c46d092018-04-07 15:32:379
Tim van der Lippe399a9562020-01-16 10:53:2810 'parser': '@typescript-eslint/parser',
11
12 'plugins': [
13 '@typescript-eslint',
Jack Franklin8b9aa2f2020-02-12 16:35:1514 'mocha',
Tim van der Lipped6c33c42020-03-10 16:57:2215 'rulesdir',
Tim van der Lippe399a9562020-01-16 10:53:2816 ],
17
Tim van der Lippe1d6e57a2019-09-30 11:55:3418 'parserOptions': {'ecmaVersion': 9, 'sourceType': 'module'},
Blink Reformat4c46d092018-04-07 15:32:3719
Tim van der Lippe1d6e57a2019-09-30 11:55:3420 /**
Blink Reformat4c46d092018-04-07 15:32:3721 * ESLint rules
22 *
23 * All available rules: http://eslint.org/docs/rules/
24 *
25 * Rules take the following form:
26 * "rule-name", [severity, { opts }]
27 * Severity: 2 == error, 1 == warning, 0 == off.
28 */
Tim van der Lippe1d6e57a2019-09-30 11:55:3429 'rules': {
30 /**
Blink Reformat4c46d092018-04-07 15:32:3731 * Enforced rules
32 */
33
34
Tim van der Lippe1d6e57a2019-09-30 11:55:3435 // syntax preferences
Mathias Bynens23ee1aa2020-03-02 12:06:3836 'quotes': [2, 'single', {'avoidEscape': true, 'allowTemplateLiterals': false}],
Tim van der Lippe1d6e57a2019-09-30 11:55:3437 'semi': 2,
38 'no-extra-semi': 2,
39 'comma-style': [2, 'last'],
40 'wrap-iife': [2, 'inside'],
41 'spaced-comment': [2, 'always', {'markers': ['*']}],
42 'eqeqeq': [2],
43 'accessor-pairs': [2, {'getWithoutSet': false, 'setWithoutGet': false}],
44 'curly': 2,
45 'new-parens': 2,
46 'func-call-spacing': 2,
47 'arrow-parens': [2, 'as-needed'],
Tim van der Lippe20b29c22019-11-04 14:36:1548 'eol-last': 2,
Blink Reformat4c46d092018-04-07 15:32:3749
Tim van der Lippe1d6e57a2019-09-30 11:55:3450 // anti-patterns
Tim van der Lippe1d6e57a2019-09-30 11:55:3451 'no-caller': 2,
Mathias Bynens88e8f152020-03-25 14:33:1252 'no-case-declarations': 2,
Mathias Bynensf06e8c02020-02-28 13:58:2853 'no-cond-assign': 2,
54 'no-console': [2, {'allow': ['assert', 'context', 'error', 'timeStamp', 'time', 'timeEnd', 'warn']}],
55 'no-debugger': 2,
56 'no-dupe-keys': 2,
57 'no-duplicate-case': 2,
58 'no-else-return': [2, {'allowElseIf': false}],
59 'no-empty-character-class': 2,
Tim van der Lippe1d6e57a2019-09-30 11:55:3460 'no-implied-eval': 2,
61 'no-labels': 2,
Mathias Bynensf06e8c02020-02-28 13:58:2862 'no-multi-str': 2,
Tim van der Lippe1d6e57a2019-09-30 11:55:3463 'no-new-object': 2,
64 'no-octal-escape': 2,
65 'no-self-compare': 2,
66 'no-shadow-restricted-names': 2,
Tim van der Lippe1d6e57a2019-09-30 11:55:3467 'no-unreachable': 2,
68 'no-unsafe-negation': 2,
Mathias Bynensf06e8c02020-02-28 13:58:2869 'no-unused-vars': [2, {'args': 'none', 'vars': 'local'}],
70 'no-var': 2,
71 'no-with': 2,
72 'prefer-const': 2,
Tim van der Lippe1d6e57a2019-09-30 11:55:3473 'radix': 2,
74 'valid-typeof': 2,
Blink Reformat4c46d092018-04-07 15:32:3775
Tim van der Lippe1d6e57a2019-09-30 11:55:3476 // es2015 features
77 'require-yield': 2,
78 'template-curly-spacing': [2, 'never'],
Blink Reformat4c46d092018-04-07 15:32:3779
Tim van der Lippe1d6e57a2019-09-30 11:55:3480 // spacing details
81 'space-infix-ops': 2,
82 'space-in-parens': [2, 'never'],
83 'space-before-function-paren': [2, {'anonymous': 'never', 'named': 'never', 'asyncArrow': 'always'}],
84 'no-whitespace-before-property': 2,
85 'keyword-spacing': [
86 2, {
87 'overrides': {
88 'if': {'after': true},
89 'else': {'after': true},
90 'for': {'after': true},
91 'while': {'after': true},
92 'do': {'after': true},
93 'switch': {'after': true},
94 'return': {'after': true}
95 }
96 }
97 ],
98 'arrow-spacing': [2, {'after': true, 'before': true}],
Blink Reformat4c46d092018-04-07 15:32:3799
Tim van der Lippe1d6e57a2019-09-30 11:55:34100 // file whitespace
101 'no-multiple-empty-lines': [2, {'max': 2}],
102 'no-mixed-spaces-and-tabs': 2,
103 'no-trailing-spaces': 2,
104 'linebreak-style': [2, 'unix'],
Blink Reformat4c46d092018-04-07 15:32:37105
Tim van der Lippe1d6e57a2019-09-30 11:55:34106 /**
Blink Reformat4c46d092018-04-07 15:32:37107 * Disabled, aspirational rules
108 */
109
Tim van der Lippe1d6e57a2019-09-30 11:55:34110 'indent': [0, 2, {'SwitchCase': 1, 'CallExpression': {'arguments': 2}, 'MemberExpression': 2}],
Blink Reformat4c46d092018-04-07 15:32:37111
Tim van der Lippe1d6e57a2019-09-30 11:55:34112 // brace-style is disabled, as eslint cannot enforce 1tbs as default, but allman for functions
113 'brace-style': [0, 'allman', {'allowSingleLine': true}],
Blink Reformat4c46d092018-04-07 15:32:37114
Tim van der Lippe1d6e57a2019-09-30 11:55:34115 // key-spacing is disabled, as some objects use value-aligned spacing, some not.
116 'key-spacing': [0, {'beforeColon': false, 'afterColon': true, 'align': 'value'}],
117 // quote-props is diabled, as property quoting styles are too varied to enforce.
118 'quote-props': [0, 'as-needed'],
Blink Reformat4c46d092018-04-07 15:32:37119
Tim van der Lippe1d6e57a2019-09-30 11:55:34120 // no-implicit-globals will prevent accidental globals
Tim van der Lippe399a9562020-01-16 10:53:28121 'no-implicit-globals': [0],
122
123 '@typescript-eslint/interface-name-prefix': [2, {'prefixWithI': 'never'}],
124 '@typescript-eslint/explicit-member-accessibility': [0],
Jack Franklin8b9aa2f2020-02-12 16:35:15125
126 // errors on it('test') with no body
127 'mocha/no-pending-tests': 2,
128 // errors on {describe, it}.only
129 'mocha/no-exclusive-tests': 2,
Tim van der Lipped6c33c42020-03-10 16:57:22130
131 // DevTools specific rules
132 'rulesdir/es_modules_import': 2,
Tim van der Lippe4a8441c2020-03-12 15:45:18133 'rulesdir/check_license_header': 2,
Tim van der Lippe399a9562020-01-16 10:53:28134 },
135 'overrides': [{
136 'files': ['*.ts'],
137 'rules': {
Jack Franklinb07e3302020-03-19 15:45:50138 '@typescript-eslint/explicit-member-accessibility': [2, {'accessibility': 'explicit'}],
Tim van der Lippe399a9562020-01-16 10:53:28139 'comma-dangle': [2, 'always-multiline'],
Jack Franklin95310322020-03-20 14:34:04140 // run just the TypeScript unused-vars rule, else we get duplicate errors
141 'no-unused-vars': 0,
Tim van der Lippe399a9562020-01-16 10:53:28142 '@typescript-eslint/no-unused-vars': [2],
143 }
144 }]
Blink Reformat4c46d092018-04-07 15:32:37145};