-
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
85 additions
and
5 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { describe, it, expect } from "bun:test"; | ||
import { parseOuptut } from "./publint"; | ||
|
||
describe("Publint", () => { | ||
it("should properly parse output", async () => { | ||
const stdout = `@aklinker1/check lint results: | ||
Suggestions: | ||
1. Consider being better lolz. | ||
Warnings: | ||
1. pkg.exports["."].import types is not exported. Consider adding pkg.exports["."].import.types: "./dist/index.d.ts" to be compatible with TypeScript's "moduleResolution": "bundler" compiler option. | ||
Errors: | ||
1. pkg.module is ./dist/index.cjs but the file does not exist. | ||
`; | ||
const stderr = ""; | ||
const code = 1; | ||
|
||
expect(parseOuptut({ code, stdout, stderr })).toEqual({ | ||
type: "error", | ||
problems: [ | ||
{ | ||
file: "package.json", | ||
message: "Consider being better lolz.", | ||
kind: "warning", | ||
}, | ||
{ | ||
file: "package.json", | ||
message: | ||
'pkg.exports["."].import types is not exported. Consider adding pkg.exports["."].import.types: "./dist/index.d.ts" to be compatible with TypeScript\'s "moduleResolution": "bundler" compiler option.', | ||
kind: "warning", | ||
}, | ||
{ | ||
file: "package.json", | ||
message: | ||
"pkg.module is ./dist/index.cjs but the file does not exist.", | ||
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,38 @@ | ||
import type { OutputParser, Problem, ProblemKind, Tool } from "../types"; | ||
import { isBinInstalled, execAndParse } from "../utils"; | ||
|
||
const bin = "node_modules/.bin/publint"; | ||
const args: string[] = []; | ||
|
||
export const publint: Tool = { | ||
name: "Publint", | ||
isInstalled: (root) => isBinInstalled(bin, root), | ||
check: (root) => execAndParse(root, bin, args, parseOuptut), | ||
}; | ||
|
||
export const parseOuptut: OutputParser = ({ code, stdout, stderr }) => { | ||
if (code === 0) return { type: "success" }; | ||
|
||
let kind: ProblemKind = "warning"; | ||
const problems = stdout.split(/\r?\n/).reduce<Problem[]>((acc, line) => { | ||
if (line.includes("Errors:")) { | ||
kind = "error"; | ||
return acc; | ||
} | ||
const match = /^[0-9]+\.\s?(.*)$/.exec(line); | ||
if (match == null) return acc; | ||
|
||
acc.push({ | ||
kind, | ||
message: match[1], | ||
file: "package.json", | ||
}); | ||
|
||
return acc; | ||
}, []); | ||
|
||
return { | ||
type: kind, | ||
problems, | ||
}; | ||
}; |