Skip to content

Commit d5fa8da

Browse files
committedJul 9, 2024
feat: new rule convert-to-jsdoc-comments; fixes #1002
1 parent 394b85f commit d5fa8da

9 files changed

+844
-4
lines changed
 
+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# `convert-to-jsdoc-comments`
2+
3+
Converts single line or non-JSDoc, multiline comments into JSDoc comments.
4+
5+
## Options
6+
7+
### `enableFixer`
8+
9+
Set to `false` to disable fixing.
10+
11+
### `lineOrBlockStyle`
12+
13+
What style of comments to which to apply JSDoc conversion.
14+
15+
- `block` - Applies to block-style comments (`/* ... */`)
16+
- `line` - Applies to line-style comments (`// ...`)
17+
- `both` - Applies to both block and line-style comments
18+
19+
Defaults to `both`.
20+
21+
### `enforceJsdocLineStyle`
22+
23+
What policy to enforce on the conversion of non-JSDoc comments without
24+
line breaks. (Non-JSDoc (mulitline) comments with line breaks will always
25+
be converted to `multi` style JSDoc comments.)
26+
27+
- `multi` - Convert to multi-line style
28+
```js
29+
/**
30+
* Some text
31+
*/
32+
```
33+
- `single` - Convert to single-line style
34+
```js
35+
/** Some text */
36+
```
37+
38+
Defaults to `multi`.
39+
40+
### `allowedPrefixes`
41+
42+
An array of prefixes to allow at the beginning of a comment.
43+
44+
Defaults to `['@ts-', 'istanbul ', 'c8 ', 'v8 ', 'eslint', 'prettier-']`.
45+
46+
Supplying your own value overrides the defaults.
47+
48+
|||
49+
|---|---|
50+
|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`|
51+
|Tags|(N/A)|
52+
|Recommended|false|
53+
|Settings|`minLines`, `maxLines`|
54+
|Options|`enableFixer`, `enforceJsdocLineStyle`, `lineOrBlockStyle`|
55+
56+
## Failing examples
57+
58+
<!-- assertions-failing convertToJsdocComments -->
59+
60+
## Passing examples
61+
62+
<!-- assertions-passing convertToJsdocComments -->
+179
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
<a name="user-content-convert-to-jsdoc-comments"></a>
2+
<a name="convert-to-jsdoc-comments"></a>
3+
# <code>convert-to-jsdoc-comments</code>
4+
5+
Converts single line or non-JSDoc, multiline comments into JSDoc comments.
6+
7+
<a name="user-content-convert-to-jsdoc-comments-options"></a>
8+
<a name="convert-to-jsdoc-comments-options"></a>
9+
## Options
10+
11+
<a name="user-content-convert-to-jsdoc-comments-options-enablefixer"></a>
12+
<a name="convert-to-jsdoc-comments-options-enablefixer"></a>
13+
### <code>enableFixer</code>
14+
15+
Set to `false` to disable fixing.
16+
17+
<a name="user-content-convert-to-jsdoc-comments-options-lineorblockstyle"></a>
18+
<a name="convert-to-jsdoc-comments-options-lineorblockstyle"></a>
19+
### <code>lineOrBlockStyle</code>
20+
21+
What style of comments to which to apply JSDoc conversion.
22+
23+
- `block` - Applies to block-style comments (`/* ... */`)
24+
- `line` - Applies to line-style comments (`// ...`)
25+
- `both` - Applies to both block and line-style comments
26+
27+
Defaults to `both`.
28+
29+
<a name="user-content-convert-to-jsdoc-comments-options-enforcejsdoclinestyle"></a>
30+
<a name="convert-to-jsdoc-comments-options-enforcejsdoclinestyle"></a>
31+
### <code>enforceJsdocLineStyle</code>
32+
33+
What policy to enforce on the conversion of non-JSDoc comments without
34+
line breaks. (Non-JSDoc (mulitline) comments with line breaks will always
35+
be converted to `multi` style JSDoc comments.)
36+
37+
- `multi` - Convert to multi-line style
38+
```js
39+
/**
40+
* Some text
41+
*/
42+
```
43+
- `single` - Convert to single-line style
44+
```js
45+
/** Some text */
46+
```
47+
48+
Defaults to `multi`.
49+
50+
<a name="user-content-convert-to-jsdoc-comments-options-allowedprefixes"></a>
51+
<a name="convert-to-jsdoc-comments-options-allowedprefixes"></a>
52+
### <code>allowedPrefixes</code>
53+
54+
An array of prefixes to allow at the beginning of a comment.
55+
56+
Defaults to `['@ts-', 'istanbul ', 'c8 ', 'v8 ', 'eslint', 'prettier-']`.
57+
58+
Supplying your own value overrides the defaults.
59+
60+
|||
61+
|---|---|
62+
|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`|
63+
|Tags|(N/A)|
64+
|Recommended|false|
65+
|Settings|`minLines`, `maxLines`|
66+
|Options|`enableFixer`, `enforceJsdocLineStyle`, `lineOrBlockStyle`|
67+
68+
<a name="user-content-convert-to-jsdoc-comments-failing-examples"></a>
69+
<a name="convert-to-jsdoc-comments-failing-examples"></a>
70+
## Failing examples
71+
72+
The following patterns are considered problems:
73+
74+
````js
75+
// A single line comment
76+
function quux () {}
77+
// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"enforceJsdocLineStyle":"single"}]
78+
// Message: Line comments should be JSDoc-style.
79+
80+
// A single line comment
81+
function quux () {}
82+
// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"contexts":[{"context":"FunctionDeclaration","inlineCommentBlock":true}]}]
83+
// Message: Line comments should be JSDoc-style.
84+
85+
// A single line comment
86+
function quux () {}
87+
// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"enableFixer":false,"enforceJsdocLineStyle":"single"}]
88+
// Message: Line comments should be JSDoc-style.
89+
90+
// A single line comment
91+
function quux () {}
92+
// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"lineOrBlockStyle":"line","enforceJsdocLineStyle":"single"}]
93+
// Message: Line comments should be JSDoc-style.
94+
95+
/* A single line comment */
96+
function quux () {}
97+
// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"enforceJsdocLineStyle":"single"}]
98+
// Message: Block comments should be JSDoc-style.
99+
100+
/* A single line comment */
101+
function quux () {}
102+
// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"lineOrBlockStyle":"block","enforceJsdocLineStyle":"single"}]
103+
// Message: Block comments should be JSDoc-style.
104+
105+
// A single line comment
106+
function quux () {}
107+
// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"enforceJsdocLineStyle":"multi"}]
108+
// Message: Line comments should be JSDoc-style.
109+
110+
// A single line comment
111+
function quux () {}
112+
// Message: Line comments should be JSDoc-style.
113+
114+
/* A single line comment */
115+
function quux () {}
116+
// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"enforceJsdocLineStyle":"multi"}]
117+
// Message: Block comments should be JSDoc-style.
118+
119+
// Single line comment
120+
function quux() {
121+
122+
}
123+
// Settings: {"jsdoc":{"structuredTags":{"see":{"name":false,"required":["name"]}}}}
124+
// Message: Cannot add "name" to `require` with the tag's `name` set to `false`
125+
126+
/* Entity to represent a user in the system. */
127+
@Entity('users', getVal())
128+
export class User {
129+
}
130+
// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"contexts":["ClassDeclaration"]}]
131+
// Message: Block comments should be JSDoc-style.
132+
133+
/* A single line comment */ function quux () {}
134+
// Settings: {"jsdoc":{"minLines":0,"maxLines":0}}
135+
// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"enforceJsdocLineStyle":"single"}]
136+
// Message: Block comments should be JSDoc-style.
137+
````
138+
139+
140+
141+
<a name="user-content-convert-to-jsdoc-comments-passing-examples"></a>
142+
<a name="convert-to-jsdoc-comments-passing-examples"></a>
143+
## Passing examples
144+
145+
The following patterns are not considered problems:
146+
147+
````js
148+
/** A single line comment */
149+
function quux () {}
150+
// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"enforceJsdocLineStyle":"single"}]
151+
152+
/** A single line comment */
153+
function quux () {}
154+
// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"enforceJsdocLineStyle":"multi"}]
155+
156+
/** A single line comment */
157+
function quux () {}
158+
// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"lineOrBlockStyle":"line"}]
159+
160+
/** A single line comment */
161+
function quux () {}
162+
// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"lineOrBlockStyle":"block"}]
163+
164+
/* A single line comment */
165+
function quux () {}
166+
// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"lineOrBlockStyle":"line","enforceJsdocLineStyle":"single"}]
167+
168+
// A single line comment
169+
function quux () {}
170+
// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"lineOrBlockStyle":"block","enforceJsdocLineStyle":"single"}]
171+
172+
// @ts-expect-error
173+
function quux () {}
174+
175+
// @custom-something
176+
function quux () {}
177+
// "jsdoc/convert-to-jsdoc-comments": ["error"|"warn", {"allowedPrefixes":["@custom-"]}]
178+
````
179+

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"url": "http://gajus.com"
66
},
77
"dependencies": {
8-
"@es-joy/jsdoccomment": "~0.43.1",
8+
"@es-joy/jsdoccomment": "~0.44.0",
99
"are-docs-informative": "^0.0.2",
1010
"comment-parser": "1.4.1",
1111
"debug": "^4.3.5",

‎pnpm-lock.yaml

+15-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/bin/generateRule.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export default iterateJsdoc(({
121121
await fs.writeFile(ruleTestPath, ruleTestTemplate);
122122
}
123123

124-
const ruleReadmeTemplate = `### \`${ruleName}\`
124+
const ruleReadmeTemplate = `# \`${ruleName}\`
125125
126126
|||
127127
|---|---|

‎src/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import checkSyntax from './rules/checkSyntax.js';
99
import checkTagNames from './rules/checkTagNames.js';
1010
import checkTypes from './rules/checkTypes.js';
1111
import checkValues from './rules/checkValues.js';
12+
import convertToJsdocComments from './rules/convertToJsdocComments.js';
1213
import emptyTags from './rules/emptyTags.js';
1314
import implementsOnClasses from './rules/implementsOnClasses.js';
1415
import importsAsDependencies from './rules/importsAsDependencies.js';
@@ -81,6 +82,7 @@ const index = {
8182
'check-tag-names': checkTagNames,
8283
'check-types': checkTypes,
8384
'check-values': checkValues,
85+
'convert-to-jsdoc-comments': convertToJsdocComments,
8486
'empty-tags': emptyTags,
8587
'implements-on-classes': implementsOnClasses,
8688
'imports-as-dependencies': importsAsDependencies,
@@ -153,6 +155,7 @@ const createRecommendedRuleset = (warnOrError, flatName) => {
153155
'jsdoc/check-tag-names': warnOrError,
154156
'jsdoc/check-types': warnOrError,
155157
'jsdoc/check-values': warnOrError,
158+
'jsdoc/convert-to-jsdoc-comments': 'off',
156159
'jsdoc/empty-tags': warnOrError,
157160
'jsdoc/implements-on-classes': warnOrError,
158161
'jsdoc/imports-as-dependencies': 'off',

‎src/rules/convertToJsdocComments.js

+213
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
import iterateJsdoc from '../iterateJsdoc.js';
2+
import {
3+
getSettings,
4+
} from '../iterateJsdoc.js';
5+
import jsdocUtils from '../jsdocUtils.js';
6+
import {
7+
getNonJsdocComment,
8+
getDecorator,
9+
getReducedASTNode,
10+
} from '@es-joy/jsdoccomment';
11+
12+
/** @type {import('eslint').Rule.RuleModule} */
13+
export default {
14+
create (context) {
15+
/* c8 ignore next -- Fallback to deprecated method */
16+
const {
17+
sourceCode = context.getSourceCode(),
18+
} = context;
19+
const settings = getSettings(context);
20+
if (!settings) {
21+
return {};
22+
}
23+
24+
const {
25+
contexts = settings.contexts || [],
26+
enableFixer = true,
27+
enforceJsdocLineStyle = 'multi',
28+
lineOrBlockStyle = 'both',
29+
allowedPrefixes = ['@ts-', 'istanbul ', 'c8 ', 'v8 ', 'eslint', 'prettier-']
30+
} = context.options[0] ?? {};
31+
32+
/**
33+
* @type {import('../iterateJsdoc.js').CheckJsdoc}
34+
*/
35+
const checkNonJsdoc = (_info, _handler, node) => {
36+
const comment = getNonJsdocComment(sourceCode, node, settings);
37+
38+
if (
39+
!comment ||
40+
/** @type {string[]} */
41+
(allowedPrefixes).some((prefix) => {
42+
return comment.value.trimStart().startsWith(prefix);
43+
})
44+
) {
45+
return;
46+
}
47+
48+
const fix = /** @type {import('eslint').Rule.ReportFixer} */ (fixer) => {
49+
// Default to one line break if the `minLines`/`maxLines` settings allow
50+
const lines = settings.minLines === 0 && settings.maxLines >= 1 ? 1 : settings.minLines;
51+
/** @type {import('eslint').Rule.Node|import('@typescript-eslint/types').TSESTree.Decorator} */
52+
let baseNode = getReducedASTNode(node, sourceCode);
53+
54+
const decorator = getDecorator(baseNode);
55+
if (decorator) {
56+
baseNode = decorator;
57+
}
58+
59+
const indent = jsdocUtils.getIndent({
60+
text: sourceCode.getText(
61+
/** @type {import('eslint').Rule.Node} */ (baseNode),
62+
/** @type {import('eslint').AST.SourceLocation} */
63+
(
64+
/** @type {import('eslint').Rule.Node} */ (baseNode).loc
65+
).start.column,
66+
),
67+
});
68+
69+
const {
70+
inlineCommentBlock,
71+
} =
72+
/**
73+
* @type {{
74+
* context: string,
75+
* inlineCommentBlock: boolean,
76+
* minLineCount: import('../iterateJsdoc.js').Integer
77+
* }[]}
78+
*/ (contexts).find((contxt) => {
79+
if (typeof contxt === 'string') {
80+
return false;
81+
}
82+
83+
const {
84+
context: ctxt,
85+
} = contxt;
86+
return ctxt === node.type;
87+
}) || {};
88+
const insertion = (
89+
inlineCommentBlock || enforceJsdocLineStyle === 'single'
90+
? `/** ${comment.value.trim()} `
91+
: `/**\n${indent}*${comment.value.trimEnd()}\n${indent}`
92+
) +
93+
`*/${'\n'.repeat((lines || 1) - 1)}`;
94+
95+
return fixer.replaceText(
96+
/** @type {import('eslint').AST.Token} */
97+
(comment),
98+
insertion,
99+
);
100+
};
101+
102+
/**
103+
* @param {string} messageId
104+
*/
105+
const report = (messageId) => {
106+
const loc = {
107+
end: {
108+
column: 0,
109+
/* c8 ignore next 2 -- Guard */
110+
// @ts-expect-error Ok
111+
line: (comment.loc?.start?.line ?? 1),
112+
},
113+
start: {
114+
column: 0,
115+
/* c8 ignore next 2 -- Guard */
116+
// @ts-expect-error Ok
117+
line: (comment.loc?.start?.line ?? 1)
118+
},
119+
};
120+
121+
context.report({
122+
fix: enableFixer ? fix : null,
123+
loc,
124+
messageId,
125+
node,
126+
});
127+
};
128+
129+
if (comment.type === 'Block') {
130+
if (lineOrBlockStyle === 'line') {
131+
return;
132+
}
133+
report('blockCommentsJsdocStyle');
134+
return;
135+
}
136+
137+
if (comment.type === 'Line') {
138+
if (lineOrBlockStyle === 'block') {
139+
return;
140+
}
141+
report('lineCommentsJsdocStyle');
142+
}
143+
};
144+
145+
return {
146+
...jsdocUtils.getContextObject(
147+
jsdocUtils.enforcedContexts(context, true, settings),
148+
checkNonJsdoc,
149+
)
150+
};
151+
},
152+
meta: {
153+
fixable: 'code',
154+
155+
messages: {
156+
blockCommentsJsdocStyle: 'Block comments should be JSDoc-style.',
157+
lineCommentsJsdocStyle: 'Line comments should be JSDoc-style.',
158+
},
159+
160+
docs: {
161+
description: 'Converts non-JSDoc comments preceding nodes into JSDoc ones',
162+
url: 'https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/convert-to-jsdoc-comments.md#repos-sticky-header',
163+
},
164+
schema: [
165+
{
166+
additionalProperties: false,
167+
properties: {
168+
allowedPrefixes: {
169+
type: 'array',
170+
items: {
171+
type: 'string'
172+
}
173+
},
174+
enableFixer: {
175+
type: 'boolean'
176+
},
177+
enforceJsdocLineStyle: {
178+
type: 'string',
179+
enum: ['multi', 'single']
180+
},
181+
lineOrBlockStyle: {
182+
type: 'string',
183+
enum: ['block', 'line', 'both']
184+
},
185+
contexts: {
186+
items: {
187+
anyOf: [
188+
{
189+
type: 'string',
190+
},
191+
{
192+
additionalProperties: false,
193+
properties: {
194+
context: {
195+
type: 'string',
196+
},
197+
inlineCommentBlock: {
198+
type: 'boolean',
199+
},
200+
},
201+
type: 'object',
202+
},
203+
],
204+
},
205+
type: 'array',
206+
},
207+
},
208+
type: 'object',
209+
},
210+
],
211+
type: 'suggestion',
212+
},
213+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,369 @@
1+
import {parser as typescriptEslintParser} from 'typescript-eslint';
2+
3+
export default {
4+
invalid: [
5+
{
6+
code: `
7+
// A single line comment
8+
function quux () {}
9+
`,
10+
errors: [
11+
{
12+
line: 2,
13+
message: 'Line comments should be JSDoc-style.',
14+
},
15+
],
16+
options: [
17+
{
18+
enforceJsdocLineStyle: 'single'
19+
}
20+
],
21+
output: `
22+
/** A single line comment */
23+
function quux () {}
24+
`
25+
},
26+
{
27+
code: `
28+
// A single line comment
29+
function quux () {}
30+
`,
31+
errors: [
32+
{
33+
line: 2,
34+
message: 'Line comments should be JSDoc-style.',
35+
},
36+
],
37+
options: [
38+
{
39+
contexts: [
40+
{
41+
context: 'FunctionDeclaration',
42+
inlineCommentBlock: true
43+
}
44+
]
45+
}
46+
],
47+
output: `
48+
/** A single line comment */
49+
function quux () {}
50+
`
51+
},
52+
{
53+
code: `
54+
// A single line comment
55+
function quux () {}
56+
`,
57+
errors: [
58+
{
59+
line: 2,
60+
message: 'Line comments should be JSDoc-style.',
61+
},
62+
],
63+
options: [
64+
{
65+
enableFixer: false,
66+
enforceJsdocLineStyle: 'single'
67+
}
68+
],
69+
},
70+
{
71+
code: `
72+
// A single line comment
73+
function quux () {}
74+
`,
75+
errors: [
76+
{
77+
line: 2,
78+
message: 'Line comments should be JSDoc-style.',
79+
},
80+
],
81+
options: [
82+
{
83+
lineOrBlockStyle: 'line',
84+
enforceJsdocLineStyle: 'single'
85+
}
86+
],
87+
output: `
88+
/** A single line comment */
89+
function quux () {}
90+
`
91+
},
92+
{
93+
code: `
94+
/* A single line comment */
95+
function quux () {}
96+
`,
97+
errors: [
98+
{
99+
line: 2,
100+
message: 'Block comments should be JSDoc-style.',
101+
},
102+
],
103+
options: [
104+
{
105+
enforceJsdocLineStyle: 'single'
106+
}
107+
],
108+
output: `
109+
/** A single line comment */
110+
function quux () {}
111+
`,
112+
},
113+
{
114+
code: `
115+
/* A single line comment */
116+
function quux () {}
117+
`,
118+
errors: [
119+
{
120+
line: 2,
121+
message: 'Block comments should be JSDoc-style.',
122+
},
123+
],
124+
options: [
125+
{
126+
lineOrBlockStyle: 'block',
127+
enforceJsdocLineStyle: 'single'
128+
}
129+
],
130+
output: `
131+
/** A single line comment */
132+
function quux () {}
133+
`,
134+
},
135+
{
136+
code: `
137+
// A single line comment
138+
function quux () {}
139+
`,
140+
errors: [
141+
{
142+
line: 2,
143+
message: 'Line comments should be JSDoc-style.',
144+
},
145+
],
146+
options: [
147+
{
148+
enforceJsdocLineStyle: 'multi'
149+
}
150+
],
151+
output: `
152+
/**
153+
* A single line comment
154+
*/
155+
function quux () {}
156+
`,
157+
},
158+
{
159+
code: `
160+
// A single line comment
161+
function quux () {}
162+
`,
163+
errors: [
164+
{
165+
line: 2,
166+
message: 'Line comments should be JSDoc-style.',
167+
},
168+
],
169+
output: `
170+
/**
171+
* A single line comment
172+
*/
173+
function quux () {}
174+
`,
175+
},
176+
{
177+
code: `
178+
/* A single line comment */
179+
function quux () {}
180+
`,
181+
errors: [
182+
{
183+
line: 2,
184+
message: 'Block comments should be JSDoc-style.',
185+
},
186+
],
187+
options: [
188+
{
189+
enforceJsdocLineStyle: 'multi'
190+
}
191+
],
192+
output: `
193+
/**
194+
* A single line comment
195+
*/
196+
function quux () {}
197+
`,
198+
},
199+
{
200+
code: `
201+
// Single line comment
202+
function quux() {
203+
204+
}
205+
`,
206+
errors: [
207+
{
208+
line: 1,
209+
message: 'Cannot add "name" to `require` with the tag\'s `name` set to `false`',
210+
},
211+
],
212+
settings: {
213+
jsdoc: {
214+
structuredTags: {
215+
see: {
216+
name: false,
217+
required: [
218+
'name',
219+
],
220+
},
221+
},
222+
},
223+
},
224+
},
225+
{
226+
code: `
227+
/* Entity to represent a user in the system. */
228+
@Entity('users', getVal())
229+
export class User {
230+
}
231+
`,
232+
errors: [
233+
{
234+
line: 2,
235+
message: 'Block comments should be JSDoc-style.',
236+
},
237+
],
238+
options: [
239+
{
240+
contexts: ['ClassDeclaration']
241+
}
242+
],
243+
output: `
244+
/**
245+
* Entity to represent a user in the system.
246+
*/
247+
@Entity('users', getVal())
248+
export class User {
249+
}
250+
`,
251+
languageOptions: {
252+
parser: typescriptEslintParser,
253+
sourceType: 'module',
254+
},
255+
},
256+
{
257+
code: `
258+
/* A single line comment */ function quux () {}
259+
`,
260+
errors: [
261+
{
262+
line: 2,
263+
message: 'Block comments should be JSDoc-style.',
264+
},
265+
],
266+
options: [
267+
{
268+
enforceJsdocLineStyle: 'single'
269+
}
270+
],
271+
settings: {
272+
jsdoc: {
273+
minLines: 0,
274+
maxLines: 0,
275+
},
276+
},
277+
output: `
278+
/** A single line comment */ function quux () {}
279+
`
280+
},
281+
],
282+
valid: [
283+
{
284+
code: `
285+
/** A single line comment */
286+
function quux () {}
287+
`,
288+
options: [
289+
{
290+
enforceJsdocLineStyle: 'single'
291+
}
292+
],
293+
},
294+
{
295+
code: `
296+
/** A single line comment */
297+
function quux () {}
298+
`,
299+
options: [
300+
{
301+
enforceJsdocLineStyle: 'multi'
302+
}
303+
],
304+
},
305+
{
306+
code: `
307+
/** A single line comment */
308+
function quux () {}
309+
`,
310+
options: [
311+
{
312+
lineOrBlockStyle: 'line',
313+
}
314+
],
315+
},
316+
{
317+
code: `
318+
/** A single line comment */
319+
function quux () {}
320+
`,
321+
options: [
322+
{
323+
lineOrBlockStyle: 'block',
324+
}
325+
],
326+
},
327+
{
328+
code: `
329+
/* A single line comment */
330+
function quux () {}
331+
`,
332+
options: [
333+
{
334+
lineOrBlockStyle: 'line',
335+
enforceJsdocLineStyle: 'single'
336+
}
337+
],
338+
},
339+
{
340+
code: `
341+
// A single line comment
342+
function quux () {}
343+
`,
344+
options: [
345+
{
346+
lineOrBlockStyle: 'block',
347+
enforceJsdocLineStyle: 'single'
348+
}
349+
],
350+
},
351+
{
352+
code: `
353+
// @ts-expect-error
354+
function quux () {}
355+
`,
356+
},
357+
{
358+
code: `
359+
// @custom-something
360+
function quux () {}
361+
`,
362+
options: [
363+
{
364+
allowedPrefixes: ['@custom-']
365+
}
366+
],
367+
},
368+
],
369+
};

‎test/rules/ruleNames.json

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"check-tag-names",
1111
"check-types",
1212
"check-values",
13+
"convert-to-jsdoc-comments",
1314
"empty-tags",
1415
"implements-on-classes",
1516
"imports-as-dependencies",

0 commit comments

Comments
 (0)
Please sign in to comment.