eslint-plugin-jsdoc 57.2.1 → 58.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/buildRejectOrPreferRuleDefinition.cjs +349 -0
- package/dist/buildRejectOrPreferRuleDefinition.cjs.map +1 -0
- package/dist/buildRejectOrPreferRuleDefinition.d.ts +9 -0
- package/dist/cjs/buildRejectOrPreferRuleDefinition.d.ts +8 -0
- package/dist/cjs/rules/checkTypes.d.ts +6 -1
- package/dist/index-cjs.cjs +33 -3
- package/dist/index-cjs.cjs.map +1 -1
- package/dist/index-esm.cjs +29 -1
- package/dist/index-esm.cjs.map +1 -1
- package/dist/index-esm.d.ts +28 -2
- package/dist/index.cjs +61 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +28 -2
- package/dist/rules/checkTypes.cjs +73 -379
- package/dist/rules/checkTypes.cjs.map +1 -1
- package/dist/rules/checkTypes.d.ts +6 -1
- package/dist/rules/requireParam.cjs +13 -0
- package/dist/rules/requireParam.cjs.map +1 -1
- package/dist/rules.d.ts +10 -3
- package/package.json +1 -1
- package/src/buildRejectOrPreferRuleDefinition.js +472 -0
- package/src/index-cjs.js +35 -3
- package/src/index-esm.js +36 -1
- package/src/index.js +68 -4
- package/src/rules/checkTypes.js +82 -511
- package/src/rules/requireParam.js +20 -0
- package/src/rules.d.ts +10 -3
package/src/index-cjs.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildForbidRuleDefinition,
|
|
3
3
|
} from './buildForbidRuleDefinition.js';
|
|
4
|
+
import {
|
|
5
|
+
buildRejectOrPreferRuleDefinition,
|
|
6
|
+
} from './buildRejectOrPreferRuleDefinition.js';
|
|
4
7
|
import {
|
|
5
8
|
getJsdocProcessorPlugin,
|
|
6
9
|
} from './getJsdocProcessorPlugin.js';
|
|
@@ -107,6 +110,33 @@ index.rules = {
|
|
|
107
110
|
'no-restricted-syntax': noRestrictedSyntax,
|
|
108
111
|
'no-types': noTypes,
|
|
109
112
|
'no-undefined-types': noUndefinedTypes,
|
|
113
|
+
'reject-any-type': buildRejectOrPreferRuleDefinition({
|
|
114
|
+
description: 'Reports use of `any` or `*` type',
|
|
115
|
+
overrideSettings: {
|
|
116
|
+
'*': {
|
|
117
|
+
message: 'Prefer a more specific type to `*`',
|
|
118
|
+
replacement: false,
|
|
119
|
+
unifyParentAndChildTypeChecks: true,
|
|
120
|
+
},
|
|
121
|
+
any: {
|
|
122
|
+
message: 'Prefer a more specific type to `any`',
|
|
123
|
+
replacement: false,
|
|
124
|
+
unifyParentAndChildTypeChecks: true,
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/reject-any-type.md#repos-sticky-header',
|
|
128
|
+
}),
|
|
129
|
+
'reject-function-type': buildRejectOrPreferRuleDefinition({
|
|
130
|
+
description: 'Reports use of `Function` type',
|
|
131
|
+
overrideSettings: {
|
|
132
|
+
Function: {
|
|
133
|
+
message: 'Prefer a more specific type to `Function`',
|
|
134
|
+
replacement: false,
|
|
135
|
+
unifyParentAndChildTypeChecks: true,
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/reject-function-type.md#repos-sticky-header',
|
|
139
|
+
}),
|
|
110
140
|
'require-asterisk-prefix': requireAsteriskPrefix,
|
|
111
141
|
'require-description': requireDescription,
|
|
112
142
|
'require-description-complete-sentence': requireDescriptionCompleteSentence,
|
|
@@ -122,7 +152,7 @@ index.rules = {
|
|
|
122
152
|
message: '@next should have a type',
|
|
123
153
|
},
|
|
124
154
|
],
|
|
125
|
-
description: 'Requires a type for
|
|
155
|
+
description: 'Requires a type for `@next` tags',
|
|
126
156
|
url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-next-type.md#repos-sticky-header',
|
|
127
157
|
}),
|
|
128
158
|
'require-param': requireParam,
|
|
@@ -147,7 +177,7 @@ index.rules = {
|
|
|
147
177
|
message: '@throws should have a type',
|
|
148
178
|
},
|
|
149
179
|
],
|
|
150
|
-
description: 'Requires a type for
|
|
180
|
+
description: 'Requires a type for `@throws` tags',
|
|
151
181
|
url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-throws-type.md#repos-sticky-header',
|
|
152
182
|
}),
|
|
153
183
|
'require-yields': requireYields,
|
|
@@ -160,7 +190,7 @@ index.rules = {
|
|
|
160
190
|
message: '@yields should have a type',
|
|
161
191
|
},
|
|
162
192
|
],
|
|
163
|
-
description: 'Requires a type for
|
|
193
|
+
description: 'Requires a type for `@yields` tags',
|
|
164
194
|
url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-yields-type.md#repos-sticky-header',
|
|
165
195
|
}),
|
|
166
196
|
'sort-tags': sortTags,
|
|
@@ -218,6 +248,8 @@ const createRecommendedRuleset = (warnOrError, flatName) => {
|
|
|
218
248
|
'jsdoc/no-restricted-syntax': 'off',
|
|
219
249
|
'jsdoc/no-types': 'off',
|
|
220
250
|
'jsdoc/no-undefined-types': warnOrError,
|
|
251
|
+
'jsdoc/reject-any-type': warnOrError,
|
|
252
|
+
'jsdoc/reject-function-type': warnOrError,
|
|
221
253
|
'jsdoc/require-asterisk-prefix': 'off',
|
|
222
254
|
'jsdoc/require-description': 'off',
|
|
223
255
|
'jsdoc/require-description-complete-sentence': 'off',
|
package/src/index-esm.js
CHANGED
|
@@ -8,6 +8,9 @@ import index from './index-cjs.js';
|
|
|
8
8
|
import {
|
|
9
9
|
buildForbidRuleDefinition,
|
|
10
10
|
} from './buildForbidRuleDefinition.js';
|
|
11
|
+
import {
|
|
12
|
+
buildRejectOrPreferRuleDefinition,
|
|
13
|
+
} from './buildRejectOrPreferRuleDefinition.js';
|
|
11
14
|
|
|
12
15
|
// eslint-disable-next-line unicorn/prefer-export-from --- Reusing `index`
|
|
13
16
|
export default index;
|
|
@@ -22,7 +25,7 @@ export default index;
|
|
|
22
25
|
* settings?: Partial<import('./iterateJsdoc.js').Settings>,
|
|
23
26
|
* rules?: {[key in keyof import('./rules.d.ts').Rules]?: import('eslint').Linter.RuleEntry<import('./rules.d.ts').Rules[key]>},
|
|
24
27
|
* extraRuleDefinitions?: {
|
|
25
|
-
* forbid
|
|
28
|
+
* forbid?: {
|
|
26
29
|
* [contextName: string]: {
|
|
27
30
|
* description?: string,
|
|
28
31
|
* url?: string,
|
|
@@ -32,6 +35,19 @@ export default index;
|
|
|
32
35
|
* comment: string
|
|
33
36
|
* })[]
|
|
34
37
|
* }
|
|
38
|
+
* },
|
|
39
|
+
* preferTypes?: {
|
|
40
|
+
* [typeName: string]: {
|
|
41
|
+
* description: string,
|
|
42
|
+
* overrideSettings: {
|
|
43
|
+
* [typeNodeName: string]: {
|
|
44
|
+
* message: string,
|
|
45
|
+
* replacement?: false|string,
|
|
46
|
+
* unifyParentAndChildTypeChecks?: boolean,
|
|
47
|
+
* }
|
|
48
|
+
* },
|
|
49
|
+
* url: string,
|
|
50
|
+
* }
|
|
35
51
|
* }
|
|
36
52
|
* }
|
|
37
53
|
* }
|
|
@@ -125,6 +141,25 @@ export const jsdoc = function (cfg) {
|
|
|
125
141
|
});
|
|
126
142
|
}
|
|
127
143
|
}
|
|
144
|
+
|
|
145
|
+
if (cfg.extraRuleDefinitions.preferTypes) {
|
|
146
|
+
for (const [
|
|
147
|
+
typeName,
|
|
148
|
+
{
|
|
149
|
+
description,
|
|
150
|
+
overrideSettings,
|
|
151
|
+
url,
|
|
152
|
+
},
|
|
153
|
+
] of Object.entries(cfg.extraRuleDefinitions.preferTypes)) {
|
|
154
|
+
outputConfig.plugins.jsdoc.rules[`prefer-type-${typeName}`] =
|
|
155
|
+
buildRejectOrPreferRuleDefinition({
|
|
156
|
+
description,
|
|
157
|
+
overrideSettings,
|
|
158
|
+
typeName,
|
|
159
|
+
url,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
128
163
|
}
|
|
129
164
|
}
|
|
130
165
|
|
package/src/index.js
CHANGED
|
@@ -7,6 +7,9 @@ import {
|
|
|
7
7
|
import {
|
|
8
8
|
buildForbidRuleDefinition,
|
|
9
9
|
} from './buildForbidRuleDefinition.js';
|
|
10
|
+
import {
|
|
11
|
+
buildRejectOrPreferRuleDefinition,
|
|
12
|
+
} from './buildRejectOrPreferRuleDefinition.js';
|
|
10
13
|
import {
|
|
11
14
|
getJsdocProcessorPlugin,
|
|
12
15
|
} from './getJsdocProcessorPlugin.js';
|
|
@@ -113,6 +116,33 @@ index.rules = {
|
|
|
113
116
|
'no-restricted-syntax': noRestrictedSyntax,
|
|
114
117
|
'no-types': noTypes,
|
|
115
118
|
'no-undefined-types': noUndefinedTypes,
|
|
119
|
+
'reject-any-type': buildRejectOrPreferRuleDefinition({
|
|
120
|
+
description: 'Reports use of `any` or `*` type',
|
|
121
|
+
overrideSettings: {
|
|
122
|
+
'*': {
|
|
123
|
+
message: 'Prefer a more specific type to `*`',
|
|
124
|
+
replacement: false,
|
|
125
|
+
unifyParentAndChildTypeChecks: true,
|
|
126
|
+
},
|
|
127
|
+
any: {
|
|
128
|
+
message: 'Prefer a more specific type to `any`',
|
|
129
|
+
replacement: false,
|
|
130
|
+
unifyParentAndChildTypeChecks: true,
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/reject-any-type.md#repos-sticky-header',
|
|
134
|
+
}),
|
|
135
|
+
'reject-function-type': buildRejectOrPreferRuleDefinition({
|
|
136
|
+
description: 'Reports use of `Function` type',
|
|
137
|
+
overrideSettings: {
|
|
138
|
+
Function: {
|
|
139
|
+
message: 'Prefer a more specific type to `Function`',
|
|
140
|
+
replacement: false,
|
|
141
|
+
unifyParentAndChildTypeChecks: true,
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/reject-function-type.md#repos-sticky-header',
|
|
145
|
+
}),
|
|
116
146
|
'require-asterisk-prefix': requireAsteriskPrefix,
|
|
117
147
|
'require-description': requireDescription,
|
|
118
148
|
'require-description-complete-sentence': requireDescriptionCompleteSentence,
|
|
@@ -128,7 +158,7 @@ index.rules = {
|
|
|
128
158
|
message: '@next should have a type',
|
|
129
159
|
},
|
|
130
160
|
],
|
|
131
|
-
description: 'Requires a type for
|
|
161
|
+
description: 'Requires a type for `@next` tags',
|
|
132
162
|
url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-next-type.md#repos-sticky-header',
|
|
133
163
|
}),
|
|
134
164
|
'require-param': requireParam,
|
|
@@ -153,7 +183,7 @@ index.rules = {
|
|
|
153
183
|
message: '@throws should have a type',
|
|
154
184
|
},
|
|
155
185
|
],
|
|
156
|
-
description: 'Requires a type for
|
|
186
|
+
description: 'Requires a type for `@throws` tags',
|
|
157
187
|
url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-throws-type.md#repos-sticky-header',
|
|
158
188
|
}),
|
|
159
189
|
'require-yields': requireYields,
|
|
@@ -166,7 +196,7 @@ index.rules = {
|
|
|
166
196
|
message: '@yields should have a type',
|
|
167
197
|
},
|
|
168
198
|
],
|
|
169
|
-
description: 'Requires a type for
|
|
199
|
+
description: 'Requires a type for `@yields` tags',
|
|
170
200
|
url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-yields-type.md#repos-sticky-header',
|
|
171
201
|
}),
|
|
172
202
|
'sort-tags': sortTags,
|
|
@@ -224,6 +254,8 @@ const createRecommendedRuleset = (warnOrError, flatName) => {
|
|
|
224
254
|
'jsdoc/no-restricted-syntax': 'off',
|
|
225
255
|
'jsdoc/no-types': 'off',
|
|
226
256
|
'jsdoc/no-undefined-types': warnOrError,
|
|
257
|
+
'jsdoc/reject-any-type': warnOrError,
|
|
258
|
+
'jsdoc/reject-function-type': warnOrError,
|
|
227
259
|
'jsdoc/require-asterisk-prefix': 'off',
|
|
228
260
|
'jsdoc/require-description': 'off',
|
|
229
261
|
'jsdoc/require-description-complete-sentence': 'off',
|
|
@@ -609,7 +641,7 @@ export default index;
|
|
|
609
641
|
* settings?: Partial<import('./iterateJsdoc.js').Settings>,
|
|
610
642
|
* rules?: {[key in keyof import('./rules.d.ts').Rules]?: import('eslint').Linter.RuleEntry<import('./rules.d.ts').Rules[key]>},
|
|
611
643
|
* extraRuleDefinitions?: {
|
|
612
|
-
* forbid
|
|
644
|
+
* forbid?: {
|
|
613
645
|
* [contextName: string]: {
|
|
614
646
|
* description?: string,
|
|
615
647
|
* url?: string,
|
|
@@ -619,6 +651,19 @@ export default index;
|
|
|
619
651
|
* comment: string
|
|
620
652
|
* })[]
|
|
621
653
|
* }
|
|
654
|
+
* },
|
|
655
|
+
* preferTypes?: {
|
|
656
|
+
* [typeName: string]: {
|
|
657
|
+
* description: string,
|
|
658
|
+
* overrideSettings: {
|
|
659
|
+
* [typeNodeName: string]: {
|
|
660
|
+
* message: string,
|
|
661
|
+
* replacement?: false|string,
|
|
662
|
+
* unifyParentAndChildTypeChecks?: boolean,
|
|
663
|
+
* }
|
|
664
|
+
* },
|
|
665
|
+
* url: string,
|
|
666
|
+
* }
|
|
622
667
|
* }
|
|
623
668
|
* }
|
|
624
669
|
* }
|
|
@@ -712,6 +757,25 @@ export const jsdoc = function (cfg) {
|
|
|
712
757
|
});
|
|
713
758
|
}
|
|
714
759
|
}
|
|
760
|
+
|
|
761
|
+
if (cfg.extraRuleDefinitions.preferTypes) {
|
|
762
|
+
for (const [
|
|
763
|
+
typeName,
|
|
764
|
+
{
|
|
765
|
+
description,
|
|
766
|
+
overrideSettings,
|
|
767
|
+
url,
|
|
768
|
+
},
|
|
769
|
+
] of Object.entries(cfg.extraRuleDefinitions.preferTypes)) {
|
|
770
|
+
outputConfig.plugins.jsdoc.rules[`prefer-type-${typeName}`] =
|
|
771
|
+
buildRejectOrPreferRuleDefinition({
|
|
772
|
+
description,
|
|
773
|
+
overrideSettings,
|
|
774
|
+
typeName,
|
|
775
|
+
url,
|
|
776
|
+
});
|
|
777
|
+
}
|
|
778
|
+
}
|
|
715
779
|
}
|
|
716
780
|
}
|
|
717
781
|
|