Nikolay Vitkov | de07efa | 2025-01-17 12:58:35 | [diff] [blame] | 1 | // Copyright 2025 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 | |
Nikolay Vitkov | 41c6911 | 2025-01-31 15:20:04 | [diff] [blame] | 5 | import stylisticPlugin from '@stylistic/eslint-plugin'; |
Nikolay Vitkov | a095148 | 2025-07-07 12:17:52 | [diff] [blame] | 6 | import { defineConfig, globalIgnores } from 'eslint/config'; |
Nikolay Vitkov | f1e3bd8 | 2025-02-13 11:55:22 | [diff] [blame] | 7 | import eslintPlugin from 'eslint-plugin-eslint-plugin'; |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 8 | import importPlugin from 'eslint-plugin-import'; |
| 9 | import jsdocPlugin from 'eslint-plugin-jsdoc'; |
Nikolay Vitkov | 41c6911 | 2025-01-31 15:20:04 | [diff] [blame] | 10 | import mochaPlugin from 'eslint-plugin-mocha'; |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 11 | import globals from 'globals'; |
Nikolay Vitkov | a095148 | 2025-07-07 12:17:52 | [diff] [blame] | 12 | import { join } from 'path'; |
Nikolay Vitkov | f1e99c0 | 2025-05-09 12:21:42 | [diff] [blame] | 13 | import typescriptEslint from 'typescript-eslint'; |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 14 | |
Nikolay Vitkov | c917875 | 2025-04-02 13:37:07 | [diff] [blame] | 15 | import rulesdirPlugin from './scripts/eslint_rules/rules-dir.mjs'; |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 16 | |
Nikolay Vitkov | 856215c | 2025-04-23 14:32:57 | [diff] [blame] | 17 | export default defineConfig([ |
| 18 | globalIgnores([ |
| 19 | // Git submodules that are not in third_party |
| 20 | 'build/', |
| 21 | 'buildtools/', |
Nikolay Vitkov | 5b2bcff | 2025-01-29 19:21:12 | [diff] [blame] | 22 | |
Nikolay Vitkov | 856215c | 2025-04-23 14:32:57 | [diff] [blame] | 23 | // Don't include the common build directory |
| 24 | 'out/', |
| 25 | // Don't include third party code |
| 26 | 'third_party/', |
Nikolay Vitkov | 4dc470b | 2025-02-20 12:44:32 | [diff] [blame] | 27 | |
Jack Franklin | 825d753 | 2025-07-03 08:43:24 | [diff] [blame] | 28 | 'front_end/diff/diff_match_patch.js', |
Nikolay Vitkov | 856215c | 2025-04-23 14:32:57 | [diff] [blame] | 29 | 'front_end/models/javascript_metadata/NativeFunctions.js', |
| 30 | // All of these scripts are auto-generated so don't lint them. |
| 31 | 'front_end/generated/ARIAProperties.js', |
| 32 | 'front_end/generated/Deprecation.ts', |
| 33 | 'front_end/generated/InspectorBackendCommands.js', |
| 34 | 'front_end/generated/protocol-mapping.d.ts', |
| 35 | 'front_end/generated/protocol-proxy-api.d.ts', |
| 36 | 'front_end/generated/protocol.ts', |
| 37 | // Any third_party addition has its source code checked out into |
| 38 | // third_party/X/package, so we ignore that code as it's not code we author or |
| 39 | // own. |
| 40 | 'front_end/third_party/*/package/', |
| 41 | // Any JS files are also not authored by devtools-frontend, so we ignore those. |
| 42 | 'front_end/third_party/**/*', |
| 43 | // Lighthouse doesn't have a package/ folder but has other nested folders, so |
| 44 | // we ignore any folders within the lighthouse directory. |
| 45 | 'front_end/third_party/lighthouse/*/', |
| 46 | // The CodeMirror bundle file is auto-generated and rolled-up as part of the', |
| 47 | // install script, so we don't need to lint it. |
| 48 | 'front_end/third_party/codemirror.next/bundle.ts', |
| 49 | // Lit lib files are auto-generated and rolled up as part of the install script. |
| 50 | 'front_end/third_party/lit/src/*.ts', |
| 51 | // @puppeteer/replay is auto-generated. |
| 52 | 'front_end/third_party/puppeteer-replay/**/*.ts', |
| 53 | // Third party code we did not author for extensions |
| 54 | 'extensions/cxx_debugging/third_party/**/*', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 55 | |
Nikolay Vitkov | 856215c | 2025-04-23 14:32:57 | [diff] [blame] | 56 | '**/node_modules', |
| 57 | 'scripts/build/typescript/tests', |
| 58 | 'scripts/migration/**/*.js', |
| 59 | 'scripts/protocol_typescript/*.js', |
| 60 | 'scripts/deps/tests/fixtures', |
| 61 | 'test/**/fixtures/', |
| 62 | 'test/e2e/**/*.js', |
| 63 | 'test/shared/**/*.js', |
| 64 | ]), |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 65 | { |
Nikolay Vitkov | b4e8dc7 | 2025-01-07 13:03:02 | [diff] [blame] | 66 | name: 'JavaScript files', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 67 | plugins: { |
Nikolay Vitkov | f1e99c0 | 2025-05-09 12:21:42 | [diff] [blame] | 68 | '@typescript-eslint': typescriptEslint.plugin, |
Nikolay Vitkov | b4e8dc7 | 2025-01-07 13:03:02 | [diff] [blame] | 69 | '@stylistic': stylisticPlugin, |
Nikolay Vitkov | f1e3bd8 | 2025-02-13 11:55:22 | [diff] [blame] | 70 | '@eslint-plugin': eslintPlugin, |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 71 | mocha: mochaPlugin, |
| 72 | rulesdir: rulesdirPlugin, |
| 73 | import: importPlugin, |
| 74 | jsdoc: jsdocPlugin, |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 75 | }, |
| 76 | |
| 77 | languageOptions: { |
Nikolay Vitkov | b4e8dc7 | 2025-01-07 13:03:02 | [diff] [blame] | 78 | ecmaVersion: 'latest', |
| 79 | sourceType: 'module', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 80 | globals: { |
| 81 | ...globals.browser, |
| 82 | }, |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 83 | }, |
| 84 | |
Nikolay Vitkov | 5b2bcff | 2025-01-29 19:21:12 | [diff] [blame] | 85 | linterOptions: { |
| 86 | reportUnusedDisableDirectives: 'error', |
| 87 | }, |
| 88 | |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 89 | rules: { |
| 90 | // syntax preferences |
Nikolay Vitkov | b4e8dc7 | 2025-01-07 13:03:02 | [diff] [blame] | 91 | '@stylistic/quotes': [ |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 92 | 'error', |
| 93 | 'single', |
| 94 | { |
| 95 | avoidEscape: true, |
| 96 | allowTemplateLiterals: false, |
| 97 | }, |
| 98 | ], |
| 99 | |
Nikolay Vitkov | b4e8dc7 | 2025-01-07 13:03:02 | [diff] [blame] | 100 | '@stylistic/semi': 'error', |
| 101 | '@stylistic/no-extra-semi': 'error', |
| 102 | '@stylistic/comma-style': ['error', 'last'], |
| 103 | '@stylistic/wrap-iife': ['error', 'inside'], |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 104 | |
Nikolay Vitkov | b4e8dc7 | 2025-01-07 13:03:02 | [diff] [blame] | 105 | '@stylistic/spaced-comment': [ |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 106 | 'error', |
| 107 | 'always', |
| 108 | { |
| 109 | markers: ['*'], |
| 110 | }, |
| 111 | ], |
| 112 | |
| 113 | eqeqeq: 'error', |
| 114 | |
| 115 | 'accessor-pairs': [ |
| 116 | 'error', |
| 117 | { |
| 118 | getWithoutSet: false, |
| 119 | setWithoutGet: false, |
| 120 | }, |
| 121 | ], |
| 122 | |
| 123 | curly: 'error', |
Nikolay Vitkov | b4e8dc7 | 2025-01-07 13:03:02 | [diff] [blame] | 124 | '@stylistic/new-parens': 'error', |
| 125 | '@stylistic/func-call-spacing': 'error', |
| 126 | '@stylistic/arrow-parens': ['error', 'as-needed'], |
| 127 | '@stylistic/eol-last': 'error', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 128 | 'object-shorthand': ['error', 'properties'], |
| 129 | 'no-useless-rename': 'error', |
| 130 | |
| 131 | // anti-patterns |
| 132 | 'no-caller': 'error', |
| 133 | 'no-case-declarations': 'error', |
| 134 | 'no-cond-assign': 'error', |
| 135 | |
| 136 | 'no-console': [ |
| 137 | 'error', |
| 138 | { |
| 139 | allow: [ |
| 140 | 'assert', |
| 141 | 'context', |
| 142 | 'error', |
| 143 | 'timeStamp', |
| 144 | 'time', |
| 145 | 'timeEnd', |
| 146 | 'warn', |
| 147 | ], |
| 148 | }, |
| 149 | ], |
| 150 | |
| 151 | 'no-debugger': 'error', |
| 152 | 'no-dupe-keys': 'error', |
| 153 | 'no-duplicate-case': 'error', |
| 154 | |
| 155 | 'no-else-return': [ |
| 156 | 'error', |
| 157 | { |
| 158 | allowElseIf: false, |
| 159 | }, |
| 160 | ], |
| 161 | |
Nikolay Vitkov | d1ebd9e | 2025-02-26 10:19:45 | [diff] [blame] | 162 | 'no-empty': [ |
| 163 | 'error', |
| 164 | { |
| 165 | allowEmptyCatch: true, |
| 166 | }, |
| 167 | ], |
| 168 | 'no-lonely-if': 'error', |
| 169 | |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 170 | 'no-empty-character-class': 'error', |
| 171 | 'no-global-assign': 'error', |
| 172 | 'no-implied-eval': 'error', |
| 173 | 'no-labels': 'error', |
| 174 | 'no-multi-str': 'error', |
Nikolay Vitkov | b4e8dc7 | 2025-01-07 13:03:02 | [diff] [blame] | 175 | 'no-object-constructor': 'error', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 176 | 'no-octal-escape': 'error', |
| 177 | 'no-self-compare': 'error', |
| 178 | 'no-shadow-restricted-names': 'error', |
| 179 | 'no-unreachable': 'error', |
| 180 | 'no-unsafe-negation': 'error', |
| 181 | |
| 182 | 'no-unused-vars': [ |
| 183 | 'error', |
| 184 | { |
| 185 | args: 'none', |
| 186 | vars: 'local', |
| 187 | }, |
| 188 | ], |
| 189 | |
| 190 | 'no-var': 'error', |
| 191 | 'no-with': 'error', |
| 192 | 'prefer-const': 'error', |
| 193 | radix: 'error', |
| 194 | 'valid-typeof': 'error', |
| 195 | 'no-return-assign': ['error', 'always'], |
Nikolay Vitkov | a095148 | 2025-07-07 12:17:52 | [diff] [blame] | 196 | 'no-implicit-coercion': ['error', { allow: ['!!'] }], |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 197 | |
Nikolay Vitkov | c32e3bb | 2025-03-10 10:56:34 | [diff] [blame] | 198 | 'no-array-constructor': 'error', |
| 199 | |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 200 | // es2015 features |
| 201 | 'require-yield': 'error', |
Nikolay Vitkov | b4e8dc7 | 2025-01-07 13:03:02 | [diff] [blame] | 202 | '@stylistic/template-curly-spacing': ['error', 'never'], |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 203 | |
| 204 | // file whitespace |
Nikolay Vitkov | b4e8dc7 | 2025-01-07 13:03:02 | [diff] [blame] | 205 | '@stylistic/no-multiple-empty-lines': [ |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 206 | 'error', |
| 207 | { |
| 208 | max: 1, |
| 209 | }, |
| 210 | ], |
Nikolay Vitkov | b4e8dc7 | 2025-01-07 13:03:02 | [diff] [blame] | 211 | '@stylistic/no-mixed-spaces-and-tabs': 'error', |
| 212 | '@stylistic/no-trailing-spaces': 'error', |
| 213 | '@stylistic/linebreak-style': ['error', 'unix'], |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 214 | |
| 215 | /** |
| 216 | * Disabled, aspirational rules |
| 217 | */ |
Nikolay Vitkov | b4e8dc7 | 2025-01-07 13:03:02 | [diff] [blame] | 218 | '@stylistic/indent': [ |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 219 | 'off', |
| 220 | 2, |
| 221 | { |
| 222 | SwitchCase: 1, |
| 223 | CallExpression: { |
| 224 | arguments: 2, |
| 225 | }, |
| 226 | MemberExpression: 2, |
| 227 | }, |
| 228 | ], |
| 229 | |
| 230 | // brace-style is disabled, as eslint cannot enforce 1tbs as default, but allman for functions |
Nikolay Vitkov | b4e8dc7 | 2025-01-07 13:03:02 | [diff] [blame] | 231 | '@stylistic/brace-style': [ |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 232 | 'off', |
| 233 | 'allman', |
| 234 | { |
| 235 | allowSingleLine: true, |
| 236 | }, |
| 237 | ], |
| 238 | |
| 239 | // key-spacing is disabled, as some objects use value-aligned spacing, some not. |
Nikolay Vitkov | b4e8dc7 | 2025-01-07 13:03:02 | [diff] [blame] | 240 | '@stylistic/key-spacing': [ |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 241 | 'off', |
| 242 | { |
| 243 | beforeColon: false, |
| 244 | afterColon: true, |
| 245 | align: 'value', |
| 246 | }, |
| 247 | ], |
| 248 | |
Nikolay Vitkov | b4e8dc7 | 2025-01-07 13:03:02 | [diff] [blame] | 249 | '@stylistic/quote-props': ['error', 'as-needed'], |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 250 | |
| 251 | // no-implicit-globals will prevent accidental globals |
| 252 | 'no-implicit-globals': 'off', |
| 253 | 'no-unused-private-class-members': 'error', |
Nikolay Vitkov | a3e7ae1 | 2025-05-26 17:43:51 | [diff] [blame] | 254 | 'no-useless-constructor': 'error', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 255 | |
Benedikt Meurer | 00c3958 | 2025-01-31 09:26:27 | [diff] [blame] | 256 | // Sort imports first |
| 257 | 'import/first': 'error', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 258 | // Closure does not properly typecheck default exports |
| 259 | 'import/no-default-export': 'error', |
| 260 | /** |
| 261 | * Catch duplicate import paths. For example this would catch the following example: |
| 262 | * import {Foo} from './foo.js' |
| 263 | * import * as FooModule from './foo.js' |
| 264 | **/ |
| 265 | 'import/no-duplicates': 'error', |
Nikolay Vitkov | 41c6911 | 2025-01-31 15:20:04 | [diff] [blame] | 266 | /** |
| 267 | * Provides more consistency in the imports. |
| 268 | */ |
| 269 | 'import/order': [ |
| 270 | 'error', |
| 271 | { |
| 272 | // We need to group the builtin and external as clang-format |
| 273 | // can't differentiate the two |
| 274 | groups: [['builtin', 'external'], 'parent', 'sibling', 'index'], |
| 275 | 'newlines-between': 'always', |
| 276 | // clang-format has it's own logic overriding this |
| 277 | named: false, |
| 278 | alphabetize: { |
| 279 | order: 'asc', |
| 280 | caseInsensitive: true, |
| 281 | }, |
| 282 | }, |
| 283 | ], |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 284 | // Try to spot '// console.log()' left over from debugging |
| 285 | 'rulesdir/no-commented-out-console': 'error', |
| 286 | // Prevent imports being commented out rather than deleted. |
| 287 | 'rulesdir/no-commented-out-import': 'error', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 288 | 'rulesdir/check-license-header': 'error', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 289 | /** |
| 290 | * Ensures that JS Doc comments are properly aligned - all the starting |
| 291 | * `*` are in the right place. |
| 292 | */ |
| 293 | 'jsdoc/check-alignment': 'error', |
| 294 | }, |
| 295 | }, |
| 296 | { |
| 297 | name: 'TypeScript files', |
| 298 | files: ['**/*.ts'], |
| 299 | |
| 300 | languageOptions: { |
| 301 | ecmaVersion: 'latest', |
| 302 | sourceType: 'module', |
| 303 | |
Nikolay Vitkov | f1e99c0 | 2025-05-09 12:21:42 | [diff] [blame] | 304 | parser: typescriptEslint.parser, |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 305 | parserOptions: { |
| 306 | allowAutomaticSingleRunInference: true, |
| 307 | project: join( |
Nikolay Vitkov | a095148 | 2025-07-07 12:17:52 | [diff] [blame] | 308 | import.meta.dirname, |
| 309 | 'config', |
| 310 | 'typescript', |
| 311 | 'tsconfig.eslint.json', |
| 312 | ), |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 313 | }, |
| 314 | }, |
| 315 | |
| 316 | rules: { |
Benedikt Meurer | 84b0fcc | 2025-02-12 13:57:23 | [diff] [blame] | 317 | '@typescript-eslint/array-type': [ |
| 318 | 'error', |
| 319 | { |
| 320 | default: 'array-simple', |
| 321 | }, |
| 322 | ], |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 323 | '@typescript-eslint/no-explicit-any': [ |
| 324 | 'error', |
| 325 | { |
| 326 | ignoreRestArgs: true, |
| 327 | }, |
| 328 | ], |
| 329 | |
| 330 | '@typescript-eslint/explicit-member-accessibility': [ |
| 331 | 'error', |
| 332 | { |
| 333 | accessibility: 'no-public', |
| 334 | }, |
| 335 | ], |
| 336 | |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 337 | // run just the TypeScript unused-vars rule, else we get duplicate errors |
| 338 | 'no-unused-vars': 'off', |
| 339 | '@typescript-eslint/no-unused-vars': [ |
| 340 | 'error', |
| 341 | { |
| 342 | argsIgnorePattern: '^_', |
| 343 | }, |
| 344 | ], |
| 345 | |
Nikolay Vitkov | b4e8dc7 | 2025-01-07 13:03:02 | [diff] [blame] | 346 | '@stylistic/member-delimiter-style': [ |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 347 | 'error', |
| 348 | { |
| 349 | multiline: { |
| 350 | delimiter: 'semi', |
| 351 | requireLast: true, |
| 352 | }, |
| 353 | |
| 354 | singleline: { |
| 355 | delimiter: 'comma', |
| 356 | requireLast: false, |
| 357 | }, |
| 358 | |
| 359 | overrides: { |
| 360 | interface: { |
| 361 | singleline: { |
| 362 | delimiter: 'semi', |
| 363 | requireLast: false, |
| 364 | }, |
| 365 | |
| 366 | multiline: { |
| 367 | delimiter: 'semi', |
| 368 | requireLast: true, |
| 369 | }, |
| 370 | }, |
| 371 | |
| 372 | typeLiteral: { |
| 373 | singleline: { |
| 374 | delimiter: 'comma', |
| 375 | requireLast: false, |
| 376 | }, |
| 377 | |
| 378 | multiline: { |
| 379 | delimiter: 'comma', |
| 380 | requireLast: true, |
| 381 | }, |
| 382 | }, |
| 383 | }, |
| 384 | }, |
| 385 | ], |
| 386 | |
| 387 | '@typescript-eslint/no-floating-promises': [ |
| 388 | 'error', |
| 389 | { |
| 390 | ignoreVoid: true, |
| 391 | }, |
| 392 | ], |
| 393 | |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 394 | /** |
| 395 | * Enforce that enum members are explicitly defined: |
| 396 | * const enum Foo { A = 'a' } rather than const enum Foo { A } |
| 397 | */ |
| 398 | '@typescript-eslint/prefer-enum-initializers': 'error', |
| 399 | /** |
| 400 | * Ban non-null assertion operator, e.g.: |
| 401 | * this.foo!.toLowerCase() |
| 402 | */ |
| 403 | '@typescript-eslint/no-non-null-assertion': 'error', |
| 404 | '@typescript-eslint/consistent-type-imports': 'error', |
| 405 | |
| 406 | '@typescript-eslint/naming-convention': [ |
| 407 | 'error', |
Nikolay Vitkov | 52a1797 | 2025-01-15 12:52:10 | [diff] [blame] | 408 | // Forbids interfaces starting with an I prefix. |
| 409 | { |
| 410 | selector: 'interface', |
| 411 | format: ['PascalCase'], |
| 412 | |
| 413 | custom: { |
| 414 | regex: '^I[A-Z]', |
| 415 | match: false, |
| 416 | }, |
| 417 | }, |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 418 | { |
| 419 | selector: [ |
| 420 | 'function', |
| 421 | 'accessor', |
| 422 | 'method', |
| 423 | 'property', |
| 424 | 'parameterProperty', |
| 425 | ], |
| 426 | format: ['camelCase'], |
| 427 | }, |
| 428 | { |
| 429 | selector: 'variable', |
| 430 | |
| 431 | filter: { |
| 432 | // Ignore localization variables. |
| 433 | regex: '^(UIStrings|str_)$', |
| 434 | match: false, |
| 435 | }, |
| 436 | |
| 437 | format: ['camelCase'], |
| 438 | }, |
| 439 | { |
| 440 | // We are using camelCase, PascalCase and UPPER_CASE for top-level constants, allow the for now. |
| 441 | selector: 'variable', |
| 442 | modifiers: ['const'], |
| 443 | filter: { |
| 444 | // Ignore localization variables. |
| 445 | regex: '^(UIStrings|str_)$', |
| 446 | match: false, |
| 447 | }, |
| 448 | |
| 449 | format: ['camelCase', 'UPPER_CASE', 'PascalCase'], |
| 450 | }, |
| 451 | { |
| 452 | selector: 'classProperty', |
| 453 | modifiers: ['static', 'readonly'], |
| 454 | format: ['UPPER_CASE', 'camelCase'], |
| 455 | }, |
| 456 | { |
| 457 | selector: 'enumMember', |
| 458 | format: ['UPPER_CASE'], |
| 459 | }, |
| 460 | { |
| 461 | selector: ['typeLike'], |
| 462 | format: ['PascalCase'], |
| 463 | }, |
| 464 | { |
| 465 | selector: 'parameter', |
| 466 | format: ['camelCase'], |
| 467 | leadingUnderscore: 'allow', |
| 468 | }, |
| 469 | { |
| 470 | // Public methods are currently in transition and may still have leading underscores. |
| 471 | selector: 'method', |
| 472 | modifiers: ['public'], |
| 473 | format: ['camelCase'], |
| 474 | leadingUnderscore: 'allow', |
| 475 | }, |
| 476 | { |
| 477 | selector: 'property', |
| 478 | modifiers: ['public'], |
| 479 | format: ['camelCase'], |
| 480 | leadingUnderscore: 'allow', |
| 481 | }, |
| 482 | { |
| 483 | // Object literals may be constructed as arguments to external libraries which follow different styles. |
| 484 | selector: ['objectLiteralMethod', 'objectLiteralProperty'], |
| 485 | modifiers: ['public'], |
| 486 | format: null, |
| 487 | }, |
| 488 | { |
| 489 | // Ignore type properties that require quotes |
| 490 | selector: 'typeProperty', |
| 491 | format: null, |
| 492 | modifiers: ['requiresQuotes'], |
| 493 | }, |
| 494 | ], |
| 495 | |
Nikolay Vitkov | 44e3006 | 2025-01-07 14:33:04 | [diff] [blame] | 496 | '@typescript-eslint/consistent-type-definitions': ['error', 'interface'], |
| 497 | |
Nikolay Vitkov | 9306264 | 2025-02-18 09:49:30 | [diff] [blame] | 498 | // Disable eslint base rule |
| 499 | 'no-throw-literal': 'off', |
| 500 | '@typescript-eslint/only-throw-error': 'error', |
| 501 | |
Nikolay Vitkov | 65a5a91 | 2025-02-18 18:30:26 | [diff] [blame] | 502 | // Disabled this rule while investigating why it creates |
| 503 | // certain TypeScript compilation errors after fixes |
| 504 | '@typescript-eslint/no-unnecessary-type-assertion': 'off', |
| 505 | |
Nikolay Vitkov | d36860c | 2025-02-19 17:50:27 | [diff] [blame] | 506 | '@typescript-eslint/no-inferrable-types': 'error', |
| 507 | |
Nikolay Vitkov | d396b27 | 2025-02-19 08:37:28 | [diff] [blame] | 508 | '@typescript-eslint/consistent-generic-constructors': [ |
| 509 | 'error', |
| 510 | 'constructor', |
| 511 | ], |
| 512 | |
Nikolay Vitkov | d36860c | 2025-02-19 17:50:27 | [diff] [blame] | 513 | // This is more performant |
| 514 | // And should provide better stack trace when debugging |
| 515 | // see https://v8.dev/blog/fast-async. |
| 516 | '@typescript-eslint/return-await': ['error', 'always'], |
| 517 | |
| 518 | '@typescript-eslint/ban-ts-comment': [ |
| 519 | 'error', |
| 520 | { |
| 521 | // Change after we add some placeholder for old errors |
| 522 | minimumDescriptionLength: 0, |
| 523 | 'ts-check': false, |
| 524 | 'ts-expect-error': 'allow-with-description', |
| 525 | 'ts-ignore': true, |
| 526 | 'ts-nocheck': true, |
| 527 | }, |
| 528 | ], |
| 529 | |
Nikolay Vitkov | 6814017 | 2025-02-20 19:25:39 | [diff] [blame] | 530 | '@typescript-eslint/prefer-optional-chain': 'error', |
| 531 | |
Nikolay Vitkov | b30f3b2 | 2025-03-04 13:38:33 | [diff] [blame] | 532 | '@typescript-eslint/no-unsafe-function-type': 'error', |
| 533 | |
Nikolay Vitkov | a2ced3f | 2025-03-05 11:58:03 | [diff] [blame] | 534 | '@typescript-eslint/no-empty-object-type': [ |
| 535 | 'error', |
| 536 | { |
| 537 | allowInterfaces: 'with-single-extends', |
| 538 | }, |
| 539 | ], |
| 540 | |
Nikolay Vitkov | c32e3bb | 2025-03-10 10:56:34 | [diff] [blame] | 541 | 'no-array-constructor': 'off', |
| 542 | '@typescript-eslint/no-array-constructor': 'error', |
| 543 | |
Nikolay Vitkov | 74a532c | 2025-05-16 10:55:58 | [diff] [blame] | 544 | '@typescript-eslint/consistent-indexed-object-style': 'error', |
| 545 | |
Nikolay Vitkov | a3e7ae1 | 2025-05-26 17:43:51 | [diff] [blame] | 546 | 'no-useless-constructor': 'off', |
| 547 | '@typescript-eslint/no-useless-constructor': 'error', |
| 548 | |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 549 | 'rulesdir/no-underscored-properties': 'error', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 550 | 'rulesdir/inline-type-imports': 'error', |
| 551 | |
| 552 | 'rulesdir/enforce-default-import-name': [ |
| 553 | 'error', |
| 554 | { |
| 555 | // Enforce that any import of models/trace/trace.js names the import Trace. |
| 556 | modulePath: join( |
Nikolay Vitkov | a095148 | 2025-07-07 12:17:52 | [diff] [blame] | 557 | import.meta.dirname, |
| 558 | 'front_end', |
| 559 | 'models', |
| 560 | 'trace', |
| 561 | 'trace.js', |
| 562 | ), |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 563 | importName: 'Trace', |
| 564 | }, |
| 565 | ], |
Connor Clark | 4d3add7 | 2025-06-17 21:58:12 | [diff] [blame] | 566 | |
| 567 | 'rulesdir/validate-timing-types': 'error', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 568 | }, |
| 569 | }, |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 570 | { |
| 571 | name: 'Scripts files', |
| 572 | files: ['scripts/**/*'], |
| 573 | rules: { |
| 574 | 'no-console': 'off', |
Nikolay Vitkov | de07efa | 2025-01-17 12:58:35 | [diff] [blame] | 575 | 'rulesdir/es-modules-import': 'off', |
Nikolay Vitkov | 77ba8df | 2025-03-27 15:06:08 | [diff] [blame] | 576 | 'import/no-default-export': 'off', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 577 | }, |
| 578 | }, |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 579 | { |
| 580 | name: 'Front-end files', |
| 581 | files: ['front_end/**/*'], |
| 582 | rules: { |
| 583 | // L10n rules are only relevant in 'front_end'. |
| 584 | 'rulesdir/l10n-filename-matches': [ |
| 585 | 'error', |
| 586 | { |
| 587 | rootFrontendDirectory: join(import.meta.dirname, 'front_end'), |
| 588 | }, |
| 589 | ], |
| 590 | 'rulesdir/l10n-i18nString-call-only-with-uistrings': 'error', |
| 591 | 'rulesdir/l10n-no-i18nString-calls-module-instantiation': 'error', |
| 592 | 'rulesdir/l10n-no-locked-or-placeholder-only-phrase': 'error', |
| 593 | 'rulesdir/l10n-no-uistrings-export': 'error', |
| 594 | 'rulesdir/l10n-no-unused-message': 'error', |
| 595 | }, |
| 596 | }, |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 597 | { |
| 598 | name: 'Front-end TypeScript files', |
| 599 | files: ['front_end/**/*.ts'], |
| 600 | rules: { |
| 601 | '@typescript-eslint/explicit-function-return-type': [ |
| 602 | 'error', |
| 603 | { |
| 604 | allowExpressions: true, |
| 605 | allowConciseArrowFunctionExpressionsStartingWithVoid: true, |
| 606 | allowIIFEs: true, |
| 607 | }, |
| 608 | ], |
Danil Somsikov | d12440f | 2025-03-31 18:45:43 | [diff] [blame] | 609 | 'rulesdir/no-imperative-dom-api': 'error', |
Danil Somsikov | 9f442bb | 2025-04-02 09:58:27 | [diff] [blame] | 610 | 'rulesdir/no-lit-render-outside-of-view': 'error', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 611 | 'rulesdir/no-importing-images-from-src': 'error', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 612 | 'rulesdir/enforce-custom-event-names': 'error', |
| 613 | 'rulesdir/set-data-type-reference': 'error', |
| 614 | 'rulesdir/no-bound-component-methods': 'error', |
Benedikt Meurer | 07ad609 | 2025-04-24 15:28:53 | [diff] [blame] | 615 | 'rulesdir/no-adopted-style-sheets': 'error', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 616 | 'rulesdir/no-customized-builtin-elements': 'error', |
Kateryna Prokopenko | 0e68ea4 | 2025-05-30 09:46:26 | [diff] [blame] | 617 | 'rulesdir/no-deprecated-component-usages': 'error', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 618 | 'rulesdir/no-self-closing-custom-element-tagnames': 'error', |
Benedikt Meurer | 6e53408 | 2025-01-29 10:36:02 | [diff] [blame] | 619 | 'rulesdir/no-a-tags-in-lit': 'error', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 620 | 'rulesdir/check-css-import': 'error', |
| 621 | 'rulesdir/enforce-optional-properties-last': 'error', |
| 622 | 'rulesdir/check-enumerated-histograms': 'error', |
| 623 | 'rulesdir/check-was-shown-methods': 'error', |
| 624 | 'rulesdir/static-custom-event-names': 'error', |
Benedikt Meurer | 6e53408 | 2025-01-29 10:36:02 | [diff] [blame] | 625 | 'rulesdir/lit-no-attribute-quotes': 'error', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 626 | 'rulesdir/lit-template-result-or-nothing': 'error', |
| 627 | 'rulesdir/inject-checkbox-styles': 'error', |
| 628 | 'rulesdir/jslog-context-list': 'error', |
Nikolay Vitkov | de07efa | 2025-01-17 12:58:35 | [diff] [blame] | 629 | 'rulesdir/es-modules-import': 'error', |
| 630 | 'rulesdir/html-tagged-template': 'error', |
Nikolay Vitkov | 49d12de | 2025-02-12 14:41:46 | [diff] [blame] | 631 | 'rulesdir/enforce-custom-element-definitions-location': [ |
| 632 | 'error', |
| 633 | { |
| 634 | rootFrontendDirectory: join(import.meta.dirname, 'front_end'), |
| 635 | }, |
| 636 | ], |
Ergun Erdogmus | 5efc7e9 | 2025-02-21 11:36:50 | [diff] [blame] | 637 | 'rulesdir/enforce-ui-strings-as-const': 'error', |
Nikolay Vitkov | a095148 | 2025-07-07 12:17:52 | [diff] [blame] | 638 | 'rulesdir/no-new-lit-element-components': 'error', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 639 | }, |
| 640 | }, |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 641 | { |
| 642 | name: 'Front-end meta files', |
| 643 | files: ['front_end/**/*-meta.ts'], |
| 644 | rules: { |
| 645 | '@typescript-eslint/naming-convention': [ |
| 646 | 'error', |
| 647 | { |
| 648 | selector: 'parameter', |
| 649 | format: ['camelCase', 'PascalCase'], |
| 650 | leadingUnderscore: 'allow', |
| 651 | }, |
| 652 | ], |
| 653 | }, |
| 654 | }, |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 655 | { |
| 656 | name: 'TypeScript test files', |
| 657 | files: [ |
| 658 | '*.test.ts', |
| 659 | // This makes the specificity greater than the front-end ts files |
| 660 | 'front_end/**/*.test.ts', |
| 661 | 'test/**/*.ts', |
| 662 | '**/testing/*.ts', |
Nikolay Vitkov | 856215c | 2025-04-23 14:32:57 | [diff] [blame] | 663 | 'scripts/eslint_rules/test/**/*', |
Nikolay Vitkov | 3cace8f | 2025-02-14 16:37:53 | [diff] [blame] | 664 | 'extensions/cxx_debugging/e2e/**', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 665 | ], |
| 666 | |
| 667 | rules: { |
| 668 | // errors on it('test') with no body |
| 669 | 'mocha/no-pending-tests': 'error', |
| 670 | |
| 671 | // errors on {describe, it}.only |
| 672 | 'mocha/no-exclusive-tests': 'error', |
| 673 | |
| 674 | 'mocha/no-async-describe': 'error', |
| 675 | 'mocha/no-global-tests': 'error', |
| 676 | 'mocha/no-nested-tests': 'error', |
| 677 | |
| 678 | '@typescript-eslint/no-non-null-assertion': 'off', |
| 679 | '@typescript-eslint/explicit-function-return-type': 'off', |
| 680 | |
Nikolay Vitkov | 9306264 | 2025-02-18 09:49:30 | [diff] [blame] | 681 | '@typescript-eslint/only-throw-error': [ |
| 682 | 'error', |
| 683 | { |
| 684 | allow: [ |
| 685 | { |
| 686 | // Chai AssertionError does not extend Error |
| 687 | from: 'package', |
| 688 | package: 'chai', |
| 689 | name: ['AssertionError'], |
| 690 | }, |
| 691 | ], |
| 692 | }, |
| 693 | ], |
| 694 | |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 695 | 'rulesdir/check-test-definitions': 'error', |
| 696 | 'rulesdir/no-assert-strict-equal-for-arrays-and-objects': 'error', |
| 697 | 'rulesdir/no-assert-deep-strict-equal': 'error', |
| 698 | 'rulesdir/no-assert-equal': 'error', |
| 699 | 'rulesdir/no-assert-equal-boolean-null-undefined': 'error', |
Danil Somsikov | d12440f | 2025-03-31 18:45:43 | [diff] [blame] | 700 | 'rulesdir/no-imperative-dom-api': 'off', |
Danil Somsikov | 9f442bb | 2025-04-02 09:58:27 | [diff] [blame] | 701 | 'rulesdir/no-lit-render-outside-of-view': 'off', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 702 | 'rulesdir/prefer-assert-instance-of': 'error', |
| 703 | 'rulesdir/prefer-assert-is-ok': 'error', |
| 704 | 'rulesdir/prefer-assert-length-of': 'error', |
Benedikt Meurer | ebef25a | 2025-04-11 12:28:21 | [diff] [blame] | 705 | 'rulesdir/prefer-assert-strict-equal': 'error', |
Benedikt Meurer | adbf0df | 2025-04-11 08:48:52 | [diff] [blame] | 706 | 'rulesdir/prefer-sinon-assert': 'error', |
Benedikt Meurer | 39e5133 | 2025-01-07 13:17:54 | [diff] [blame] | 707 | 'rulesdir/prefer-url-string': 'error', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 708 | 'rulesdir/trace-engine-test-timeouts': 'error', |
Jack Franklin | 2593106 | 2025-06-02 15:20:46 | [diff] [blame] | 709 | 'rulesdir/no-document-body-mutation': 'error', |
Nikolay Vitkov | 49d12de | 2025-02-12 14:41:46 | [diff] [blame] | 710 | 'rulesdir/enforce-custom-element-definitions-location': 'off', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 711 | }, |
| 712 | |
| 713 | settings: { |
| 714 | 'mocha/additionalCustomNames': [ |
| 715 | { |
| 716 | name: 'describeWithDevtoolsExtension', |
| 717 | type: 'suite', |
| 718 | interfaces: ['BDD', 'TDD'], |
| 719 | }, |
| 720 | { |
| 721 | name: 'describeWithEnvironment', |
| 722 | type: 'suite', |
| 723 | interfaces: ['BDD', 'TDD'], |
| 724 | }, |
| 725 | { |
| 726 | name: 'describeWithLocale', |
| 727 | type: 'suite', |
| 728 | interfaces: ['BDD', 'TDD'], |
| 729 | }, |
| 730 | { |
| 731 | name: 'describeWithMockConnection', |
| 732 | type: 'suite', |
| 733 | interfaces: ['BDD', 'TDD'], |
| 734 | }, |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 735 | ], |
| 736 | }, |
| 737 | }, |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 738 | { |
Nikolay Vitkov | 52a1797 | 2025-01-15 12:52:10 | [diff] [blame] | 739 | name: 'Use private class members rule', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 740 | files: [ |
| 741 | 'front_end/panels/**/components/*.ts', |
| 742 | 'front_end/ui/components/**/*.ts', |
| 743 | 'front_end/entrypoints/**/*.ts', |
| 744 | ], |
| 745 | |
| 746 | rules: { |
| 747 | 'rulesdir/prefer-private-class-members': 'error', |
| 748 | }, |
| 749 | }, |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 750 | { |
Nikolay Vitkov | 52a1797 | 2025-01-15 12:52:10 | [diff] [blame] | 751 | name: 'Ignore private class members rule', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 752 | files: [ |
| 753 | 'front_end/panels/recorder/**/*.ts', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 754 | 'front_end/ui/components/suggestion_input/*.ts', |
| 755 | ], |
| 756 | rules: { |
| 757 | // TODO(crbug/1402569): Reenable once https://github.com/microsoft/TypeScript/issues/48885 is closed. |
| 758 | 'rulesdir/prefer-private-class-members': 'off', |
| 759 | }, |
| 760 | }, |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 761 | { |
Nikolay Vitkov | 52a1797 | 2025-01-15 12:52:10 | [diff] [blame] | 762 | name: 'Supported CSS properties rules', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 763 | files: ['front_end/generated/SupportedCSSProperties.js'], |
| 764 | rules: { |
| 765 | 'rulesdir/jslog-context-list': 'error', |
| 766 | }, |
| 767 | }, |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 768 | { |
| 769 | name: 'EsLint rules test', |
Nikolay Vitkov | 856215c | 2025-04-23 14:32:57 | [diff] [blame] | 770 | files: ['scripts/eslint_rules/tests/**/*'], |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 771 | rules: { |
Nikolay Vitkov | f1e3bd8 | 2025-02-13 11:55:22 | [diff] [blame] | 772 | '@eslint-plugin/no-only-tests': 'error', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 773 | }, |
| 774 | }, |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 775 | { |
| 776 | name: 'Legacy test runner', |
| 777 | files: ['front_end/legacy_test_runner/**/*'], |
| 778 | rules: { |
| 779 | 'rulesdir/es-modules-import': 'off', |
| 780 | }, |
| 781 | }, |
| 782 | { |
Nikolay Vitkov | a095148 | 2025-07-07 12:17:52 | [diff] [blame] | 783 | name: 'Front-end component docs', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 784 | files: ['front_end/ui/components/docs/**/*.ts'], |
| 785 | rules: { |
| 786 | // This makes the component doc examples very verbose and doesn't add |
| 787 | // anything, so we leave return types to the developer within the |
| 788 | // component_docs folder. |
| 789 | '@typescript-eslint/explicit-function-return-type': 'off', |
Benedikt Meurer | 6e53408 | 2025-01-29 10:36:02 | [diff] [blame] | 790 | // We use Lit to help render examples sometimes and we don't use |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 791 | // {host: this} as often the `this` is the window. |
Benedikt Meurer | 6e53408 | 2025-01-29 10:36:02 | [diff] [blame] | 792 | 'rulesdir/lit-host-this': 'off', |
Danil Somsikov | d12440f | 2025-03-31 18:45:43 | [diff] [blame] | 793 | 'rulesdir/no-imperative-dom-api': 'off', |
Danil Somsikov | 9f442bb | 2025-04-02 09:58:27 | [diff] [blame] | 794 | 'rulesdir/no-lit-render-outside-of-view': 'off', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 795 | }, |
| 796 | }, |
| 797 | { |
Jack Franklin | 4870534 | 2025-06-17 11:59:57 | [diff] [blame] | 798 | name: 'No SDK in models/trace', |
| 799 | files: ['front_end/models/trace/**/*.ts'], |
| 800 | ignores: ['front_end/models/trace/**/*.test.ts'], |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 801 | rules: { |
| 802 | 'rulesdir/no-imports-in-directory': [ |
| 803 | 'error', |
| 804 | { |
Nikolay Vitkov | 19a227c | 2025-07-01 11:25:29 | [diff] [blame] | 805 | bannedImportPaths: [ |
| 806 | { |
| 807 | bannedPath: join( |
Nikolay Vitkov | a095148 | 2025-07-07 12:17:52 | [diff] [blame] | 808 | import.meta.dirname, |
| 809 | 'front_end', |
| 810 | 'core', |
| 811 | 'sdk', |
| 812 | 'sdk.js', |
| 813 | ), |
Nikolay Vitkov | 19a227c | 2025-07-01 11:25:29 | [diff] [blame] | 814 | allowTypeImports: true, |
| 815 | }, |
| 816 | ], |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 817 | }, |
| 818 | ], |
| 819 | }, |
| 820 | }, |
| 821 | { |
Nikolay Vitkov | 52a1797 | 2025-01-15 12:52:10 | [diff] [blame] | 822 | name: 'Recorder injected code', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 823 | files: ['front_end/panels/recorder/injected/**/*.ts'], |
| 824 | rules: { |
| 825 | // The code is rolled up and tree-shaken independently from the regular entrypoints. |
| 826 | 'rulesdir/es-modules-import': 'off', |
| 827 | }, |
| 828 | }, |
| 829 | { |
Nikolay Vitkov | b4e8dc7 | 2025-01-07 13:03:02 | [diff] [blame] | 830 | name: 'Performance panel file', |
Nikolay Vitkov | 55adf67 | 2025-01-02 12:07:33 | [diff] [blame] | 831 | files: ['front_end/ui/legacy/components/perf_ui/**/*.ts'], |
| 832 | rules: { |
| 833 | // Enable tracking of canvas save() and |
| 834 | // restore() calls to try and catch bugs. Only |
| 835 | // enabled in this folder because it is an |
| 836 | // expensive rule to run and we do not need it |
| 837 | // for any code that doesn't use Canvas. |
| 838 | 'rulesdir/canvas-context-tracking': 'error', |
| 839 | }, |
| 840 | }, |
Jack Franklin | c10b497 | 2025-02-28 16:32:56 | [diff] [blame] | 841 | { |
| 842 | name: 'TypeScript type-definitions', |
| 843 | files: ['**/*.d.ts'], |
| 844 | rules: { |
| 845 | // Not a useful rule for .d.ts files where we are |
| 846 | // representing an existing module. |
Nikolay Vitkov | a2ced3f | 2025-03-05 11:58:03 | [diff] [blame] | 847 | 'import/no-default-export': 'off', |
| 848 | }, |
| 849 | }, |
Nikolay Vitkov | afc8a8c | 2025-03-17 10:05:28 | [diff] [blame] | 850 | { |
| 851 | name: 'Config files', |
| 852 | files: ['eslint.config.mjs', '**/*/rollup.config.mjs'], |
| 853 | rules: { |
| 854 | // The config operate on the default export |
| 855 | // So allow it for them |
| 856 | 'import/no-default-export': 'off', |
| 857 | }, |
| 858 | }, |
Nikolay Vitkov | 856215c | 2025-04-23 14:32:57 | [diff] [blame] | 859 | ]); |