refactor(scripts): cleanup & enforce code style (#1388)
This commit is contained in:
1 parent
7db9b234c1
commit
5d74d700a2
23 files changed
+290
-270
No files matched your search
+35
-29
@@ -1,44 +1,50 @@
|
||||
import * as color from "@std/fmt/colors";
|
||||
import type { WalkEntry } from "@std/fs";
|
||||
import { relative } from "@std/path";
|
||||
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 { REPO_ROOT } from "@/deps.ts";
|
||||
import { log } from "@/logger.ts";
|
||||
|
||||
export const lint = (
|
||||
export async function lint(
|
||||
entry: WalkEntry,
|
||||
content: string,
|
||||
fix: boolean,
|
||||
config: stylelint.Config,
|
||||
) =>
|
||||
stylelint.lint({ code: content, config, fix })
|
||||
.then(({ results, code }) => {
|
||||
if (code) {
|
||||
Deno.writeTextFileSync(entry.path, code);
|
||||
}
|
||||
results.map((result) => {
|
||||
result.warnings.map((warning) => {
|
||||
// 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";
|
||||
) {
|
||||
const { results, code } = await stylelint.lint({
|
||||
code: content,
|
||||
config,
|
||||
fix,
|
||||
});
|
||||
|
||||
log.log(message, {
|
||||
file: relative(REPO_ROOT, entry.path),
|
||||
startLine: warning.line,
|
||||
endLine: warning.endLine,
|
||||
startColumn: warning.column,
|
||||
endColumn: warning.endColumn,
|
||||
content,
|
||||
}, warning.severity);
|
||||
});
|
||||
if (code) {
|
||||
Deno.writeTextFileSync(entry.path, code);
|
||||
}
|
||||
|
||||
if (result.warnings.length > 0) throw new Error("stylelint error");
|
||||
});
|
||||
});
|
||||
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");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user