-
Notifications
You must be signed in to change notification settings - Fork 6
/
linters.ts
56 lines (44 loc) · 1.22 KB
/
linters.ts
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
51
52
53
54
55
56
import { IntrospectFn } from "../deps.ts";
import {
ESLint,
introspect as introspectESLint,
} from "../_shared/eslint/mod.ts";
import {
introspect as introspectStylelint,
Stylelint,
} from "../_shared/stylelint/mod.ts";
// deno-lint-ignore no-empty-interface
interface Deno {}
export type Linters = {
eslint?: ESLint | null;
stylelint?: Stylelint | null;
deno?: Deno;
} | null;
function anyValue(records: Record<string, unknown>): boolean {
return Object.values(records).some((v) => v);
}
export const introspect: IntrospectFn<Linters> = async (context) => {
const logger = context.getLogger("html");
logger.debug("detecting linter");
const eslint = await introspectESLint(context);
if (eslint !== null) {
logger.debug("detected ESLint");
}
const styleLint = await introspectStylelint(context);
if (styleLint !== null) {
logger.debug("detected stylelint");
}
const linters = {
eslint,
styleLint,
};
if (anyValue(linters)) return linters;
if (context.suggestDefault) {
logger.warning("No Vue or HTML linter detected, using ESLint");
return {
eslint: { name: "eslint", hasIgnoreFile: false },
};
}
logger.debug("no supported linter detected");
return null;
};