-
-
Notifications
You must be signed in to change notification settings - Fork 153
/
noDefaults.js
62 lines (61 loc) · 1.72 KB
/
noDefaults.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import iterateJsdoc from '../iterateJsdoc';
export default iterateJsdoc(({
context,
utils,
}) => {
const {noOptionalParamNames} = context.options[0] || {};
const paramTags = utils.getPresentTags(['param', 'arg', 'argument']);
paramTags.forEach((tag) => {
if (noOptionalParamNames && tag.optional) {
utils.reportJSDoc(`Optional param names are not permitted on @${tag.tag}.`, tag, () => {
utils.changeTag(tag, {
name: tag.name.replace(/([^=]*)(=.+)?/, '$1'),
});
});
} else if (tag.default) {
utils.reportJSDoc(`Defaults are not permitted on @${tag.tag}.`, tag, () => {
utils.changeTag(tag, {
name: tag.name.replace(/([^=]*)(=.+)?/, '[$1]'),
});
});
}
});
const defaultTags = utils.getPresentTags(['default', 'defaultvalue']);
defaultTags.forEach((tag) => {
if (tag.description.trim()) {
utils.reportJSDoc(`Default values are not permitted on @${tag.tag}.`, tag, () => {
utils.changeTag(tag, {
description: '',
postTag: '',
});
});
}
});
}, {
contextDefaults: true,
meta: {
docs: {
description: 'This rule reports defaults being used on the relevant portion of `@param` or `@default`.',
url: 'https://github.com/gajus/eslint-plugin-jsdoc#eslint-plugin-jsdoc-rules-no-defaults',
},
fixable: 'code',
schema: [
{
additionalProperties: false,
properties: {
contexts: {
items: {
type: 'string',
},
type: 'array',
},
noOptionalParamNames: {
type: 'boolean',
},
},
type: 'object',
},
],
type: 'suggestion',
},
});