-
Notifications
You must be signed in to change notification settings - Fork 66.8k
Expand file tree
/
Copy pathinit-test.ts
More file actions
34 lines (28 loc) · 1.06 KB
/
init-test.ts
File metadata and controls
34 lines (28 loc) · 1.06 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
import markdownlint from 'markdownlint'
import type { Configuration, Options } from 'markdownlint'
import { defaultConfig } from '@/content-linter/lib/default-markdownlint-options'
import type { Rule } from '@/content-linter/types'
interface RunRuleOptions {
strings?: { [key: string]: string }
files?: string[]
ruleConfig?: boolean | object
markdownlintOptions?: Partial<Options>
}
export async function runRule(
module: Rule,
{ strings, files, ruleConfig, markdownlintOptions = {} }: RunRuleOptions,
) {
if ((!strings && !files) || (strings && files))
throw new Error('Must provide either Markdown strings or files to run a rule')
const testConfig: Configuration = {
[module.names[0]]: ruleConfig || true,
}
const testOptions: Partial<Options> = {
customRules: [module as any],
config: { ...defaultConfig, ...testConfig },
}
if (strings) testOptions.strings = strings
if (files) testOptions.files = files
const options: Options = { ...markdownlintOptions, ...testOptions }
return await markdownlint.promises.markdownlint(options)
}