Avi Drissman | 2497659 | 2022-09-12 15:24:31 | [diff] [blame] | 1 | // Copyright 2017 The Chromium Authors |
dpapad | ff82d51 | 2017-05-25 18:40:15 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | module.exports = { |
| 6 | 'root': true, |
| 7 | 'env': { |
| 8 | 'browser': true, |
dpapad | a0617309 | 2020-10-17 03:06:16 | [diff] [blame] | 9 | 'es2020': true, |
Christopher Lam | a5f2ad0 | 2018-12-05 10:05:58 | [diff] [blame] | 10 | }, |
| 11 | 'parserOptions': { |
dpapad | a0617309 | 2020-10-17 03:06:16 | [diff] [blame] | 12 | 'ecmaVersion': 2020, |
dpapad | 12b3c47 | 2019-05-29 02:16:05 | [diff] [blame] | 13 | 'sourceType': 'module', |
dpapad | ff82d51 | 2017-05-25 18:40:15 | [diff] [blame] | 14 | }, |
| 15 | 'rules': { |
| 16 | // Enabled checks. |
Dan Beam | 1a0d9dcb | 2019-01-08 09:05:35 | [diff] [blame] | 17 | 'brace-style': ['error', '1tbs'], |
dpapad | f4d85572 | 2022-07-19 01:28:18 | [diff] [blame] | 18 | |
| 19 | // https://google.github.io/styleguide/jsguide.html#features-arrays-trailing-comma |
| 20 | // https://google.github.io/styleguide/jsguide.html#features-objects-use-trailing-comma |
| 21 | 'comma-dangle': ['error', 'always-multiline'], |
| 22 | |
Dan Beam | 1a0d9dcb | 2019-01-08 09:05:35 | [diff] [blame] | 23 | 'curly': ['error', 'multi-line', 'consistent'], |
dpapad | c21c6fb | 2022-04-01 07:12:13 | [diff] [blame] | 24 | 'new-parens': 'error', |
dpapad | b2b0d6c | 2022-06-27 19:45:11 | [diff] [blame] | 25 | 'no-array-constructor': 'error', |
dpapad | c7570be | 2022-03-28 08:28:23 | [diff] [blame] | 26 | 'no-console': ['error', {allow: ['info', 'warn', 'error', 'assert']}], |
Dan Beam | b153665 | 2019-02-26 07:36:25 | [diff] [blame] | 27 | 'no-extra-boolean-cast': 'error', |
dpapad | ff82d51 | 2017-05-25 18:40:15 | [diff] [blame] | 28 | 'no-extra-semi': 'error', |
dpapad | 728cff0 | 2017-06-01 01:06:42 | [diff] [blame] | 29 | 'no-new-wrappers': 'error', |
Christopher Lam | a5f2ad0 | 2018-12-05 10:05:58 | [diff] [blame] | 30 | 'no-restricted-properties': [ |
| 31 | 'error', |
| 32 | { |
dpapad | 7b493a4 | 2019-06-22 02:07:09 | [diff] [blame] | 33 | 'property': '__lookupGetter__', |
| 34 | 'message': 'Use Object.getOwnPropertyDescriptor', |
| 35 | }, |
| 36 | { |
| 37 | 'property': '__lookupSetter__', |
| 38 | 'message': 'Use Object.getOwnPropertyDescriptor', |
| 39 | }, |
| 40 | { |
| 41 | 'property': '__defineGetter__', |
| 42 | 'message': 'Use Object.defineProperty', |
| 43 | }, |
| 44 | { |
| 45 | 'property': '__defineSetter__', |
| 46 | 'message': 'Use Object.defineProperty', |
| 47 | }, |
Dan Beam | 1aa00a12 | 2020-01-16 00:40:41 | [diff] [blame] | 48 | { |
| 49 | 'object': 'cr', |
| 50 | 'property': 'exportPath', |
| 51 | 'message': 'Use ES modules or cr.define() instead', |
| 52 | }, |
dpapad | 2674f928 | 2017-05-31 19:40:39 | [diff] [blame] | 53 | ], |
dpapad | bea253c3 | 2022-04-01 08:52:57 | [diff] [blame] | 54 | 'no-throw-literal': 'error', |
dpapad | 2d023f9 | 2022-03-29 21:11:23 | [diff] [blame] | 55 | 'no-trailing-spaces': 'error', |
Demetrios Papadopoulos | cf870bde | 2019-11-26 19:14:34 | [diff] [blame] | 56 | 'no-var': 'error', |
| 57 | 'prefer-const': 'error', |
dpapad | ab65692 | 2022-04-01 00:01:11 | [diff] [blame] | 58 | 'quotes': ['error', 'single', {allowTemplateLiterals: true}], |
dpapad | 1e511b1 | 2017-05-31 03:31:26 | [diff] [blame] | 59 | 'semi': ['error', 'always'], |
dpapad | 2674f928 | 2017-05-31 19:40:39 | [diff] [blame] | 60 | |
dpapad | d631d17 | 2022-07-20 17:29:01 | [diff] [blame] | 61 | // https://google.github.io/styleguide/jsguide.html#features-one-variable-per-declaration |
| 62 | 'one-var': ['error', { |
| 63 | let: 'never', |
| 64 | const: 'never', |
| 65 | }], |
| 66 | |
dpapad | ff82d51 | 2017-05-25 18:40:15 | [diff] [blame] | 67 | // TODO(dpapad): Add more checks according to our styleguide. |
| 68 | }, |
dpapad | ac97d7b6 | 2021-06-14 07:20:26 | [diff] [blame] | 69 | |
| 70 | 'overrides': [{ |
| 71 | 'files': ['**/*.ts'], |
| 72 | 'parser': './third_party/node/node_modules/@typescript-eslint/parser', |
dpapad | fa76653e | 2022-02-24 09:08:40 | [diff] [blame] | 73 | 'plugins': [ |
| 74 | '@typescript-eslint', |
| 75 | ], |
| 76 | 'rules': { |
| 77 | 'no-unused-vars': 'off', |
| 78 | '@typescript-eslint/no-unused-vars': [ |
| 79 | 'error', { |
| 80 | argsIgnorePattern: '^_', |
| 81 | varsIgnorePattern: '^_', |
| 82 | } |
dpapad | 5df2304 | 2022-03-21 19:22:37 | [diff] [blame] | 83 | ], |
| 84 | |
| 85 | 'semi': 'off', |
| 86 | '@typescript-eslint/semi': ['error'], |
dpapad | a2eca91 | 2022-03-28 09:36:44 | [diff] [blame] | 87 | |
dpapad | 0927916 | 2022-07-07 18:34:06 | [diff] [blame] | 88 | // https://google.github.io/styleguide/tsguide.html#arrayt-type |
| 89 | '@typescript-eslint/array-type': ['error', { |
| 90 | default: 'array-simple', |
| 91 | }], |
| 92 | |
dpapad | d533279 | 2022-07-11 21:15:14 | [diff] [blame] | 93 | // https://google.github.io/styleguide/tsguide.html#type-assertions-syntax |
| 94 | '@typescript-eslint/consistent-type-assertions': ['error', { |
| 95 | assertionStyle: 'as', |
| 96 | }], |
| 97 | |
dpapad | b1a935f | 2022-07-27 16:49:06 | [diff] [blame] | 98 | // https://google.github.io/styleguide/tsguide.html#interfaces-vs-type-aliases |
| 99 | "@typescript-eslint/consistent-type-definitions": ['error', 'interface'], |
| 100 | |
dpapad | 684f427b | 2022-05-10 05:47:02 | [diff] [blame] | 101 | // https://google.github.io/styleguide/jsguide.html#naming |
dpapad | 50adcde | 2022-05-07 00:05:52 | [diff] [blame] | 102 | '@typescript-eslint/naming-convention': [ |
| 103 | 'error', |
| 104 | { |
dpapad | 684f427b | 2022-05-10 05:47:02 | [diff] [blame] | 105 | selector: ['class', 'interface', 'typeAlias', 'enum', 'typeParameter'], |
dpapad | 978c1dab | 2022-10-19 18:12:09 | [diff] [blame] | 106 | format: ['StrictPascalCase'], |
| 107 | filter: { |
| 108 | regex: '^(' + |
| 109 | // Exclude TypeScript defined interfaces HTMLElementTagNameMap |
| 110 | // and HTMLElementEventMap. |
| 111 | 'HTMLElementTagNameMap|HTMLElementEventMap|' + |
| 112 | // Exclude native DOM types which are always named like HTML<Foo>Element. |
| 113 | 'HTML[A-Za-z]{0,}Element|' + |
| 114 | // Exclude native DOM interfaces. |
| 115 | 'UIEvent|UIEventInit|DOMError|' + |
| 116 | // Exclude the deprecated WebUIListenerBehavior interface. |
| 117 | 'WebUIListenerBehavior)$', |
| 118 | match: false, |
| 119 | }, |
dpapad | 50adcde | 2022-05-07 00:05:52 | [diff] [blame] | 120 | }, |
| 121 | { |
dpapad | 50adcde | 2022-05-07 00:05:52 | [diff] [blame] | 122 | selector: 'enumMember', |
| 123 | format: ['UPPER_CASE'], |
| 124 | }, |
dpapad | 684f427b | 2022-05-10 05:47:02 | [diff] [blame] | 125 | { |
| 126 | selector: 'classMethod', |
dpapad | e9ae77d | 2022-12-12 17:02:00 | [diff] [blame] | 127 | format: ['strictCamelCase'], |
dpapad | b7286e8 | 2022-06-16 01:33:27 | [diff] [blame] | 128 | modifiers: ['public'], |
| 129 | }, |
| 130 | { |
| 131 | selector: 'classMethod', |
dpapad | e9ae77d | 2022-12-12 17:02:00 | [diff] [blame] | 132 | format: ['strictCamelCase'], |
dpapad | b7286e8 | 2022-06-16 01:33:27 | [diff] [blame] | 133 | modifiers: ['private'], |
dpapad | 684f427b | 2022-05-10 05:47:02 | [diff] [blame] | 134 | trailingUnderscore: 'allow', |
| 135 | }, |
| 136 | { |
dpapad | e9d1fa7 | 2022-06-09 17:42:50 | [diff] [blame] | 137 | selector: 'classProperty', |
| 138 | format: ['UPPER_CASE'], |
dpapad | 588bb91 | 2022-06-15 05:35:33 | [diff] [blame] | 139 | modifiers: ['private', 'static', 'readonly'], |
| 140 | }, |
| 141 | { |
| 142 | selector: 'classProperty', |
| 143 | format: ['UPPER_CASE'], |
| 144 | modifiers: ['public', 'static', 'readonly'], |
dpapad | e9d1fa7 | 2022-06-09 17:42:50 | [diff] [blame] | 145 | }, |
| 146 | { |
| 147 | selector: 'classProperty', |
| 148 | format: ['camelCase'], |
dpapad | 588bb91 | 2022-06-15 05:35:33 | [diff] [blame] | 149 | modifiers: ['public'], |
| 150 | }, |
| 151 | { |
| 152 | selector: 'classProperty', |
| 153 | format: ['camelCase'], |
| 154 | modifiers: ['private'], |
dpapad | e9d1fa7 | 2022-06-09 17:42:50 | [diff] [blame] | 155 | trailingUnderscore: 'allow', |
| 156 | }, |
| 157 | { |
dpapad | 684f427b | 2022-05-10 05:47:02 | [diff] [blame] | 158 | selector: 'parameter', |
| 159 | format: ['camelCase'], |
| 160 | leadingUnderscore: 'allow', |
| 161 | }, |
dpapad | b17f3beb | 2022-05-10 21:34:13 | [diff] [blame] | 162 | { |
| 163 | selector: 'function', |
| 164 | format: ['camelCase'], |
| 165 | }, |
dpapad | 50adcde | 2022-05-07 00:05:52 | [diff] [blame] | 166 | ], |
| 167 | |
dpapad | a2eca91 | 2022-03-28 09:36:44 | [diff] [blame] | 168 | '@typescript-eslint/member-delimiter-style': ['error', { |
| 169 | multiline: { |
| 170 | delimiter: 'comma', |
| 171 | requireLast: true, |
| 172 | }, |
| 173 | singleline: { |
| 174 | delimiter: 'comma', |
| 175 | requireLast: false, |
| 176 | }, |
| 177 | overrides: { |
| 178 | interface: { |
| 179 | multiline: { |
| 180 | delimiter: 'semi', |
| 181 | requireLast: true, |
| 182 | }, |
| 183 | singleline: { |
| 184 | delimiter: 'semi', |
| 185 | requireLast: false, |
| 186 | }, |
| 187 | }, |
| 188 | }, |
dpapad | b5aaf1a | 2022-07-11 18:00:41 | [diff] [blame] | 189 | }], |
| 190 | |
| 191 | // https://google.github.io/styleguide/tsguide.html#wrapper-types |
| 192 | '@typescript-eslint/ban-types': ['error', { |
| 193 | extendDefaults: false, |
| 194 | types: { |
| 195 | String: { |
| 196 | message: 'Use string instead', |
| 197 | fixWith: 'string', |
| 198 | }, |
| 199 | Boolean: { |
| 200 | message: 'Use boolean instead', |
| 201 | fixWith: 'boolean', |
| 202 | }, |
| 203 | Number: { |
| 204 | message: 'Use number instead', |
| 205 | fixWith: 'number', |
| 206 | }, |
| 207 | Symbol: { |
| 208 | message: 'Use symbol instead', |
| 209 | fixWith: 'symbol', |
| 210 | }, |
| 211 | BigInt: { |
| 212 | message: 'Use bigint instead', |
| 213 | fixWith: 'bigint', |
| 214 | }, |
| 215 | } |
| 216 | }], |
dpapad | fa76653e | 2022-02-24 09:08:40 | [diff] [blame] | 217 | } |
dpapad | ac97d7b6 | 2021-06-14 07:20:26 | [diff] [blame] | 218 | }] |
dpapad | ff82d51 | 2017-05-25 18:40:15 | [diff] [blame] | 219 | }; |