Skip to content

Commit 6f1b50b

Browse files
committed
feat(informative-docs): add excludedTags; fixes #1153
Also: - fix(`informative-docs`): proper `aliases` schema - test(`informative-docs`): check `uselessWords` - test(`require-jsdoc`): example for Vue components
1 parent 85a21bf commit 6f1b50b

File tree

6 files changed

+143
-7
lines changed

6 files changed

+143
-7
lines changed

.README/rules/informative-docs.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ The default `uselessWords` option is:
6060
|Tags|any|
6161
|Recommended|false|
6262
|Settings||
63-
|Options|`aliases`, `uselessWords`|
63+
|Options|`aliases`, `excludedTags`, `uselessWords`|
6464

6565
## Failing examples
6666

docs/rules/informative-docs.md

+19-3
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ The default `uselessWords` option is:
7676
|Tags|any|
7777
|Recommended|false|
7878
|Settings||
79-
|Options|`aliases`, `uselessWords`|
79+
|Options|`aliases`, `excludedTags`, `uselessWords`|
8080

8181
<a name="user-content-informative-docs-failing-examples"></a>
8282
<a name="informative-docs-failing-examples"></a>
@@ -249,6 +249,11 @@ function takesOne(param) {}
249249
*/
250250
function takesOne(param) {}
251251
// Message: This description only repeats the name it describes.
252+
253+
/** A smiley/winkey. */
254+
let emoji;
255+
// "jsdoc/informative-docs": ["error"|"warn", {"aliases":{"emoji":["smiley","winkey"]}}]
256+
// Message: This description only repeats the name it describes.
252257
````
253258

254259

@@ -391,10 +396,21 @@ function takesOne(param) {}
391396
function takesOne(param) {}
392397

393398
/**
394-
* @class
399+
* @class
395400
*
396401
* @param {number} value - Some useful text
397-
*/
402+
*/
398403
function MyAmazingThing(value) {}
404+
405+
/**
406+
* My option.
407+
* @default {}
408+
*/
409+
// "jsdoc/informative-docs": ["error"|"warn", {"excludedTags":["default"]}]
410+
411+
/**
412+
* The
413+
*/
414+
// "jsdoc/informative-docs": ["error"|"warn", {"uselessWords":["an"]}]
399415
````
400416

docs/rules/require-jsdoc.md

+22
Original file line numberDiff line numberDiff line change
@@ -1857,5 +1857,27 @@ export default class Test {
18571857
}
18581858
}
18591859
// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"ArrowFunctionExpression":false,"ClassDeclaration":false,"ClassExpression":false,"FunctionDeclaration":false,"FunctionExpression":false,"MethodDefinition":true}}]
1860+
1861+
export default {
1862+
created() {
1863+
this.getData();
1864+
},
1865+
1866+
beforeUpdate() {},
1867+
1868+
watch: {
1869+
someValue(val) {}
1870+
},
1871+
1872+
computed: {
1873+
loaded() {},
1874+
selection() {}
1875+
},
1876+
1877+
methods: {
1878+
getData(id) {}
1879+
}
1880+
};
1881+
// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["ExportDefaultDeclaration > ObjectExpression > Property[key.name!=/^(created|beforeUpdate)$/] > FunctionExpression","ExportDefaultDeclaration > ObjectExpression > Property[key.name!=/^(watch|computed|methods)$/] > ObjectExpression > Property > FunctionExpression"]}]
18601882
````
18611883

src/rules/informativeDocs.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ export default iterateJsdoc(({
9191
report,
9292
utils,
9393
}) => {
94-
const {
94+
const /** @type {{aliases: {[key: string]: string[]}, excludedTags: string[], uselessWords: string[]}} */ {
9595
aliases = defaultAliases,
96+
excludedTags = [],
9697
uselessWords = defaultUselessWords,
9798
} = context.options[0] || {};
9899
const nodeNames = getNamesFromNode(node);
@@ -119,6 +120,10 @@ export default iterateJsdoc(({
119120
let descriptionReported = false;
120121

121122
for (const tag of jsdoc.tags) {
123+
if (excludedTags.includes(tag.tag)) {
124+
continue;
125+
}
126+
122127
if (descriptionIsRedundant(tag.description, tag.name)) {
123128
utils.reportJSDoc(
124129
'This tag description only repeats the name it describes.',
@@ -147,6 +152,16 @@ export default iterateJsdoc(({
147152
additionalProperties: false,
148153
properties: {
149154
aliases: {
155+
patternProperties: {
156+
'.*': {
157+
items: {
158+
type: 'string',
159+
},
160+
type: 'array',
161+
},
162+
},
163+
},
164+
excludedTags: {
150165
items: {
151166
type: 'string',
152167
},

test/rules/assertions/informativeDocs.js

+52-2
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,27 @@ export default {
476476
},
477477
],
478478
},
479+
{
480+
code: `
481+
/** A smiley/winkey. */
482+
let emoji;
483+
`,
484+
errors: [
485+
{
486+
line: 2,
487+
message: 'This description only repeats the name it describes.',
488+
},
489+
],
490+
options: [
491+
{
492+
aliases: {
493+
emoji: [
494+
'smiley', 'winkey',
495+
],
496+
},
497+
},
498+
],
499+
},
479500
],
480501
valid: [
481502
{
@@ -752,12 +773,41 @@ export default {
752773
{
753774
code: `
754775
/**
755-
* @class
776+
* @class
756777
*
757778
* @param {number} value - Some useful text
758-
*/
779+
*/
759780
function MyAmazingThing(value) {}
760781
`,
761782
},
783+
{
784+
code: `
785+
/**
786+
* My option.
787+
* @default {}
788+
*/
789+
`,
790+
options: [
791+
{
792+
excludedTags: [
793+
'default',
794+
],
795+
},
796+
],
797+
},
798+
{
799+
code: `
800+
/**
801+
* The
802+
*/
803+
`,
804+
options: [
805+
{
806+
uselessWords: [
807+
'an',
808+
],
809+
},
810+
],
811+
},
762812
],
763813
};

test/rules/assertions/requireJsdoc.js

+33
Original file line numberDiff line numberDiff line change
@@ -6202,5 +6202,38 @@ function quux (foo) {
62026202
sourceType: 'module',
62036203
},
62046204
},
6205+
{
6206+
code: `
6207+
export default {
6208+
created() {
6209+
this.getData();
6210+
},
6211+
6212+
beforeUpdate() {},
6213+
6214+
watch: {
6215+
someValue(val) {}
6216+
},
6217+
6218+
computed: {
6219+
loaded() {},
6220+
selection() {}
6221+
},
6222+
6223+
methods: {
6224+
getData(id) {}
6225+
}
6226+
};
6227+
`,
6228+
options: [
6229+
{
6230+
contexts: [
6231+
'ExportDefaultDeclaration > ObjectExpression > Property[key.name!=/^(created|beforeUpdate)$/] > FunctionExpression',
6232+
'ExportDefaultDeclaration > ObjectExpression > Property[key.name!=/^(watch|computed|methods)$/] > ObjectExpression > Property > FunctionExpression',
6233+
],
6234+
},
6235+
],
6236+
parser: require.resolve('@typescript-eslint/parser'),
6237+
},
62056238
],
62066239
};

0 commit comments

Comments
 (0)