|
1 | 1 | import nkzw from '@nkzw/oxlint-config'; |
2 | 2 | import { defineConfig } from 'oxlint'; |
3 | 3 |
|
| 4 | +// Product source trees, where unit tests get scratch from the package tmp-dir helpers. |
| 5 | +// scripts/, test/, and package test harnesses manage TMPDIR for child processes on purpose, |
| 6 | +// so keeping the roots explicit holds them out of scope that a bare `**` would sweep in. |
| 7 | +const PRODUCT_TEST_ROOTS = ['src', 'packages/*/src']; |
| 8 | +const PRODUCT_TEST_SHAPES = [ |
| 9 | + '**/*.test.ts', |
| 10 | + '**/*.fixtures.ts', |
| 11 | + '**/__tests__/**/*.ts', |
| 12 | + '**/test-utils/**/*.ts', |
| 13 | +]; |
| 14 | +const PRODUCT_TEST_FILES = PRODUCT_TEST_ROOTS.flatMap((root) => |
| 15 | + PRODUCT_TEST_SHAPES.map((shape) => `${root}/${shape}`), |
| 16 | +); |
| 17 | + |
4 | 18 | export default defineConfig({ |
5 | 19 | env: { |
6 | 20 | builtin: true, |
@@ -146,5 +160,33 @@ export default defineConfig({ |
146 | 160 | output: 'writable', |
147 | 161 | }, |
148 | 162 | }, |
| 163 | + { |
| 164 | + // Product tests get scratch from the package tmp-dir helpers, which honor the run's |
| 165 | + // redirected TMPDIR; reading node:os reuses a fixed path across the suite. A file with a |
| 166 | + // justified read (mocking production, a real socket path, or the TMPDIR mechanism itself) |
| 167 | + // oxlint-disables its one import line with a reason instead of widening this list. |
| 168 | + files: PRODUCT_TEST_FILES, |
| 169 | + rules: { |
| 170 | + 'no-restricted-imports': [ |
| 171 | + 'error', |
| 172 | + { |
| 173 | + paths: [ |
| 174 | + { |
| 175 | + name: 'node:os', |
| 176 | + message: |
| 177 | + 'Create test scratch with mkdtempForTest()/mkdtempForTestSync() from the package tmp-dir helper instead of reading node:os.', |
| 178 | + }, |
| 179 | + ], |
| 180 | + }, |
| 181 | + ], |
| 182 | + }, |
| 183 | + }, |
| 184 | + { |
| 185 | + // The tmp-dir helper modules are the sanctioned os.tmpdir() readers. |
| 186 | + files: ['**/tmp-dir.ts', '**/tmp-dir.fixtures.ts'], |
| 187 | + rules: { |
| 188 | + 'no-restricted-imports': ['error', { paths: [] }], |
| 189 | + }, |
| 190 | + }, |
149 | 191 | ], |
150 | 192 | }); |
0 commit comments