Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion linters/biome/biome.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,49 @@
import { linterCheckTest, linterFmtTest } from "tests";
import { linterCheckTest, linterFmtTest, TestCallback } from "tests";

linterCheckTest({ linterName: "biome", namedTestPrefixes: ["basic_check"] });

linterFmtTest({ linterName: "biome", namedTestPrefixes: ["basic_fmt", "basic_json"] });

// Verify warning-level findings ('!' marker) are captured by parse_regex,
// not just errors ('×'). Regression coverage for trunk-io/plugins#1113.
const enableWarnRule: TestCallback = (driver) => {
driver.writeFile(
"biome.json",
JSON.stringify({
$schema: "https://biomejs.dev/schemas/2.3.4/schema.json",
linter: {
enabled: true,
rules: {
recommended: false,
style: { noNonNullAssertion: "warn" },
},
},
}),
);
};
linterCheckTest({
linterName: "biome",
namedTestPrefixes: ["warning_check"],
preCheck: enableWarnRule,
});

// Verify .gitignore reaches the sandbox so vcs.useIgnoreFile works. Without
// the symlinks: directive in plugin.yaml, biome aborts with internalError/fs
// when it can't find the ignore file and silently drops all findings.
// Regression coverage for trunk-io/plugins#1113 issue 2.
const setupGitignoreRepo: TestCallback = (driver) => {
driver.writeFile(
"biome.json",
JSON.stringify({
$schema: "https://biomejs.dev/schemas/2.3.4/schema.json",
vcs: { clientKind: "git", enabled: true, useIgnoreFile: true },
linter: { enabled: true, rules: { recommended: true } },
}),
);
driver.writeFile(".gitignore", "");
};
linterCheckTest({
linterName: "biome",
namedTestPrefixes: ["gitignore_check"],
preCheck: setupGitignoreRepo,
});
17 changes: 15 additions & 2 deletions linters/biome/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ lint:
commands:
- name: lint
output: regex
# Match both errors (×) and warnings (!). The marker line must be
# the immediate next line (after a blank line) following the header,
# so each diagnostic is parsed as a self-contained block — the prior
# regex lazily matched across diagnostics and silently mis-attributed
# path/line/col to a different finding's message. Info-level (i) is
# intentionally excluded; biome surfaces those for hints, not gating.
parse_regex:
' *(?P<path>.*?):(?P<line>\d+):(?P<col>\d+) (?P<code>[^ ]+)(?:[^×]*\n).*×
(?P<message>.*)\n'
' *(?P<path>[^\n]*?):(?P<line>\d+):(?P<col>\d+) (?P<code>[^ \n]+)[^\n]*\n[ \t]*\n[
\t]+[×!] (?P<message>[^\n]+)'
run: biome check ${target}
success_codes: [0, 1]
batch: true
Expand All @@ -51,3 +57,10 @@ lint:
version_command:
parse_regex: biome CLI version ${semver}
run: biome --version
symlinks:
# biome's vcs.useIgnoreFile reads .gitignore from the sandbox root.
# Without this, the per-target sandbox lacks .gitignore and biome
# aborts with internalError/fs, silently dropping all findings.
# See trunk-io/plugins#1113.
- from: ${workspace}/.gitignore
to: .gitignore
8 changes: 4 additions & 4 deletions linters/biome/test_data/biome_v2.3.4_basic_check.check.shot
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ exports[`Testing linter biome test basic_check 1`] = `
{
"issues": [
{
"code": "lint/complexity/noUselessLoneBlockStatements",
"column": "3",
"code": "lint/correctness/noUnusedVariables",
"column": "7",
"file": "test_data/basic_check.in.ts",
"issueClass": "ISSUE_CLASS_EXISTING",
"level": "LEVEL_HIGH",
"line": "13",
"line": "6",
"linter": "biome",
"message": "Formatter would have printed the following content:",
"message": "This variable foo is unused.",
"targetType": "typescript",
},
],
Expand Down
51 changes: 51 additions & 0 deletions linters/biome/test_data/biome_v2.3.4_gitignore_check.check.shot
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing linter biome test gitignore_check 1`] = `
{
"issues": [
{
"code": "lint/correctness/noUnusedVariables",
"column": "7",
"file": "test_data/gitignore_check.in.ts",
"issueClass": "ISSUE_CLASS_EXISTING",
"level": "LEVEL_HIGH",
"line": "1",
"linter": "biome",
"message": "This variable unusedHelper is unused.",
"targetType": "typescript",
},
],
"lintActions": [
{
"command": "fmt",
"fileGroupName": "typescript",
"linter": "biome",
"paths": [
"test_data/gitignore_check.in.ts",
],
"verb": "TRUNK_VERB_FMT",
},
{
"command": "lint",
"fileGroupName": "typescript",
"linter": "biome",
"paths": [
"test_data/gitignore_check.in.ts",
],
"verb": "TRUNK_VERB_CHECK",
},
{
"command": "lint",
"fileGroupName": "typescript",
"linter": "biome",
"paths": [
"test_data/gitignore_check.in.ts",
],
"upstream": true,
"verb": "TRUNK_VERB_CHECK",
},
],
"taskFailures": [],
"unformattedFiles": [],
}
`;
51 changes: 51 additions & 0 deletions linters/biome/test_data/biome_v2.3.4_warning_check.check.shot
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Testing linter biome test warning_check 1`] = `
{
"issues": [
{
"code": "lint/style/noNonNullAssertion",
"column": "16",
"file": "test_data/warning_check.in.ts",
"issueClass": "ISSUE_CLASS_EXISTING",
"level": "LEVEL_HIGH",
"line": "5",
"linter": "biome",
"message": "Forbidden non-null assertion.",
"targetType": "typescript",
},
],
"lintActions": [
{
"command": "fmt",
"fileGroupName": "typescript",
"linter": "biome",
"paths": [
"test_data/warning_check.in.ts",
],
"verb": "TRUNK_VERB_FMT",
},
{
"command": "lint",
"fileGroupName": "typescript",
"linter": "biome",
"paths": [
"test_data/warning_check.in.ts",
],
"verb": "TRUNK_VERB_CHECK",
},
{
"command": "lint",
"fileGroupName": "typescript",
"linter": "biome",
"paths": [
"test_data/warning_check.in.ts",
],
"upstream": true,
"verb": "TRUNK_VERB_CHECK",
},
],
"taskFailures": [],
"unformattedFiles": [],
}
`;
2 changes: 2 additions & 0 deletions linters/biome/test_data/gitignore_check.in.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const unusedHelper = (input: number) => input + 1;
export const sample = 42;
6 changes: 6 additions & 0 deletions linters/biome/test_data/warning_check.in.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Triggers biome's lint/style/noNonNullAssertion at warning level when the
// rule is enabled with `level: "warn"`. Verifies that the lint parse_regex
// captures '!' (warning marker) findings, not just '×' (error marker).
const value: number | null = null;
const result = value!.toFixed();
console.log(result);
Loading