-
Notifications
You must be signed in to change notification settings - Fork 6
/
formatters.ts
43 lines (34 loc) · 1.02 KB
/
formatters.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
import { IntrospectFn } from "../deps.ts";
import {
introspect as introspectPrettier,
Prettier,
} from "../_shared/prettier/mod.ts";
// deno-lint-ignore no-empty-interface
interface Deno {}
export type Formatters = {
deno?: Deno;
prettier?: Prettier | null;
} | null;
function anyValue(records: Record<string, unknown>): boolean {
return Object.values(records).some((v) => v);
}
export const introspect: IntrospectFn<Formatters> = async (context) => {
const logger = context.getLogger("javascript");
logger.debug("detecting formatter");
const prettier = await introspectPrettier(context);
if (prettier !== null) {
logger.debug("detected Prettier");
}
const formatters: Formatters = {
prettier,
};
if (anyValue(formatters)) return formatters;
if (context.suggestDefault) {
logger.warning("No JavaScript formatter detected, using Prettier");
return {
prettier: { name: "prettier", hasIgnoreFile: false },
};
}
logger.debug("no supported formatter detected");
return null;
};