Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

Commit

Permalink
Make the exported rules a typed record (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmorand-sonarsource authored May 2, 2024
1 parent 1efe2da commit d5a1f12
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import * as preferObjectLiteral from './rules/prefer-object-literal';
import * as preferSingleBooleanReturn from './rules/prefer-single-boolean-return';
import * as preferWhile from './rules/prefer-while';

export const rules: Record<string, TSESLint.RuleModule<string, Array<unknown>>> = {
export const rules = {
'cognitive-complexity': cognitiveComplexity,
'elseif-without-else': elseifWithoutElse,
'max-switch-cases': maxSwitchCases,
Expand Down Expand Up @@ -98,7 +98,7 @@ const recommendedConfig: FlatConfig.Config = {
};

for (const key in rules) {
const rule = rules[key];
const rule = rules[key as keyof typeof rules];
const recommended = rule.meta.docs?.recommended;

recommendedConfig.rules![`sonarjs/${key}`] = recommended === undefined ? 'off' : 'error';
Expand Down
2 changes: 1 addition & 1 deletion tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ it('should document all rules', () => {
existingRules.forEach(rule => {
expect(README.includes(rule)).toBe(true);
expect(fs.existsSync(`${root}/docs/rules/${rule}.md`)).toBe(true);
expect(rules[rule].meta.docs!.url).toBe(
expect(rules[rule as keyof typeof rules].meta.docs!.url).toBe(
`https://github.com/SonarSource/eslint-plugin-sonarjs/blob/master/docs/rules/${rule}.md`,
);
});
Expand Down

0 comments on commit d5a1f12

Please sign in to comment.