Skip to content

Commit b9d88f0

Browse files
feat: compiled types now include inlined literal docs
Things like `description` and `recommended` are now visible in the types/intellisense directly, instead of needing to read the source code.
1 parent d9120ae commit b9d88f0

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/utils/rule-creator.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
import { ESLintUtils, TSESLint } from '@typescript-eslint/utils';
22
import { version } from '../../package.json';
33

4-
export interface RxjsXRuleDocs<Options extends readonly unknown[]> {
5-
description: string;
4+
export interface RxjsXRuleDocs<Options extends readonly unknown[], Desc extends string> {
5+
description: Desc;
66
recommended?: TSESLint.RuleRecommendation | TSESLint.RuleRecommendationAcrossConfigs<Options>;
77
requiresTypeChecking?: boolean;
88
}
99

1010
const REPO_URL = 'https://github.com/JasonWeinzierl/eslint-plugin-rxjs-x';
1111

12-
export const ruleCreator = ESLintUtils.RuleCreator<RxjsXRuleDocs<unknown[]>>(
12+
export const ruleCreator = ESLintUtils.RuleCreator<RxjsXRuleDocs<unknown[], string>>(
1313
(name) =>
1414
`${REPO_URL}/blob/v${version}/docs/rules/${name}.md`,
1515
// Ensure the Options type is passed to RxjsXRuleDocs.
1616
) as <
1717
Options extends readonly unknown[],
1818
MessageIds extends string,
19-
>({ meta, name, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<Options, MessageIds, RxjsXRuleDocs<Options>>>) => TSESLint.RuleModule<MessageIds, Options, RxjsXRuleDocs<Options>>;
19+
Desc extends string,
20+
Docs extends RxjsXRuleDocs<Options, Desc>,
21+
>({ meta, name, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<Options, MessageIds, Docs>>) => TSESLint.RuleModule<MessageIds, Options, Docs>;

tests/package.test.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from 'node:fs/promises';
22
import path from 'node:path';
33
import plugin from '../src';
4+
import { RxjsXRuleDocs } from '../src/utils';
45

56
function isSourceFile(value: string): boolean {
67
const ext = path.extname(value);
@@ -51,14 +52,16 @@ describe('package', () => {
5152
const namespace = 'rxjs-x';
5253
const fullRuleName = `${namespace}/${ruleName}`;
5354

54-
if (!rule.meta.docs?.recommended) {
55+
const ruleRec = (rule.meta.docs as RxjsXRuleDocs<unknown[], string>)?.recommended;
56+
57+
if (!ruleRec) {
5558
// Rule is not included in any configuration.
5659
expect(plugin.configs.recommended.rules).not.toHaveProperty(fullRuleName);
5760
expect(plugin.configs.strict.rules).not.toHaveProperty(fullRuleName);
58-
} else if (typeof rule.meta.docs.recommended === 'string') {
61+
} else if (typeof ruleRec === 'string') {
5962
// Rule specifies only a configuration name.
60-
expect(rule.meta.docs.recommended).toMatch(/^(recommended|strict)$/);
61-
if (rule.meta.docs.recommended === 'recommended') {
63+
expect(ruleRec).toMatch(/^(recommended|strict)$/);
64+
if (ruleRec === 'recommended') {
6265
expect(plugin.configs.recommended.rules).toHaveProperty(fullRuleName);
6366
} else {
6467
expect(plugin.configs.recommended.rules).not.toHaveProperty(fullRuleName);
@@ -69,12 +72,12 @@ describe('package', () => {
6972
expect(plugin.configs.strict.rules).toHaveProperty(fullRuleName, expect.any(String));
7073
} else {
7174
// Rule specifies non-default options for strict.
72-
if (rule.meta.docs.recommended.recommended) {
75+
if (ruleRec.recommended) {
7376
expect(plugin.configs.recommended.rules).toHaveProperty(fullRuleName);
7477
} else {
7578
expect(plugin.configs.recommended.rules).not.toHaveProperty(fullRuleName);
7679
}
77-
expect(plugin.configs.strict.rules).toHaveProperty(fullRuleName, [expect.any(String), rule.meta.docs.recommended.strict[0]]);
80+
expect(plugin.configs.strict.rules).toHaveProperty(fullRuleName, [expect.any(String), ruleRec.strict[0]]);
7881
}
7982
});
8083
});

0 commit comments

Comments
 (0)