forked from catppuccin/userstyles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstylelint.ts
More file actions
50 lines (42 loc) 路 1.25 KB
/
Copy pathstylelint.ts
File metadata and controls
50 lines (42 loc) 路 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import type { WalkEntry } from "@std/fs";
import { REPO_ROOT } from "@/constants.ts";
import * as color from "@std/fmt/colors";
import * as path from "@std/path";
import "postcss-less";
import stylelint from "stylelint";
import "stylelint-config-standard";
import "stylelint-config-recommended";
import { log } from "@/logger.ts";
export async function lint(
entry: WalkEntry,
content: string,
fix: boolean,
config: stylelint.Config,
) {
const { results, code } = await stylelint.lint({
code: content,
config,
fix,
});
if (code) {
Deno.writeTextFileSync(entry.path, code);
}
for (const result of results) {
for (const warning of result.warnings) {
// Some cleanup for fancier logging - dims the rule name.
const message = warning.text?.replace(
new RegExp(`\\(?${warning.rule}\\)?`),
color.dim(`(${warning.rule})`),
) ?? "unspecified stylelint error";
log.log(message, {
file: path.relative(REPO_ROOT, entry.path),
startLine: warning.line,
endLine: warning.endLine,
startColumn: warning.column,
endColumn: warning.endColumn,
content,
}, warning.severity);
}
if (result.warnings.length > 0) throw new Error("stylelint error");
}
}