|
| 1 | +// @ts-check |
| 2 | +import * as path from 'node:path' |
| 3 | +import { fileURLToPath } from 'node:url' |
| 4 | +import { includeIgnoreFile } from '@eslint/compat' |
| 5 | +import eslint from '@eslint/js' |
| 6 | +import node from 'eslint-plugin-n' |
| 7 | +import prettier from 'eslint-config-prettier' |
| 8 | +import tseslint from 'typescript-eslint' |
| 9 | +import vitest from '@vitest/eslint-plugin' |
| 10 | + |
| 11 | +import temporarySuppressions from './eslint_temporary_suppressions.js' |
| 12 | + |
| 13 | +const __filename = fileURLToPath(import.meta.url) |
| 14 | +const __dirname = path.dirname(__filename) |
| 15 | + |
| 16 | +export default tseslint.config( |
| 17 | + // Global rules and configuration |
| 18 | + includeIgnoreFile(path.resolve(__dirname, '.gitignore')), |
| 19 | + { |
| 20 | + linterOptions: { |
| 21 | + reportUnusedDisableDirectives: true, |
| 22 | + }, |
| 23 | + }, |
| 24 | + |
| 25 | + // JavaScript-specific rules |
| 26 | + eslint.configs.recommended, |
| 27 | + |
| 28 | + // Typescript-specific rules |
| 29 | + tseslint.configs.strictTypeChecked, |
| 30 | + tseslint.configs.stylisticTypeChecked, |
| 31 | + { |
| 32 | + languageOptions: { |
| 33 | + parserOptions: { |
| 34 | + project: ['./tsconfig.base.json', './packages/*/tsconfig.json'], |
| 35 | + tsconfigRootDir: __dirname, |
| 36 | + }, |
| 37 | + }, |
| 38 | + }, |
| 39 | + |
| 40 | + { |
| 41 | + files: ['**/*.?(c|m)js?(x)'], |
| 42 | + ...tseslint.configs.disableTypeChecked, |
| 43 | + }, |
| 44 | + node.configs['flat/recommended'], |
| 45 | + { |
| 46 | + rules: { |
| 47 | + 'n/no-extraneous-import': 'off', |
| 48 | + 'n/no-extraneous-require': 'off', |
| 49 | + 'n/no-missing-import': 'off', |
| 50 | + 'n/no-missing-require': 'off', |
| 51 | + 'n/no-unpublished-import': 'off', |
| 52 | + 'n/no-unpublished-require': 'off', |
| 53 | + }, |
| 54 | + }, |
| 55 | + |
| 56 | + // Project-specific rules |
| 57 | + { |
| 58 | + files: ['**/*.?(c|m)ts?(x)'], |
| 59 | + rules: { |
| 60 | + // `interface` and `type` have different use cases, allow both |
| 61 | + '@typescript-eslint/consistent-type-definitions': 'off', |
| 62 | + |
| 63 | + // Ignore underscore-prefixed unused variables (mirrors tsc behavior) |
| 64 | + '@typescript-eslint/no-unused-vars': [ |
| 65 | + 'error', |
| 66 | + { |
| 67 | + args: 'all', |
| 68 | + argsIgnorePattern: '^_', |
| 69 | + caughtErrors: 'all', |
| 70 | + caughtErrorsIgnorePattern: '^_', |
| 71 | + destructuredArrayIgnorePattern: '^_', |
| 72 | + ignoreRestSiblings: true, |
| 73 | + varsIgnorePattern: '^_', |
| 74 | + }, |
| 75 | + ], |
| 76 | + }, |
| 77 | + }, |
| 78 | + |
| 79 | + // Tests |
| 80 | + { |
| 81 | + files: ['**/*.test.?(c|m)[jt]s?(x)'], |
| 82 | + plugins: { vitest }, |
| 83 | + rules: { |
| 84 | + ...vitest.configs.recommended.rules, |
| 85 | + |
| 86 | + 'vitest/expect-expect': [ |
| 87 | + 'error', |
| 88 | + { |
| 89 | + assertFunctionNames: [ |
| 90 | + // Defaults |
| 91 | + 'assert', |
| 92 | + 'expect', |
| 93 | + |
| 94 | + // Fix issue where text-context-specific `expect()` calls trigger false positive |
| 95 | + 't.expect', |
| 96 | + 'ctx.expect', |
| 97 | + 'context.expect', |
| 98 | + |
| 99 | + // Custom assertion functions |
| 100 | + 'assertNetlifyToml', |
| 101 | + ], |
| 102 | + }, |
| 103 | + ], |
| 104 | + }, |
| 105 | + }, |
| 106 | + |
| 107 | + ...temporarySuppressions, |
| 108 | + |
| 109 | + // Must be last |
| 110 | + prettier, |
| 111 | +) |
0 commit comments