Skip to content

Commit a7dc020

Browse files
committed
fix(lint): keep the child_process and provider bans on files the node:os override matches
oxlint doesn't merge no-restricted-imports options across overrides: when several overrides match a file, the last match's options replace the earlier ones instead of accumulating. The new PRODUCT_TEST_FILES override (node:os ban) and the tmp-dir exemption override both matched files that were already covered by the child_process/provider bans (fixtures.ts and test-utils files under src/**, packages/host-kit/src/**, and the host-kit tmp-dir helper), silently dropping those bans for those files. Compose every no-restricted-imports override from shared path/pattern constants so overlapping overrides restate the full union of bans that should apply, instead of one override's options clobbering another's.
1 parent a605029 commit a7dc020

1 file changed

Lines changed: 67 additions & 46 deletions

File tree

oxlint.config.ts

Lines changed: 67 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,27 @@ const PRODUCT_TEST_FILES = PRODUCT_TEST_ROOTS.flatMap((root) =>
1515
PRODUCT_TEST_SHAPES.map((shape) => `${root}/${shape}`),
1616
);
1717

18+
// The last matching override replaces `no-restricted-imports` options instead of merging them,
19+
// so each override restates every ban that applies to the files it matches.
20+
const CHILD_PROCESS_PATH = {
21+
message:
22+
'Use process helpers from @agent-device/host-kit/command instead of importing node:child_process directly.',
23+
name: 'node:child_process',
24+
};
25+
const PROVIDER_IMPORT_PATTERN = {
26+
group: ['@agent-device/provider-*'],
27+
message:
28+
'Command implementations must ask src/cli/connection/provider-policy.ts for provider capabilities.',
29+
};
30+
const NODE_OS_PATH = {
31+
message:
32+
'Create test scratch with mkdtempForTest()/mkdtempForTestSync() from the package tmp-dir helper instead of reading node:os.',
33+
name: 'node:os',
34+
};
35+
36+
const CHILD_PROCESS_BAN_ROOTS = ['src', 'packages/host-kit/src'];
37+
const PROVIDER_BAN_ROOTS = ['src/commands', 'src/cli/commands'];
38+
1839
export default defineConfig({
1940
env: {
2041
builtin: true,
@@ -69,57 +90,23 @@ export default defineConfig({
6990
},
7091
},
7192
{
72-
files: ['src/**/*.ts', 'packages/host-kit/src/**/*.ts'],
93+
files: CHILD_PROCESS_BAN_ROOTS.map((root) => `${root}/**/*.ts`),
7394
rules: {
74-
'no-restricted-imports': [
75-
'error',
76-
{
77-
paths: [
78-
{
79-
name: 'node:child_process',
80-
message:
81-
'Use process helpers from @agent-device/host-kit/command instead of importing node:child_process directly.',
82-
},
83-
],
84-
},
85-
],
95+
'no-restricted-imports': ['error', { paths: [CHILD_PROCESS_PATH] }],
8696
},
8797
},
8898
{
89-
files: ['src/commands/**/*.ts', 'src/cli/commands/**/*.ts'],
99+
files: PROVIDER_BAN_ROOTS.map((root) => `${root}/**/*.ts`),
90100
rules: {
91101
'no-restricted-imports': [
92102
'error',
93103
{
94-
paths: [
95-
{
96-
name: 'node:child_process',
97-
message:
98-
'Use process helpers from @agent-device/host-kit/command instead of importing node:child_process directly.',
99-
},
100-
],
101-
patterns: [
102-
{
103-
group: ['@agent-device/provider-*'],
104-
message:
105-
'Command implementations must ask src/cli/connection/provider-policy.ts for provider capabilities.',
106-
},
107-
],
104+
paths: [CHILD_PROCESS_PATH],
105+
patterns: [PROVIDER_IMPORT_PATTERN],
108106
},
109107
],
110108
},
111109
},
112-
{
113-
files: [
114-
'packages/host-kit/src/internal/exec.ts',
115-
'packages/host-kit/src/**/*.test.ts',
116-
'src/**/*.test.ts',
117-
'src/**/__tests__/**/*.ts',
118-
],
119-
rules: {
120-
'no-restricted-imports': ['error', { paths: [] }],
121-
},
122-
},
123110
{
124111
files: ['examples/test-app/src/**/*.tsx'],
125112
rules: {
@@ -166,27 +153,61 @@ export default defineConfig({
166153
// justified read (mocking production, a real socket path, or the TMPDIR mechanism itself)
167154
// oxlint-disables its one import line with a reason instead of widening this list.
168155
files: PRODUCT_TEST_FILES,
156+
rules: {
157+
'no-restricted-imports': ['error', { paths: [NODE_OS_PATH] }],
158+
},
159+
},
160+
{
161+
files: CHILD_PROCESS_BAN_ROOTS.flatMap((root) =>
162+
PRODUCT_TEST_SHAPES.map((shape) => `${root}/${shape}`),
163+
),
164+
rules: {
165+
'no-restricted-imports': ['error', { paths: [CHILD_PROCESS_PATH, NODE_OS_PATH] }],
166+
},
167+
},
168+
{
169+
files: PROVIDER_BAN_ROOTS.flatMap((root) =>
170+
PRODUCT_TEST_SHAPES.map((shape) => `${root}/${shape}`),
171+
),
169172
rules: {
170173
'no-restricted-imports': [
171174
'error',
172175
{
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-
],
176+
paths: [CHILD_PROCESS_PATH, NODE_OS_PATH],
177+
patterns: [PROVIDER_IMPORT_PATTERN],
180178
},
181179
],
182180
},
183181
},
182+
{
183+
// Tests may import node:child_process and provider packages directly.
184+
files: ['packages/host-kit/src/**/*.test.ts', 'src/**/*.test.ts', 'src/**/__tests__/**/*.ts'],
185+
rules: {
186+
'no-restricted-imports': ['error', { paths: [NODE_OS_PATH] }],
187+
},
188+
},
184189
{
185190
// The tmp-dir helper modules are the sanctioned os.tmpdir() readers.
186191
files: ['**/tmp-dir.ts', '**/tmp-dir.fixtures.ts'],
187192
rules: {
188193
'no-restricted-imports': ['error', { paths: [] }],
189194
},
190195
},
196+
{
197+
files: CHILD_PROCESS_BAN_ROOTS.flatMap((root) => [
198+
`${root}/**/tmp-dir.ts`,
199+
`${root}/**/tmp-dir.fixtures.ts`,
200+
]),
201+
rules: {
202+
'no-restricted-imports': ['error', { paths: [CHILD_PROCESS_PATH] }],
203+
},
204+
},
205+
{
206+
// The host-kit process helpers are the sanctioned node:child_process importer.
207+
files: ['packages/host-kit/src/internal/exec.ts'],
208+
rules: {
209+
'no-restricted-imports': ['error', { paths: [] }],
210+
},
211+
},
191212
],
192213
});

0 commit comments

Comments
 (0)