Skip to content

Commit 07439ef

Browse files
authored
Support new biome config extends definition (#1177)
1 parent da80ab3 commit 07439ef

File tree

12 files changed

+82
-4
lines changed

12 files changed

+82
-4
lines changed

packages/knip/biome.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
33
"extends": ["../../biome.json"],
44
"files": {
5-
"ignore": ["**/dist", "package.json", "vendor/bash-parser/index.js"]
5+
"ignore": [
6+
"**/dist",
7+
"package.json",
8+
"vendor/bash-parser/index.js",
9+
"fixtures/plugins/biome-workspace/packages/stub"
10+
]
611
},
712
"formatter": {
813
"ignore": ["ignore-exports-used-in-file-alias-exclude/more.ts"]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/2.1.1/schema.json",
3+
"extends": ["@org/shared-configs/biome"]
4+
}

packages/knip/fixtures/plugins/biome-workspace/index.ts

Whitespace-only changes.

packages/knip/fixtures/plugins/biome-workspace/node_modules/@biomejs/biome/package.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/knip/fixtures/plugins/biome-workspace/node_modules/@org/shared-configs/biome.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/knip/fixtures/plugins/biome-workspace/node_modules/@org/shared-configs/package.json

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "@plugins/biome-workspace",
3+
"module": "index.ts",
4+
"type": "module",
5+
"private": true,
6+
"workspaces": [
7+
"packages/*"
8+
],
9+
"scripts": {
10+
"lint": "biome lint ."
11+
},
12+
"devDependencies": {
13+
"@biomejs/biome": "*",
14+
"@org/shared-configs": "*"
15+
}
16+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/2.1.1/schema.json",
3+
"extends": "//"
4+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "stub-package"
3+
}

packages/knip/src/plugins/biome/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { IsPluginEnabled, Plugin, PluginOptions, ResolveConfig } from '../../types/config.js';
2+
import { arrayify } from '../../util/array.js';
23
import { type Input, toConfig } from '../../util/input.js';
4+
import { join } from '../../util/path.js';
35
import { hasDependency } from '../../util/plugin.js';
46
import type { BiomeConfig } from './types.js';
57

@@ -11,12 +13,20 @@ const isEnabled: IsPluginEnabled = ({ dependencies }) => hasDependency(dependenc
1113

1214
const config: string[] = ['biome.json', 'biome.jsonc'];
1315

16+
const isRootConfigReference = (specifier: string) => specifier === '//';
17+
1418
const resolveExtends = (extendsArray: string[], options: PluginOptions): Input[] => {
15-
return extendsArray.map(specifier => toConfig('biome', specifier, { containingFilePath: options.configFilePath }));
19+
return extendsArray.map(specifier => {
20+
if (isRootConfigReference(specifier)) {
21+
return toConfig('biome', join(options.rootCwd, 'biome'), { containingFilePath: options.configFilePath });
22+
}
23+
24+
return toConfig('biome', specifier, { containingFilePath: options.configFilePath });
25+
});
1626
};
1727

1828
const resolveConfig: ResolveConfig<BiomeConfig> = (config, options) => {
19-
return [...resolveExtends(config.extends || [], options)];
29+
return [...resolveExtends(arrayify(config.extends), options)];
2030
};
2131

2232
export default {

0 commit comments

Comments
 (0)