-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
199 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { eslint } from "./eslint"; | ||
import { oxlint } from "./oxlint"; | ||
import { prettier } from "./prettier"; | ||
import { typescript } from "./typescript"; | ||
import { publint } from "./publint"; | ||
import { typescript } from "./typescript"; | ||
|
||
export const ALL_TOOLS = [publint, prettier, typescript, eslint]; | ||
export const ALL_TOOLS = [publint, prettier, typescript, oxlint, eslint]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { describe, it, expect } from "bun:test"; | ||
import { parseOuptut } from "./oxlint"; | ||
|
||
describe("Oxlint", () => { | ||
it("should properly parse output", async () => { | ||
const stdout = ` | ||
test.ts:1:7: Variable 'test' is declared but never used. [Warning/eslint(no-unused-vars)] | ||
test.ts:3:7: Variable 'variable' is declared but never used. [Warning/eslint(no-unused-vars)] | ||
test.ts:8:7: Variable 'two' is declared but never used. [Warning/eslint(no-unused-vars)] | ||
test.ts:8:7: Missing initializer in const declaration [Error] | ||
3 problems | ||
`; | ||
const stderr = ""; | ||
const code = 1; | ||
|
||
expect(parseOuptut({ code, stdout, stderr })).toEqual([ | ||
{ | ||
file: "test.ts", | ||
message: "Variable 'test' is declared but never used.", | ||
location: { | ||
line: 1, | ||
column: 7, | ||
}, | ||
rule: "eslint(no-unused-vars)", | ||
kind: "warning", | ||
}, | ||
{ | ||
file: "test.ts", | ||
message: "Variable 'variable' is declared but never used.", | ||
location: { | ||
line: 3, | ||
column: 7, | ||
}, | ||
rule: "eslint(no-unused-vars)", | ||
kind: "warning", | ||
}, | ||
{ | ||
file: "test.ts", | ||
message: "Variable 'two' is declared but never used.", | ||
location: { | ||
line: 8, | ||
column: 7, | ||
}, | ||
rule: "eslint(no-unused-vars)", | ||
kind: "warning", | ||
}, | ||
{ | ||
file: "test.ts", | ||
message: "Missing initializer in const declaration", | ||
location: { | ||
line: 8, | ||
column: 7, | ||
}, | ||
kind: "error", | ||
}, | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import type { OutputParser, Problem, ToolDefinition } from "../types"; | ||
import { execAndParse, isBinInstalled } from "../utils"; | ||
import { resolve } from "node:path"; | ||
|
||
export const oxlint: ToolDefinition = ({ binDir, root }) => { | ||
const bin = resolve(root, binDir, "oxlint"); | ||
const checkArgs = ["--format=linux"]; | ||
const fixArgs = ["--format=linux", "--fix"]; | ||
|
||
return { | ||
name: "Oxlint", | ||
isInstalled: () => isBinInstalled(bin), | ||
check: () => execAndParse(bin, checkArgs, root, parseOuptut), | ||
fix: () => execAndParse(bin, fixArgs, root, parseOuptut), | ||
}; | ||
}; | ||
|
||
export const parseOuptut: OutputParser = ({ stdout, stderr }) => { | ||
if (stdout.trim()) { | ||
return stdout.split(/\r?\n/).reduce<Problem[]>((acc, line) => { | ||
const groups = | ||
/^(?<file>.+?):(?<line>[0-9]+):(?<column>[0-9]):\s?(?<message>.*?)\s?\[(?<kind>Warning|Error)\/?(?<rule>.*?)\]\s?$/.exec( | ||
line, | ||
)?.groups; | ||
if (groups) { | ||
acc.push({ | ||
file: groups.file, | ||
kind: groups.kind === "Error" ? "error" : "warning", | ||
message: groups.message, | ||
rule: groups.rule || undefined, | ||
location: { | ||
line: parseInt(groups.line, 10), | ||
column: parseInt(groups.column, 10), | ||
}, | ||
}); | ||
} | ||
return acc; | ||
}, []); | ||
} | ||
|
||
return stdout | ||
.trim() | ||
.split(/\r?\n/) | ||
.map((line) => line.trim()) | ||
.filter((line) => !!line && !line.includes(" ")) | ||
.map( | ||
(line): Problem => ({ | ||
file: line.trim(), | ||
kind: "warning", | ||
message: "Not formatted.", | ||
}), | ||
); | ||
}; |