Skip to content

Commit c322743

Browse files
committed
refactor: add explicit return type to createTestingLibraryRule for better type safety
1 parent 4c2bc92 commit c322743

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

lib/create-testing-library-rule/index.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { ESLintUtils } from '@typescript-eslint/utils';
22

3-
import { getDocsUrl, TestingLibraryPluginDocs } from '../utils';
3+
import {
4+
getDocsUrl,
5+
TestingLibraryPluginDocs,
6+
TestingLibraryPluginRuleModule,
7+
} from '../utils';
48

59
import {
610
DetectionOptions,
@@ -27,11 +31,20 @@ export const createTestingLibraryRule = <
2731
create: EnhancedRuleCreate<TMessageIds, TOptions>;
2832
detectionOptions?: Partial<DetectionOptions>;
2933
}
30-
>) =>
31-
ESLintUtils.RuleCreator<TestingLibraryPluginDocs<TOptions>>(getDocsUrl)({
34+
>): TestingLibraryPluginRuleModule<TMessageIds, TOptions> => {
35+
const rule = ESLintUtils.RuleCreator<TestingLibraryPluginDocs<TOptions>>(
36+
getDocsUrl
37+
)({
3238
...remainingConfig,
3339
create: detectTestingLibraryUtils<TMessageIds, TOptions>(
3440
create,
3541
detectionOptions
3642
),
3743
});
44+
const { docs } = rule.meta;
45+
if (docs === undefined) {
46+
throw new Error('Rule metadata must contain `docs` property');
47+
}
48+
49+
return { ...rule, meta: { ...rule.meta, docs } };
50+
};

0 commit comments

Comments
 (0)