|
| 1 | +/** |
| 2 | + * ESLint Configuration for VS Code Python Extension |
| 3 | + * This file configures linting rules for the TypeScript/JavaScript codebase. |
| 4 | + * It uses the new flat config format introduced in ESLint 8.21.0 |
| 5 | + */ |
| 6 | + |
| 7 | +// Import essential ESLint plugins and configurations |
| 8 | +import tseslint from '@typescript-eslint/eslint-plugin'; |
| 9 | +import tsParser from '@typescript-eslint/parser'; |
| 10 | +import noOnlyTests from 'eslint-plugin-no-only-tests'; |
| 11 | +import prettier from 'eslint-config-prettier'; |
| 12 | +import importPlugin from 'eslint-plugin-import'; |
| 13 | +import js from '@eslint/js'; |
| 14 | + |
| 15 | +export default [ |
| 16 | + { |
| 17 | + ignores: ['**/node_modules/**', '**/out/**'], |
| 18 | + }, |
| 19 | + // Base configuration for all files |
| 20 | + { |
| 21 | + ignores: [ |
| 22 | + '**/node_modules/**', |
| 23 | + '**/out/**', |
| 24 | + 'src/test/analysisEngineTest.ts', |
| 25 | + 'src/test/ciConstants.ts', |
| 26 | + 'src/test/common.ts', |
| 27 | + 'src/test/constants.ts', |
| 28 | + 'src/test/core.ts', |
| 29 | + 'src/test/extension-version.functional.test.ts', |
| 30 | + 'src/test/fixtures.ts', |
| 31 | + 'src/test/index.ts', |
| 32 | + 'src/test/initialize.ts', |
| 33 | + 'src/test/mockClasses.ts', |
| 34 | + 'src/test/performanceTest.ts', |
| 35 | + 'src/test/proc.ts', |
| 36 | + 'src/test/smokeTest.ts', |
| 37 | + 'src/test/standardTest.ts', |
| 38 | + 'src/test/startupTelemetry.unit.test.ts', |
| 39 | + 'src/test/testBootstrap.ts', |
| 40 | + 'src/test/testLogger.ts', |
| 41 | + 'src/test/testRunner.ts', |
| 42 | + 'src/test/textUtils.ts', |
| 43 | + 'src/test/unittests.ts', |
| 44 | + 'src/test/vscode-mock.ts', |
| 45 | + 'src/test/interpreters/mocks.ts', |
| 46 | + 'src/test/interpreters/virtualEnvs/condaInheritEnvPrompt.unit.test.ts', |
| 47 | + 'src/test/interpreters/pythonPathUpdaterFactory.unit.test.ts', |
| 48 | + 'src/test/interpreters/activation/service.unit.test.ts', |
| 49 | + 'src/test/interpreters/helpers.unit.test.ts', |
| 50 | + 'src/test/interpreters/display.unit.test.ts', |
| 51 | + 'src/test/terminals/codeExecution/terminalCodeExec.unit.test.ts', |
| 52 | + 'src/test/terminals/codeExecution/codeExecutionManager.unit.test.ts', |
| 53 | + 'src/test/terminals/codeExecution/djangoShellCodeExect.unit.test.ts', |
| 54 | + 'src/test/activation/activeResource.unit.test.ts', |
| 55 | + 'src/test/activation/extensionSurvey.unit.test.ts', |
| 56 | + 'src/test/utils/fs.ts', |
| 57 | + 'src/test/api.functional.test.ts', |
| 58 | + 'src/test/testing/common/debugLauncher.unit.test.ts', |
| 59 | + 'src/test/testing/common/services/configSettingService.unit.test.ts', |
| 60 | + 'src/test/common/exitCIAfterTestReporter.ts', |
| 61 | + 'src/test/common/terminals/activator/index.unit.test.ts', |
| 62 | + 'src/test/common/terminals/activator/base.unit.test.ts', |
| 63 | + 'src/test/common/terminals/shellDetector.unit.test.ts', |
| 64 | + 'src/test/common/terminals/service.unit.test.ts', |
| 65 | + 'src/test/common/terminals/helper.unit.test.ts', |
| 66 | + 'src/test/common/terminals/activation.unit.test.ts', |
| 67 | + 'src/test/common/terminals/shellDetectors/shellDetectors.unit.test.ts', |
| 68 | + 'src/test/common/terminals/environmentActivationProviders/terminalActivation.testvirtualenvs.ts', |
| 69 | + 'src/test/common/socketStream.test.ts', |
| 70 | + 'src/test/common/configSettings.test.ts', |
| 71 | + 'src/test/common/experiments/telemetry.unit.test.ts', |
| 72 | + 'src/test/common/platform/filesystem.unit.test.ts', |
| 73 | + 'src/test/common/platform/errors.unit.test.ts', |
| 74 | + 'src/test/common/platform/utils.ts', |
| 75 | + 'src/test/common/platform/fs-temp.unit.test.ts', |
| 76 | + 'src/test/common/platform/fs-temp.functional.test.ts', |
| 77 | + 'src/test/common/platform/filesystem.functional.test.ts', |
| 78 | + 'src/test/common/platform/filesystem.test.ts', |
| 79 | + 'src/test/common/utils/cacheUtils.unit.test.ts', |
| 80 | + 'src/test/common/utils/decorators.unit.test.ts', |
| 81 | + 'src/test/common/utils/version.unit.test.ts', |
| 82 | + 'src/test/common/configSettings/configSettings.unit.test.ts', |
| 83 | + 'src/test/common/serviceRegistry.unit.test.ts', |
| 84 | + 'src/test/common/extensions.unit.test.ts', |
| 85 | + 'src/test/common/variables/envVarsService.unit.test.ts', |
| 86 | + 'src/test/common/helpers.test.ts', |
| 87 | + 'src/test/common/application/commands/reloadCommand.unit.test.ts', |
| 88 | + 'src/test/common/installer/channelManager.unit.test.ts', |
| 89 | + 'src/test/common/installer/pipInstaller.unit.test.ts', |
| 90 | + 'src/test/common/installer/pipEnvInstaller.unit.test.ts', |
| 91 | + 'src/test/common/socketCallbackHandler.test.ts', |
| 92 | + 'src/test/common/process/decoder.test.ts', |
| 93 | + 'src/test/common/process/processFactory.unit.test.ts', |
| 94 | + 'src/test/common/process/pythonToolService.unit.test.ts', |
| 95 | + 'src/test/common/process/proc.observable.test.ts', |
| 96 | + 'src/test/common/process/logger.unit.test.ts', |
| 97 | + 'src/test/common/process/proc.exec.test.ts', |
| 98 | + 'src/test/common/process/pythonProcess.unit.test.ts', |
| 99 | + 'src/test/common/process/proc.unit.test.ts', |
| 100 | + 'src/test/common/interpreterPathService.unit.test.ts', |
| 101 | + 'src/test/debugger/extension/adapter/adapter.test.ts', |
| 102 | + 'src/test/debugger/extension/adapter/outdatedDebuggerPrompt.unit.test.ts', |
| 103 | + 'src/test/debugger/extension/adapter/factory.unit.test.ts', |
| 104 | + 'src/test/debugger/extension/adapter/logging.unit.test.ts', |
| 105 | + 'src/test/debugger/extension/hooks/childProcessAttachHandler.unit.test.ts', |
| 106 | + 'src/test/debugger/extension/hooks/childProcessAttachService.unit.test.ts', |
| 107 | + 'src/test/debugger/utils.ts', |
| 108 | + 'src/test/debugger/envVars.test.ts', |
| 109 | + 'src/test/telemetry/index.unit.test.ts', |
| 110 | + 'src/test/telemetry/envFileTelemetry.unit.test.ts', |
| 111 | + 'src/test/application/diagnostics/checks/macPythonInterpreter.unit.test.ts', |
| 112 | + 'src/test/application/diagnostics/checks/pythonInterpreter.unit.test.ts', |
| 113 | + 'src/test/application/diagnostics/checks/powerShellActivation.unit.test.ts', |
| 114 | + 'src/test/application/diagnostics/checks/envPathVariable.unit.test.ts', |
| 115 | + 'src/test/application/diagnostics/applicationDiagnostics.unit.test.ts', |
| 116 | + 'src/test/application/diagnostics/promptHandler.unit.test.ts', |
| 117 | + 'src/test/application/diagnostics/commands/ignore.unit.test.ts', |
| 118 | + 'src/test/performance/load.perf.test.ts', |
| 119 | + 'src/client/interpreter/configuration/interpreterSelector/commands/base.ts', |
| 120 | + 'src/client/interpreter/configuration/interpreterSelector/commands/resetInterpreter.ts', |
| 121 | + 'src/client/interpreter/configuration/pythonPathUpdaterServiceFactory.ts', |
| 122 | + 'src/client/interpreter/configuration/services/globalUpdaterService.ts', |
| 123 | + 'src/client/interpreter/configuration/services/workspaceUpdaterService.ts', |
| 124 | + 'src/client/interpreter/configuration/services/workspaceFolderUpdaterService.ts', |
| 125 | + 'src/client/interpreter/helpers.ts', |
| 126 | + 'src/client/interpreter/virtualEnvs/condaInheritEnvPrompt.ts', |
| 127 | + 'src/client/interpreter/display/index.ts', |
| 128 | + 'src/client/extension.ts', |
| 129 | + 'src/client/startupTelemetry.ts', |
| 130 | + 'src/client/terminals/codeExecution/terminalCodeExecution.ts', |
| 131 | + 'src/client/terminals/codeExecution/codeExecutionManager.ts', |
| 132 | + 'src/client/terminals/codeExecution/djangoContext.ts', |
| 133 | + 'src/client/activation/commands.ts', |
| 134 | + 'src/client/activation/progress.ts', |
| 135 | + 'src/client/activation/extensionSurvey.ts', |
| 136 | + 'src/client/activation/common/analysisOptions.ts', |
| 137 | + 'src/client/activation/languageClientMiddleware.ts', |
| 138 | + 'src/client/testing/serviceRegistry.ts', |
| 139 | + 'src/client/testing/main.ts', |
| 140 | + 'src/client/testing/configurationFactory.ts', |
| 141 | + 'src/client/testing/common/constants.ts', |
| 142 | + 'src/client/testing/common/testUtils.ts', |
| 143 | + 'src/client/common/helpers.ts', |
| 144 | + 'src/client/common/net/browser.ts', |
| 145 | + 'src/client/common/net/socket/socketCallbackHandler.ts', |
| 146 | + 'src/client/common/net/socket/socketServer.ts', |
| 147 | + 'src/client/common/net/socket/SocketStream.ts', |
| 148 | + 'src/client/common/contextKey.ts', |
| 149 | + 'src/client/common/experiments/telemetry.ts', |
| 150 | + 'src/client/common/platform/serviceRegistry.ts', |
| 151 | + 'src/client/common/platform/errors.ts', |
| 152 | + 'src/client/common/platform/fs-temp.ts', |
| 153 | + 'src/client/common/platform/fs-paths.ts', |
| 154 | + 'src/client/common/platform/registry.ts', |
| 155 | + 'src/client/common/platform/pathUtils.ts', |
| 156 | + 'src/client/common/persistentState.ts', |
| 157 | + 'src/client/common/terminal/activator/base.ts', |
| 158 | + 'src/client/common/terminal/activator/powershellFailedHandler.ts', |
| 159 | + 'src/client/common/terminal/activator/index.ts', |
| 160 | + 'src/client/common/terminal/helper.ts', |
| 161 | + 'src/client/common/terminal/syncTerminalService.ts', |
| 162 | + 'src/client/common/terminal/factory.ts', |
| 163 | + 'src/client/common/terminal/commandPrompt.ts', |
| 164 | + 'src/client/common/terminal/service.ts', |
| 165 | + 'src/client/common/terminal/shellDetector.ts', |
| 166 | + 'src/client/common/terminal/shellDetectors/userEnvironmentShellDetector.ts', |
| 167 | + 'src/client/common/terminal/shellDetectors/vscEnvironmentShellDetector.ts', |
| 168 | + 'src/client/common/terminal/shellDetectors/terminalNameShellDetector.ts', |
| 169 | + 'src/client/common/terminal/shellDetectors/settingsShellDetector.ts', |
| 170 | + 'src/client/common/terminal/shellDetectors/baseShellDetector.ts', |
| 171 | + 'src/client/common/utils/decorators.ts', |
| 172 | + 'src/client/common/utils/enum.ts', |
| 173 | + 'src/client/common/utils/platform.ts', |
| 174 | + 'src/client/common/utils/stopWatch.ts', |
| 175 | + 'src/client/common/utils/random.ts', |
| 176 | + 'src/client/common/utils/sysTypes.ts', |
| 177 | + 'src/client/common/utils/misc.ts', |
| 178 | + 'src/client/common/utils/cacheUtils.ts', |
| 179 | + 'src/client/common/utils/workerPool.ts', |
| 180 | + 'src/client/common/extensions.ts', |
| 181 | + 'src/client/common/variables/serviceRegistry.ts', |
| 182 | + 'src/client/common/variables/environment.ts', |
| 183 | + 'src/client/common/variables/types.ts', |
| 184 | + 'src/client/common/variables/systemVariables.ts', |
| 185 | + 'src/client/common/cancellation.ts', |
| 186 | + 'src/client/common/interpreterPathService.ts', |
| 187 | + 'src/client/common/application/applicationShell.ts', |
| 188 | + 'src/client/common/application/languageService.ts', |
| 189 | + 'src/client/common/application/clipboard.ts', |
| 190 | + 'src/client/common/application/workspace.ts', |
| 191 | + 'src/client/common/application/debugSessionTelemetry.ts', |
| 192 | + 'src/client/common/application/documentManager.ts', |
| 193 | + 'src/client/common/application/debugService.ts', |
| 194 | + 'src/client/common/application/commands/reloadCommand.ts', |
| 195 | + 'src/client/common/application/terminalManager.ts', |
| 196 | + 'src/client/common/application/applicationEnvironment.ts', |
| 197 | + 'src/client/common/errors/errorUtils.ts', |
| 198 | + 'src/client/common/installer/serviceRegistry.ts', |
| 199 | + 'src/client/common/installer/channelManager.ts', |
| 200 | + 'src/client/common/installer/moduleInstaller.ts', |
| 201 | + 'src/client/common/installer/types.ts', |
| 202 | + 'src/client/common/installer/pipEnvInstaller.ts', |
| 203 | + 'src/client/common/installer/productService.ts', |
| 204 | + 'src/client/common/installer/pipInstaller.ts', |
| 205 | + 'src/client/common/installer/productPath.ts', |
| 206 | + 'src/client/common/process/currentProcess.ts', |
| 207 | + 'src/client/common/process/processFactory.ts', |
| 208 | + 'src/client/common/process/serviceRegistry.ts', |
| 209 | + 'src/client/common/process/pythonToolService.ts', |
| 210 | + 'src/client/common/process/internal/python.ts', |
| 211 | + 'src/client/common/process/internal/scripts/testing_tools.ts', |
| 212 | + 'src/client/common/process/types.ts', |
| 213 | + 'src/client/common/process/logger.ts', |
| 214 | + 'src/client/common/process/pythonProcess.ts', |
| 215 | + 'src/client/common/process/pythonEnvironment.ts', |
| 216 | + 'src/client/common/process/decoder.ts', |
| 217 | + 'src/client/debugger/extension/adapter/remoteLaunchers.ts', |
| 218 | + 'src/client/debugger/extension/adapter/outdatedDebuggerPrompt.ts', |
| 219 | + 'src/client/debugger/extension/adapter/factory.ts', |
| 220 | + 'src/client/debugger/extension/adapter/activator.ts', |
| 221 | + 'src/client/debugger/extension/adapter/logging.ts', |
| 222 | + 'src/client/debugger/extension/hooks/eventHandlerDispatcher.ts', |
| 223 | + 'src/client/debugger/extension/hooks/childProcessAttachService.ts', |
| 224 | + 'src/client/debugger/extension/attachQuickPick/wmicProcessParser.ts', |
| 225 | + 'src/client/debugger/extension/attachQuickPick/factory.ts', |
| 226 | + 'src/client/debugger/extension/attachQuickPick/psProcessParser.ts', |
| 227 | + 'src/client/debugger/extension/attachQuickPick/picker.ts', |
| 228 | + 'src/client/application/serviceRegistry.ts', |
| 229 | + 'src/client/application/diagnostics/base.ts', |
| 230 | + 'src/client/application/diagnostics/applicationDiagnostics.ts', |
| 231 | + 'src/client/application/diagnostics/filter.ts', |
| 232 | + 'src/client/application/diagnostics/promptHandler.ts', |
| 233 | + 'src/client/application/diagnostics/commands/base.ts', |
| 234 | + 'src/client/application/diagnostics/commands/ignore.ts', |
| 235 | + 'src/client/application/diagnostics/commands/factory.ts', |
| 236 | + 'src/client/application/diagnostics/commands/execVSCCommand.ts', |
| 237 | + 'src/client/application/diagnostics/commands/launchBrowser.ts', |
| 238 | + ], |
| 239 | + linterOptions: { |
| 240 | + reportUnusedDisableDirectives: 'off', |
| 241 | + }, |
| 242 | + rules: { |
| 243 | + ...js.configs.recommended.rules, |
| 244 | + 'no-undef': 'off', |
| 245 | + }, |
| 246 | + }, |
| 247 | + // TypeScript-specific configuration |
| 248 | + { |
| 249 | + files: ['**/*.ts', '**/*.tsx', '**/*.js', 'src', 'pythonExtensionApi/src'], |
| 250 | + languageOptions: { |
| 251 | + parser: tsParser, |
| 252 | + parserOptions: { |
| 253 | + ecmaVersion: 'latest', |
| 254 | + sourceType: 'module', |
| 255 | + }, |
| 256 | + globals: { |
| 257 | + ...(js.configs.recommended.languageOptions?.globals || {}), |
| 258 | + mocha: true, |
| 259 | + require: 'readonly', |
| 260 | + process: 'readonly', |
| 261 | + exports: 'readonly', |
| 262 | + module: 'readonly', |
| 263 | + __dirname: 'readonly', |
| 264 | + __filename: 'readonly', |
| 265 | + setTimeout: 'readonly', |
| 266 | + setInterval: 'readonly', |
| 267 | + clearTimeout: 'readonly', |
| 268 | + clearInterval: 'readonly', |
| 269 | + }, |
| 270 | + }, |
| 271 | + plugins: { |
| 272 | + '@typescript-eslint': tseslint, |
| 273 | + 'no-only-tests': noOnlyTests, |
| 274 | + import: importPlugin, |
| 275 | + prettier: prettier, |
| 276 | + }, |
| 277 | + settings: { |
| 278 | + 'import/resolver': { |
| 279 | + node: { |
| 280 | + extensions: ['.js', '.ts'], |
| 281 | + }, |
| 282 | + }, |
| 283 | + }, |
| 284 | + rules: { |
| 285 | + // Base configurations |
| 286 | + ...tseslint.configs.recommended.rules, |
| 287 | + ...prettier.rules, |
| 288 | + |
| 289 | + // TypeScript-specific rules |
| 290 | + '@typescript-eslint/ban-ts-comment': [ |
| 291 | + 'error', |
| 292 | + { |
| 293 | + 'ts-ignore': 'allow-with-description', |
| 294 | + }, |
| 295 | + ], |
| 296 | + '@typescript-eslint/ban-types': 'off', |
| 297 | + '@typescript-eslint/explicit-module-boundary-types': 'off', |
| 298 | + '@typescript-eslint/no-empty-interface': 'off', |
| 299 | + '@typescript-eslint/no-explicit-any': 'off', |
| 300 | + '@typescript-eslint/no-namespace': 'off', |
| 301 | + '@typescript-eslint/no-non-null-assertion': 'off', |
| 302 | + '@typescript-eslint/no-loss-of-precision': 'off', |
| 303 | + '@typescript-eslint/no-unused-vars': [ |
| 304 | + 'warn', |
| 305 | + { |
| 306 | + varsIgnorePattern: '^_', |
| 307 | + argsIgnorePattern: '^_', |
| 308 | + }, |
| 309 | + ], |
| 310 | + '@typescript-eslint/no-var-requires': 'off', |
| 311 | + '@typescript-eslint/no-use-before-define': [ |
| 312 | + 'error', |
| 313 | + { |
| 314 | + functions: false, |
| 315 | + }, |
| 316 | + ], |
| 317 | + |
| 318 | + // Import rules |
| 319 | + 'import/extensions': 'off', |
| 320 | + 'import/namespace': 'off', |
| 321 | + 'import/no-extraneous-dependencies': 'off', |
| 322 | + 'import/no-unresolved': 'off', |
| 323 | + 'import/prefer-default-export': 'off', |
| 324 | + |
| 325 | + // Testing rules |
| 326 | + 'no-only-tests/no-only-tests': [ |
| 327 | + 'error', |
| 328 | + { |
| 329 | + block: ['test', 'suite'], |
| 330 | + focus: ['only'], |
| 331 | + }, |
| 332 | + ], |
| 333 | + |
| 334 | + // Code style rules |
| 335 | + 'linebreak-style': 'off', |
| 336 | + 'no-bitwise': 'off', |
| 337 | + 'no-console': 'off', |
| 338 | + 'no-underscore-dangle': 'off', |
| 339 | + 'operator-assignment': 'off', |
| 340 | + 'func-names': 'off', |
| 341 | + |
| 342 | + // Error handling and control flow |
| 343 | + 'no-empty': ['error', { allowEmptyCatch: true }], |
| 344 | + 'no-async-promise-executor': 'off', |
| 345 | + 'no-await-in-loop': 'off', |
| 346 | + 'no-unreachable': 'off', |
| 347 | + 'no-void': 'off', |
| 348 | + |
| 349 | + // Duplicates and overrides (TypeScript handles these) |
| 350 | + 'no-dupe-class-members': 'off', |
| 351 | + 'no-redeclare': 'off', |
| 352 | + 'no-undef': 'off', |
| 353 | + |
| 354 | + // Miscellaneous rules |
| 355 | + 'no-control-regex': 'off', |
| 356 | + 'no-extend-native': 'off', |
| 357 | + 'no-inner-declarations': 'off', |
| 358 | + 'no-multi-str': 'off', |
| 359 | + 'no-param-reassign': 'off', |
| 360 | + 'no-prototype-builtins': 'off', |
| 361 | + 'no-empty-function': 'off', |
| 362 | + 'no-template-curly-in-string': 'off', |
| 363 | + 'no-useless-escape': 'off', |
| 364 | + 'no-extra-parentheses': 'off', |
| 365 | + 'no-extra-paren': 'off', |
| 366 | + '@typescript-eslint/no-extra-parens': 'off', |
| 367 | + strict: 'off', |
| 368 | + |
| 369 | + // Restricted syntax |
| 370 | + 'no-restricted-syntax': [ |
| 371 | + 'error', |
| 372 | + { |
| 373 | + selector: 'ForInStatement', |
| 374 | + message: |
| 375 | + 'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.', |
| 376 | + }, |
| 377 | + { |
| 378 | + selector: 'LabeledStatement', |
| 379 | + message: |
| 380 | + 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.', |
| 381 | + }, |
| 382 | + { |
| 383 | + selector: 'WithStatement', |
| 384 | + message: |
| 385 | + '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.', |
| 386 | + }, |
| 387 | + ], |
| 388 | + }, |
| 389 | + }, |
| 390 | +]; |
0 commit comments