|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2024 Google LLC |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +import eslint from '@eslint/js'; |
| 8 | +import noOnlyTests from 'eslint-plugin-no-only-tests'; |
| 9 | +import tseslint from 'typescript-eslint'; |
| 10 | + |
| 11 | +/** |
| 12 | + * We want to be able to lint non-TypeScript files. If we don't guard our |
| 13 | + * TypeScript rules with a "files" constraint, eslint will try to lint all files |
| 14 | + * using the TypeScript parser, which will fail for projects outside a |
| 15 | + * TypeScript project. Maybe there is a simpler way to do this? |
| 16 | + */ |
| 17 | +const onlyTypeScriptFiles = (configs) => |
| 18 | + configs.map((config) => ({files: ['**/*.ts'], ...config})); |
| 19 | + |
| 20 | +export default [ |
| 21 | + { |
| 22 | + // List all visible files: |
| 23 | + // npx eslint --debug 2>&1 | grep "eslint:eslint Lint" | cut -f 4- -d" " | sort |
| 24 | + ignores: [ |
| 25 | + '**/.wireit/', |
| 26 | + '**/node_modules/', |
| 27 | + 'lib/', |
| 28 | + 'vscode-extension/.vscode-test/', |
| 29 | + 'vscode-extension/lib/', |
| 30 | + 'vscode-extension/built/', |
| 31 | + ], |
| 32 | + }, |
| 33 | + eslint.configs.recommended, |
| 34 | + ...onlyTypeScriptFiles([ |
| 35 | + ...tseslint.configs.strictTypeChecked, |
| 36 | + { |
| 37 | + languageOptions: { |
| 38 | + parserOptions: { |
| 39 | + projectService: true, |
| 40 | + tsconfigRootDir: import.meta.dirname, |
| 41 | + }, |
| 42 | + }, |
| 43 | + plugins: { |
| 44 | + 'no-only-tests': noOnlyTests, |
| 45 | + }, |
| 46 | + rules: { |
| 47 | + 'no-only-tests/no-only-tests': 'error', |
| 48 | + '@typescript-eslint/no-unused-vars': [ |
| 49 | + 'error', |
| 50 | + {argsIgnorePattern: '^_', varsIgnorePattern: '^_'}, |
| 51 | + ], |
| 52 | + '@typescript-eslint/no-non-null-assertion': 'off', |
| 53 | + '@typescript-eslint/no-useless-constructor': 'off', |
| 54 | + '@typescript-eslint/only-throw-error': 'off', |
| 55 | + '@typescript-eslint/no-confusing-void-expression': 'off', |
| 56 | + '@typescript-eslint/restrict-template-expressions': 'off', |
| 57 | + '@typescript-eslint/no-unnecessary-condition': 'off', |
| 58 | + '@typescript-eslint/no-unnecessary-type-arguments': 'off', |
| 59 | + '@typescript-eslint/no-unnecessary-template-expression': 'off', |
| 60 | + '@typescript-eslint/use-unknown-in-catch-callback-variable': 'off', |
| 61 | + }, |
| 62 | + }, |
| 63 | + ]), |
| 64 | +]; |
0 commit comments