forked from webpro-nl/knip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
43 lines (34 loc) · 1.26 KB
/
index.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 { timerify } from '../../util/Performance.js';
import { hasDependency, load } from '../../util/plugin.js';
import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
// https://prettier.io/docs/en/configuration.html
type PrettierConfig = {
plugins?: (
| string
| {
parsers?: Record<string, unknown>;
printers?: Record<string, unknown>;
languages?: unknown[];
options?: Record<string, unknown>;
}
)[];
};
export const NAME = 'Prettier';
/** @public */
export const ENABLERS = ['prettier'];
export const isEnabled: IsPluginEnabledCallback = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
export const CONFIG_FILE_PATTERNS = [
'.prettierrc',
'.prettierrc.{json,js,cjs,yml,yaml}',
'prettier.config.{js,cjs}',
'package.json',
];
const findPrettierDependencies: GenericPluginCallback = async (configFilePath, { manifest }) => {
const config: PrettierConfig = configFilePath.endsWith('package.json')
? manifest.prettier
: await load(configFilePath);
return config && Array.isArray(config.plugins)
? config.plugins.filter((plugin): plugin is string => typeof plugin === 'string')
: [];
};
export const findDependencies = timerify(findPrettierDependencies);