UNPKG

6.36 kBJavaScriptView Raw
1// Copyright 2020 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// clang-format off
6
7const path = require('path');
8const rulesDirPlugin = require('eslint-plugin-rulesdir');
9rulesDirPlugin.RULES_DIR = path.join(__dirname, 'scripts', 'eslint_rules', 'lib');
10
11module.exports = {
12 'root': true,
13
14 'env': {'browser': true, 'es6': true},
15
16 'parser': '@typescript-eslint/parser',
17
18 'plugins': [
19 '@typescript-eslint',
20 'mocha',
21 'rulesdir',
22 'import',
23 'jsdoc',
24 ],
25
26 'parserOptions': {'ecmaVersion': 9, 'sourceType': 'module'},
27
28 /**
29 * ESLint rules
30 *
31 * All available rules: http://eslint.org/docs/rules/
32 *
33 * Rules take the following form:
34 * 'rule-name', [severity, { opts }]
35 * Severity: 2 == error, 1 == warning, 0 == off.
36 */
37 'rules': {
38 /**
39 * Enforced rules
40 */
41
42 // syntax preferences
43 'quotes': [2, 'single', {'avoidEscape': true, 'allowTemplateLiterals': false}],
44 'semi': 2,
45 'no-extra-semi': 2,
46 'comma-style': [2, 'last'],
47 'wrap-iife': [2, 'inside'],
48 'spaced-comment': [2, 'always', {'markers': ['*']}],
49 'eqeqeq': [2],
50 'accessor-pairs': [2, {'getWithoutSet': false, 'setWithoutGet': false}],
51 'curly': 2,
52 'new-parens': 2,
53 'func-call-spacing': 2,
54 'arrow-parens': [2, 'as-needed'],
55 'eol-last': 2,
56
57 // anti-patterns
58 'no-caller': 2,
59 'no-case-declarations': 2,
60 'no-cond-assign': 2,
61 'no-console': [2, {'allow': ['assert', 'context', 'error', 'timeStamp', 'time', 'timeEnd', 'warn']}],
62 'no-debugger': 2,
63 'no-dupe-keys': 2,
64 'no-duplicate-case': 2,
65 'no-else-return': [2, {'allowElseIf': false}],
66 'no-empty-character-class': 2,
67 'no-global-assign': 2,
68 'no-implied-eval': 2,
69 'no-labels': 2,
70 'no-multi-str': 2,
71 'no-new-object': 2,
72 'no-octal-escape': 2,
73 'no-self-compare': 2,
74 'no-shadow-restricted-names': 2,
75 'no-unreachable': 2,
76 'no-unsafe-negation': 2,
77 'no-unused-vars': [2, {'args': 'none', 'vars': 'local'}],
78 'no-var': 2,
79 'no-with': 2,
80 'prefer-const': 2,
81 'radix': 2,
82 'valid-typeof': 2,
83 'no-return-assign': [2, 'always'],
84 'no-implicit-coercion': 2,
85
86 // es2015 features
87 'require-yield': 2,
88 'template-curly-spacing': [2, 'never'],
89
90 // file whitespace
91 'no-multiple-empty-lines': [2, {'max': 1}],
92 'no-mixed-spaces-and-tabs': 2,
93 'no-trailing-spaces': 2,
94 'linebreak-style': [2, 'unix'],
95
96 /**
97 * Disabled, aspirational rules
98 */
99
100 'indent': [0, 2, {'SwitchCase': 1, 'CallExpression': {'arguments': 2}, 'MemberExpression': 2}],
101
102 // brace-style is disabled, as eslint cannot enforce 1tbs as default, but allman for functions
103 'brace-style': [0, 'allman', {'allowSingleLine': true}],
104
105 // key-spacing is disabled, as some objects use value-aligned spacing, some not.
106 'key-spacing': [0, {'beforeColon': false, 'afterColon': true, 'align': 'value'}],
107 // quote-props is diabled, as property quoting styles are too varied to enforce.
108 'quote-props': [0, 'as-needed'],
109
110 // no-implicit-globals will prevent accidental globals
111 'no-implicit-globals': [0],
112 'no-unused-private-class-members': 2,
113
114 // forbids interfaces starting with an I prefix.
115 '@typescript-eslint/naming-convention':
116 [2, {'selector': 'interface', 'format': ['PascalCase'], 'custom': {'regex': '^I[A-Z]', 'match': false}}],
117 '@typescript-eslint/explicit-member-accessibility': [0],
118 '@typescript-eslint/no-explicit-any': 2,
119
120 // Closure does not properly typecheck default exports
121 'import/no-default-export': 2,
122
123 // Try to spot '// console.log()' left over from debugging
124 'rulesdir/commented_out_console': 2,
125
126 // Prevent imports being commented out rather than deleted.
127 'rulesdir/commented_out_import': 2,
128
129 // DevTools specific rules
130 'rulesdir/es_modules_import': 2,
131 'rulesdir/check_license_header': 2,
132 /**
133 * Ensures that JS Doc comments are properly aligned - all the starting
134 * `*` are in the right place.
135 */
136 'jsdoc/check-alignment': 2,
137 },
138 'overrides': [{
139 'files': ['*.ts'],
140 'parserOptions': {
141 'allowAutomaticSingleRunInference': true,
142 'project': path.join(__dirname, 'config', 'typescript', 'tsconfig.eslint.json'),
143 },
144 'rules': {
145 '@typescript-eslint/explicit-member-accessibility': [2, {'accessibility': 'no-public'}],
146 'comma-dangle': 'off',
147 '@typescript-eslint/comma-dangle': [2, 'always-multiline'],
148
149 // run just the TypeScript unused-vars rule, else we get duplicate errors
150 'no-unused-vars': 0,
151 '@typescript-eslint/no-unused-vars': [2, {'argsIgnorePattern': '^_'}],
152 // run just the TypeScript semi rule, else we get duplicate errors
153 'semi': 0,
154 '@typescript-eslint/semi': ['error'],
155 '@typescript-eslint/member-delimiter-style': [
156 'error', {
157 'multiline': {'delimiter': 'semi', 'requireLast': true},
158 'singleline': {'delimiter': 'comma', 'requireLast': false},
159 'overrides': {
160 'interface': {
161 'singleline': {'delimiter': 'semi', 'requireLast': false},
162 'multiline': {'delimiter': 'semi', 'requireLast': true}
163 },
164 'typeLiteral': {
165 'singleline': {'delimiter': 'comma', 'requireLast': false},
166 'multiline': {'delimiter': 'comma', 'requireLast': true}
167 }
168 }
169 }
170 ],
171 '@typescript-eslint/no-floating-promises': [2, {ignoreVoid: true}],
172 // func-call-spacing doesn't work well with .ts
173 'func-call-spacing': 0,
174 '@typescript-eslint/func-call-spacing': 2,
175
176 /**
177 * Enforce that enum members are explicitly defined:
178 * const enum Foo { A = 'a' } rather than const enum Foo { A }
179 */
180 '@typescript-eslint/prefer-enum-initializers': 2,
181 /**
182 * Ban non-null assertion operator, e.g.:
183 * this.foo!.toLowerCase()
184 */
185 '@typescript-eslint/no-non-null-assertion': 2,
186 '@typescript-eslint/consistent-type-imports': 2,
187 'rulesdir/const_enum': 2,
188 'rulesdir/no_underscored_properties': 2,
189 'rulesdir/prefer_readonly_keyword': 2,
190 'rulesdir/inline_type_imports': 2,
191 }
192 }]
193};
194
195// clang-format on