Skip to content

Commit c21a3f3

Browse files
authored
fix(typescript): ensure rules without a schema are represented as well (#1518)
1 parent 224bbe6 commit c21a3f3

File tree

3 files changed

+71
-37
lines changed

3 files changed

+71
-37
lines changed

src/bin/generateRuleTypes.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,20 @@ for (const [
1212
ruleName,
1313
rule,
1414
] of Object.entries(index.rules)) {
15-
if (rule.meta?.schema?.[0]) {
16-
str += ` /** ${rule.meta.docs.description} */\n`;
17-
str += ` "jsdoc/${ruleName}": `;
18-
const ts = await compile({
19-
items: rule.meta.schema,
20-
type: 'array',
21-
}, 'Test', {
22-
bannerComment: '',
23-
});
15+
str += ` /** ${rule.meta.docs.description} */\n`;
16+
str += ` "jsdoc/${ruleName}": `;
17+
const ts = await compile({
18+
items: rule.meta.schema ?? [],
19+
type: 'array',
20+
}, 'Test', {
21+
bannerComment: '',
22+
});
2423

25-
str += ts
26-
.replace(/^export type Test = ?/v, '')
27-
.replace(/^export interface Test /v, '')
28-
.replaceAll('\n', '\n ').trimEnd().replace(/;$/v, '') +
29-
';\n\n';
30-
}
24+
str += ts
25+
.replace(/^export type Test = ?/v, '')
26+
.replace(/^export interface Test /v, '')
27+
.replaceAll('\n', '\n ').trimEnd().replace(/;$/v, '') +
28+
';\n\n';
3129
}
3230

3331
str = str.replace(/\n$/v, '') + '}\n';

src/rules.d.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
export interface Rules {
2+
/** Checks that `@access` tags have a valid value. */
3+
"jsdoc/check-access": [];
4+
25
/** Reports invalid alignment of JSDoc block asterisks. */
36
"jsdoc/check-alignment":
47
| []
@@ -90,6 +93,9 @@ export interface Rules {
9093
}
9194
];
9295

96+
/** Reports against syntax not valid for the mode (e.g., Google Closure Compiler in non-Closure mode). */
97+
"jsdoc/check-syntax": [];
98+
9399
/** Reports invalid block tag names. */
94100
"jsdoc/check-tag-names":
95101
| []
@@ -102,6 +108,9 @@ export interface Rules {
102108
}
103109
];
104110

111+
/** Checks that any `@template` names are actually used in the connected `@typedef` or type alias. */
112+
"jsdoc/check-template-names": [];
113+
105114
/** Reports invalid types. */
106115
"jsdoc/check-types":
107116
| []
@@ -188,6 +197,9 @@ export interface Rules {
188197
}
189198
];
190199

200+
/** Reports if JSDoc `import()` statements point to a package which is not listed in `dependencies` or `devDependencies` */
201+
"jsdoc/imports-as-dependencies": [];
202+
191203
/** This rule reports doc comments that only restate their attached name. */
192204
"jsdoc/informative-docs":
193205
| []
@@ -300,6 +312,9 @@ export interface Rules {
300312
}
301313
];
302314

315+
/** Detects and removes extra lines of a blank block description */
316+
"jsdoc/no-blank-block-descriptions": [];
317+
303318
/** Removes empty blocks with nothing but possibly line breaks */
304319
"jsdoc/no-blank-blocks":
305320
| []
@@ -542,6 +557,9 @@ export interface Rules {
542557
}
543558
];
544559

560+
/** Requires a type for @next tags */
561+
"jsdoc/require-next-type": [];
562+
545563
/** Requires that all function parameters are documented. */
546564
"jsdoc/require-param":
547565
| []
@@ -621,6 +639,18 @@ export interface Rules {
621639
}
622640
];
623641

642+
/** Requires that all `@typedef` and `@namespace` tags have `@property` when their type is a plain `object`, `Object`, or `PlainObject`. */
643+
"jsdoc/require-property": [];
644+
645+
/** Requires that each `@property` tag has a `description` value. */
646+
"jsdoc/require-property-description": [];
647+
648+
/** Requires that all function `@property` tags have names. */
649+
"jsdoc/require-property-name": [];
650+
651+
/** Requires that each `@property` tag has a `type` value. */
652+
"jsdoc/require-property-type": [];
653+
624654
/** Requires that returns are documented. */
625655
"jsdoc/require-returns":
626656
| []
@@ -718,6 +748,9 @@ export interface Rules {
718748
}
719749
];
720750

751+
/** Requires a type for @throws tags */
752+
"jsdoc/require-throws-type": [];
753+
721754
/** Requires yields are documented. */
722755
"jsdoc/require-yields":
723756
| []
@@ -757,6 +790,9 @@ export interface Rules {
757790
}
758791
];
759792

793+
/** Requires a type for @yields tags */
794+
"jsdoc/require-yields-type": [];
795+
760796
/** Sorts tags by a specified sequence according to tag name. */
761797
"jsdoc/sort-tags":
762798
| []

src/rules/checkTypes.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,28 @@ const getMessage = (upperCase) => {
8888
'`' + (upperCase ? 'O' : 'o') + 'bject`, e.g., `{[key: string]: string}`';
8989
};
9090

91+
/**
92+
* @type {{
93+
* message: string,
94+
* replacement: false
95+
* }}
96+
*/
97+
const info = {
98+
message: getMessage(),
99+
replacement: false,
100+
};
101+
102+
/**
103+
* @type {{
104+
* message: string,
105+
* replacement: false
106+
* }}
107+
*/
108+
const infoUC = {
109+
message: getMessage(true),
110+
replacement: false,
111+
};
112+
91113
export default iterateJsdoc(({
92114
context,
93115
jsdocNode,
@@ -120,28 +142,6 @@ export default iterateJsdoc(({
120142
'Object.<>' in preferredTypesOriginal ||
121143
'object<>' in preferredTypesOriginal);
122144

123-
/**
124-
* @type {{
125-
* message: string,
126-
* replacement: false
127-
* }}
128-
*/
129-
const info = {
130-
message: getMessage(),
131-
replacement: false,
132-
};
133-
134-
/**
135-
* @type {{
136-
* message: string,
137-
* replacement: false
138-
* }}
139-
*/
140-
const infoUC = {
141-
message: getMessage(true),
142-
replacement: false,
143-
};
144-
145145
/** @type {import('../iterateJsdoc.js').PreferredTypes} */
146146
const typeToInject = mode === 'typescript' ?
147147
{

0 commit comments

Comments
 (0)