Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

Commit c4df6d2

Browse files
committed
Add rule jsdoc/require-jsdoc
1 parent ebf42df commit c4df6d2

File tree

3 files changed

+172
-1
lines changed

3 files changed

+172
-1
lines changed

.eslintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,14 @@ module.exports = defineConfig({
8888
'backtick',
8989
'backticks',
9090
'browserify',
91+
'cjs',
9192
'commonjs',
9293
'dom',
9394
'ecma',
9495
'embertest',
96+
'esm',
9597
'esnext',
98+
'getters',
9699
'globals',
97100
'greasemonkey',
98101
'inferrable',

src/rules/jsdoc/index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import type { MatchDescriptionRule } from './match-description';
22
import type { NoTypesRule } from './no-types';
3+
import type { RequireJsdocRule } from './require-jsdoc';
34

45
/**
56
* All jsdoc rules.
67
*/
7-
export type JSDocRules = MatchDescriptionRule & NoTypesRule;
8+
export type JSDocRules = MatchDescriptionRule & NoTypesRule & RequireJsdocRule;

src/rules/jsdoc/require-jsdoc.d.ts

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
import type { RuleConfig } from '../rule-config';
2+
3+
/**
4+
* Option.
5+
*/
6+
export type RequireJsdocOption = {
7+
/**
8+
* Set this to an array of strings or objects representing the additional AST contexts where you wish the rule to be applied (e.g., `Property` for properties).
9+
*
10+
* If specified as an object, it should have a `context` property and can have an `inlineCommentBlock` property which, if set to `true`, will add an inline `doc-comment` instead of the regular, multi-line, indented jsdoc block which will otherwise be added.
11+
*
12+
* Note that you may need to disable `require` items (e.g., `MethodDefinition`) if you are specifying a more precise form in `contexts` (e.g., `MethodDefinition:not([accessibility="private"])`).
13+
*
14+
* See the ["AST and Selectors"](https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-advanced-ast-and-selectors) section of our README for more on the expected format.
15+
*
16+
* @default []
17+
*
18+
* @see [contexts](https://github.com/gajus/eslint-plugin-jsdoc#contexts-5)
19+
*/
20+
contexts?: Array<
21+
| string
22+
| {
23+
context: string;
24+
inlineCommentBlock?: boolean;
25+
}
26+
>;
27+
/**
28+
* @see [publicOnly](https://github.com/gajus/eslint-plugin-jsdoc#publiconly)
29+
*/
30+
publicOnly?: {
31+
/**
32+
* Only check node ancestors to check if node is exported.
33+
*
34+
* @default false
35+
*/
36+
ancestorsOnly?: boolean;
37+
/**
38+
* ESM exports are checked for JSDoc comments.
39+
*
40+
* @default true
41+
*/
42+
esm?: boolean;
43+
/**
44+
* CommonJS exports are checked for JSDoc comments.
45+
*
46+
* @default true
47+
*/
48+
cjs?: boolean;
49+
/**
50+
* Window global exports are checked for JSDoc comments.
51+
*
52+
* @default false
53+
*/
54+
window?: boolean;
55+
};
56+
/**
57+
* An object with the following optional boolean keys which all default to `false` except as noted, indicating the contexts where the rule will apply.
58+
*
59+
* @see [require](https://github.com/gajus/eslint-plugin-jsdoc#require)
60+
*/
61+
require?: {
62+
/**
63+
* @default false
64+
*/
65+
ArrowFunctionExpression?: boolean;
66+
/**
67+
* @default false
68+
*/
69+
ClassDeclaration?: boolean;
70+
/**
71+
* @default false
72+
*/
73+
ClassExpression?: boolean;
74+
/**
75+
* @default true
76+
*/
77+
FunctionDeclaration?: boolean;
78+
/**
79+
* @default false
80+
*/
81+
FunctionExpression?: boolean;
82+
/**
83+
* @default false
84+
*/
85+
MethodDefinition?: boolean;
86+
};
87+
/**
88+
* When `true`, the rule will not report missing jsdoc blocks above constructors with no parameters or return values (this is enabled by default as the class name or description should be seen as sufficient to convey intent).
89+
*
90+
* @default true
91+
*
92+
* @see [exemptEmptyConstructors](https://github.com/gajus/eslint-plugin-jsdoc#exemptemptyconstructors)
93+
*/
94+
exemptEmptyConstructors?: boolean;
95+
/**
96+
* When `true`, the rule will not report missing jsdoc blocks above functions/methods with no parameters or return values (intended where function/method names are sufficient for themselves as documentation).
97+
*
98+
* @default false
99+
*
100+
* @see [exemptEmptyFunctions](https://github.com/gajus/eslint-plugin-jsdoc#exemptemptyfunctions)
101+
*/
102+
exemptEmptyFunctions?: boolean;
103+
/**
104+
* A value indicating whether `constructors` should be checked.
105+
*
106+
* When `true`, `exemptEmptyConstructors` may still avoid reporting when no parameters or return values are found.
107+
*
108+
* @default true
109+
*
110+
* @see [checkConstructors](https://github.com/gajus/eslint-plugin-jsdoc#checkconstructors)
111+
*/
112+
checkConstructors?: boolean;
113+
/**
114+
* A value indicating whether getters should be checked.
115+
*
116+
* Besides setting as a boolean, this option can be set to the string `"no-setter"` to indicate that getters should be checked but only when there is no setter. This may be useful if one only wishes documentation on one of the two accessors.
117+
*
118+
* @default false
119+
*
120+
* @see [checkGetters](https://github.com/gajus/eslint-plugin-jsdoc#checkgetters)
121+
*/
122+
checkGetters?: boolean;
123+
/**
124+
* A value indicating whether setters should be checked.
125+
*
126+
* Besides setting as a boolean, this option can be set to the string `"no-getter"` to indicate that setters should be checked but only when there is no getter. This may be useful if one only wishes documentation on one of the two accessors.
127+
*
128+
* @default false
129+
*
130+
* @see [checkSetters](https://github.com/gajus/eslint-plugin-jsdoc#checksetters)
131+
*/
132+
checkSetters?: boolean;
133+
/**
134+
* A boolean on whether to enable the fixer (which adds an empty jsdoc block).
135+
*
136+
* @default true
137+
*
138+
* @see [enableFixer](https://github.com/gajus/eslint-plugin-jsdoc#enablefixer)
139+
*/
140+
enableFixer?: boolean;
141+
};
142+
143+
/**
144+
* Options.
145+
*/
146+
export type RequireJsdocOptions = [RequireJsdocOption?];
147+
148+
/**
149+
* Checks for presence of jsdoc comments, on class declarations as well as functions.
150+
*
151+
* @see [require-jsdoc](https://github.com/gajus/eslint-plugin-jsdoc#require-jsdoc)
152+
*/
153+
export type RequireJsdocRuleConfig = RuleConfig<RequireJsdocOptions>;
154+
155+
/**
156+
* Checks for presence of jsdoc comments, on class declarations as well as functions.
157+
*
158+
* @see [require-jsdoc](https://github.com/gajus/eslint-plugin-jsdoc#require-jsdoc)
159+
*/
160+
export interface RequireJsdocRule {
161+
/**
162+
* Checks for presence of jsdoc comments, on class declarations as well as functions.
163+
*
164+
* @see [require-jsdoc](https://github.com/gajus/eslint-plugin-jsdoc#require-jsdoc)
165+
*/
166+
'jsdoc/require-jsdoc': RequireJsdocRuleConfig;
167+
}

0 commit comments

Comments
 (0)