Skip to content

Commit

Permalink
feat: Add publint support
Browse files Browse the repository at this point in the history
  • Loading branch information
aklinker1 committed Mar 8, 2024
1 parent 57828e3 commit 03e0678
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 5 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
> [!WARNING]
> I have not actually published this to NPM yet.
https://github.com/aklinker1/check/assets/10101283/c8089e5c-e25f-4f59-8897-d2a6f97a3139

```sh
pnpm i @aklinker1/check
pnpm check
pnpm check --fix
```

https://github.com/aklinker1/check/assets/10101283/c8089e5c-e25f-4f59-8897-d2a6f97a3139

To enable TS, ESLint, or Prettier, just install the package:
To enable checks for any of the following modules, just install them:

```sh
pnpm i -D typescript eslint prettier
pnpm i -D typescript eslint prettier publint
```

## Contributing
Expand Down
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"devDependencies": {
"@types/bun": "latest",
"publint": "^0.2.7",
"unbuild": "latest"
},
"peerDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion src/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import type { Tool } from "../types";
import { eslint } from "./eslint";
import { prettier } from "./prettier";
import { typescript } from "./typescript";
import { publint } from "./publint";

export const ALL_TOOLS: Tool[] = [prettier, typescript, eslint];
export const ALL_TOOLS: Tool[] = [publint, prettier, typescript, eslint];
40 changes: 40 additions & 0 deletions src/tools/publint.test.ts
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",
},
],
});
});
});
38 changes: 38 additions & 0 deletions src/tools/publint.ts
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,
};
};

0 comments on commit 03e0678

Please sign in to comment.