Skip to content

Commit e98a6c7

Browse files
committed
fix: resolve parent xo config from nested cwd
1 parent e48fec9 commit e98a6c7

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

lib/resolve-config.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ export async function resolveXoConfig(options: LinterOptions): Promise<{
2424
options.cwd = path.resolve(process.cwd(), options.cwd);
2525
}
2626

27-
const stopDirectory = path.dirname(options.cwd);
28-
2927
const flatConfigExplorer = cosmiconfig(moduleName, {
28+
searchStrategy: 'project',
3029
searchPlaces: [
3130
'package.json',
3231
`${moduleName}.config.js`,
@@ -38,7 +37,6 @@ export async function resolveXoConfig(options: LinterOptions): Promise<{
3837
'.ts': loadTypeScriptConfig, // eslint-disable-line @typescript-eslint/naming-convention
3938
'.mts': loadTypeScriptConfig, // eslint-disable-line @typescript-eslint/naming-convention
4039
},
41-
stopDir: stopDirectory,
4240
cache: true,
4341
});
4442

test/resolve-config.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,36 @@ test('resolves package.json object config', async t => {
110110
t.deepEqual(flatOptions, [{space: true}]);
111111
});
112112

113+
test('resolves parent package.json config from nested package cwd', async t => {
114+
const pkg = JSON.parse(await fs.readFile(
115+
path.join(t.context.cwd, 'package.json'),
116+
'utf8',
117+
)) as PackageJson;
118+
119+
pkg['xo'] = {space: true};
120+
121+
await fs.writeFile(
122+
path.join(t.context.cwd, 'package.json'),
123+
JSON.stringify(pkg),
124+
'utf8',
125+
);
126+
127+
const packageCwd = path.join(t.context.cwd, 'packages', 'app');
128+
await fs.mkdir(packageCwd, {recursive: true});
129+
await fs.writeFile(
130+
path.join(packageCwd, 'package.json'),
131+
JSON.stringify({name: 'app'}),
132+
'utf8',
133+
);
134+
135+
const {flatOptions, flatConfigPath} = await resolveXoConfig({
136+
cwd: packageCwd,
137+
});
138+
139+
t.deepEqual(flatConfigPath, path.join(t.context.cwd, 'package.json'));
140+
t.deepEqual(flatOptions, [{space: true}]);
141+
});
142+
113143
test('resolves all config extensions types', async t => {
114144
const testConfigEsm = `export default [
115145
{

0 commit comments

Comments
 (0)