|
| 1 | +// @ts-check |
| 2 | +import * as path from 'node:path' |
| 3 | +import { fileURLToPath } from 'node:url' |
| 4 | +import eslint from '@eslint/js' |
| 5 | +import { includeIgnoreFile } from '@eslint/compat' |
| 6 | +import prettier from 'eslint-config-prettier' |
| 7 | +import node from 'eslint-plugin-n' |
| 8 | +import vitest from '@vitest/eslint-plugin' |
| 9 | +import tseslint from 'typescript-eslint' |
| 10 | + |
| 11 | +const __filename = fileURLToPath(import.meta.url) |
| 12 | +const __dirname = path.dirname(__filename) |
| 13 | + |
| 14 | +export default tseslint.config( |
| 15 | + // Global rules and configuration |
| 16 | + includeIgnoreFile(path.resolve(__dirname, '.gitignore')), |
| 17 | + { |
| 18 | + linterOptions: { |
| 19 | + reportUnusedDisableDirectives: true, |
| 20 | + }, |
| 21 | + }, |
| 22 | + |
| 23 | + // JavaScript-specific rules |
| 24 | + eslint.configs.recommended, |
| 25 | + |
| 26 | + // Typescript-specific rules |
| 27 | + tseslint.configs.strictTypeChecked, |
| 28 | + tseslint.configs.stylisticTypeChecked, |
| 29 | + { |
| 30 | + languageOptions: { |
| 31 | + parserOptions: { |
| 32 | + projectService: true, |
| 33 | + tsconfigRootDir: __dirname, |
| 34 | + }, |
| 35 | + }, |
| 36 | + }, |
| 37 | + |
| 38 | + { |
| 39 | + files: ['**/*.?(c|m)js?(x)'], |
| 40 | + ...tseslint.configs.disableTypeChecked, |
| 41 | + }, |
| 42 | + node.configs['flat/recommended'], |
| 43 | + { |
| 44 | + rules: { |
| 45 | + 'n/no-extraneous-import': 'off', |
| 46 | + 'n/no-extraneous-require': 'off', |
| 47 | + 'n/no-missing-import': 'off', |
| 48 | + 'n/no-missing-require': 'off', |
| 49 | + 'n/no-unpublished-import': 'off', |
| 50 | + 'n/no-unpublished-require': 'off', |
| 51 | + }, |
| 52 | + }, |
| 53 | + |
| 54 | + // Project-specific rules |
| 55 | + { |
| 56 | + ignores: ['.github/styles/', '**/__fixtures__/'], |
| 57 | + }, |
| 58 | + { |
| 59 | + files: ['**/*.?(c|m)ts?(x)'], |
| 60 | + rules: { |
| 61 | + // `interface` and `type` have different use cases, allow both |
| 62 | + '@typescript-eslint/consistent-type-definitions': 'off', |
| 63 | + |
| 64 | + // Ignore underscore-prefixed unused variables (mirrors tsc behavior) |
| 65 | + '@typescript-eslint/no-unused-vars': [ |
| 66 | + 'error', |
| 67 | + { |
| 68 | + args: 'all', |
| 69 | + argsIgnorePattern: '^_', |
| 70 | + caughtErrors: 'all', |
| 71 | + caughtErrorsIgnorePattern: '^_', |
| 72 | + destructuredArrayIgnorePattern: '^_', |
| 73 | + ignoreRestSiblings: true, |
| 74 | + varsIgnorePattern: '^_', |
| 75 | + }, |
| 76 | + ], |
| 77 | + }, |
| 78 | + }, |
| 79 | + { |
| 80 | + rules: { |
| 81 | + 'no-restricted-imports': [ |
| 82 | + 'error', |
| 83 | + { |
| 84 | + paths: [ |
| 85 | + { |
| 86 | + name: 'node:process', |
| 87 | + importNames: ['cwd'], |
| 88 | + message: 'Use `command.workingDir` instead.', |
| 89 | + }, |
| 90 | + { |
| 91 | + name: 'process', |
| 92 | + importNames: ['cwd'], |
| 93 | + message: 'Use `command.workingDir` instead.', |
| 94 | + }, |
| 95 | + |
| 96 | + { |
| 97 | + name: 'chalk', |
| 98 | + message: |
| 99 | + 'Use the safe chalk import that handles colors for json output: `import { chalk } from "src/utils/command-helpers.js"`', |
| 100 | + }, |
| 101 | + ], |
| 102 | + }, |
| 103 | + ], |
| 104 | + 'no-restricted-properties': [ |
| 105 | + 'error', |
| 106 | + { |
| 107 | + object: 'process', |
| 108 | + property: 'cwd', |
| 109 | + message: '`process.cwd` is not permitted; use `command.workingDir` instead.', |
| 110 | + }, |
| 111 | + ], |
| 112 | + }, |
| 113 | + }, |
| 114 | + |
| 115 | + // Tests |
| 116 | + { |
| 117 | + files: ['**/*.test.?(c|m)[jt]s?(x)'], |
| 118 | + plugins: { vitest }, |
| 119 | + rules: { |
| 120 | + ...vitest.configs.recommended.rules, |
| 121 | + |
| 122 | + 'vitest/expect-expect': [ |
| 123 | + 'error', |
| 124 | + { |
| 125 | + assertFunctionNames: [ |
| 126 | + // Defaults |
| 127 | + 'assert', |
| 128 | + 'expect', |
| 129 | + |
| 130 | + // Fix issue where text-context-specific `expect()` calls trigger false positive |
| 131 | + 't.expect', |
| 132 | + 'ctx.expect', |
| 133 | + 'context.expect', |
| 134 | + |
| 135 | + // Custom assertion functions |
| 136 | + 'assertNetlifyToml', |
| 137 | + ], |
| 138 | + }, |
| 139 | + ], |
| 140 | + }, |
| 141 | + }, |
| 142 | + |
| 143 | + // XXX: Temporarily disabled rules: These rules are disabled because we have offending code that we haven't yet fixed. |
| 144 | + { |
| 145 | + rules: { |
| 146 | + // Empty functions and blocks are useful (e.g `noop() {}`, `catch {}`) but can mask unintentionally omitted |
| 147 | + // implementation. We should add explanatory comments like `// intentionally empty` and `// ignore error` in these |
| 148 | + // scenarios to communicate intent. |
| 149 | + 'no-empty': 'off', |
| 150 | + '@typescript-eslint/no-empty-function': 'off', |
| 151 | + |
| 152 | + 'n/no-unsupported-features/node-builtins': [ |
| 153 | + 'error', |
| 154 | + { |
| 155 | + ignores: ['FormData', 'ReadableStream', 'Response', 'fetch', 'fs/promises.cp'], |
| 156 | + }, |
| 157 | + ], |
| 158 | + }, |
| 159 | + }, |
| 160 | + |
| 161 | + // Must be last |
| 162 | + prettier, |
| 163 | +) |
0 commit comments