forked from angular-eslint/angular-eslint
/
create-eslint-rule.ts
32 lines (29 loc) · 1.01 KB
/
create-eslint-rule.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
import { ESLintUtils } from '@typescript-eslint/utils';
/**
* We need to patch the RuleCreator in order to preserve the defaultOptions
* to use as part of documentation generation.
*/
const patchedRuleCreator: typeof ESLintUtils.RuleCreator = (urlCreator) => {
return function createRule({ name, meta, defaultOptions, create }) {
return {
meta: Object.assign(Object.assign({}, meta), {
docs: Object.assign(Object.assign({}, meta.docs), {
url: urlCreator(name),
}),
}),
defaultOptions,
create(context) {
const optionsWithDefault = ESLintUtils.applyDefault(
defaultOptions,
context.options,
);
return create(context, optionsWithDefault);
},
};
};
};
patchedRuleCreator.withoutDocs = ESLintUtils.RuleCreator.withoutDocs;
export const createESLintRule = patchedRuleCreator(
(ruleName) =>
`https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin-template/docs/rules/${ruleName}.md`,
);