Skip to content

Commit 06cb22e

Browse files
committed
feat(valid-types): move settings to options
1 parent 76e1e97 commit 06cb22e

File tree

3 files changed

+52
-17
lines changed

3 files changed

+52
-17
lines changed

src/iterateJsdoc.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,12 @@ const getUtils = (
2828
jsdocNode,
2929
{
3030
tagNamePreference,
31-
allowEmptyNamepaths,
3231
overrideReplacesDocs,
3332
implementsReplacesDocs,
3433
augmentsExtendsReplacesDocs,
3534
allowOverrideWithoutParam,
3635
allowImplementsWithoutParam,
37-
allowAugmentsExtendsWithoutParam,
38-
checkSeesForNamepaths
36+
allowAugmentsExtendsWithoutParam
3937
},
4038
report,
4139
context
@@ -158,15 +156,15 @@ const getUtils = (
158156
utils.isNamepathDefiningTag = (tagName) => {
159157
return jsdocUtils.isNamepathDefiningTag(tagName);
160158
};
161-
utils.isNamepathTag = (tagName) => {
159+
utils.isNamepathTag = (tagName, checkSeesForNamepaths) => {
162160
return jsdocUtils.isNamepathTag(tagName, checkSeesForNamepaths);
163161
};
164162

165163
utils.isTagWithType = (tagName) => {
166164
return jsdocUtils.isTagWithType(tagName);
167165
};
168166

169-
utils.passesEmptyNamepathCheck = (tag) => {
167+
utils.passesEmptyNamepathCheck = (tag, allowEmptyNamepaths) => {
170168
return !tag.name && allowEmptyNamepaths &&
171169
jsdocUtils.isPotentiallyEmptyNamepathTag(tag.tag);
172170
};
@@ -277,10 +275,6 @@ const getSettings = (context) => {
277275
settings.allowImplementsWithoutParam = _.get(context, 'settings.jsdoc.allowImplementsWithoutParam');
278276
settings.allowAugmentsExtendsWithoutParam = _.get(context, 'settings.jsdoc.allowAugmentsExtendsWithoutParam');
279277

280-
// `valid-types` only
281-
settings.allowEmptyNamepaths = _.get(context, 'settings.jsdoc.allowEmptyNamepaths') !== false;
282-
settings.checkSeesForNamepaths = Boolean(_.get(context, 'settings.jsdoc.checkSeesForNamepaths'));
283-
284278
// `require-example` only
285279
settings.avoidExampleOnConstructors = Boolean(_.get(context, 'settings.jsdoc.avoidExampleOnConstructors'));
286280

src/rules/validTypes.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
import {parse} from 'jsdoctypeparser';
22
import iterateJsdoc from '../iterateJsdoc';
3+
import warnRemovedSettings from '../warnRemovedSettings';
34

45
const asExpression = /as\s+/;
56

67
export default iterateJsdoc(({
78
jsdoc,
89
report,
9-
utils
10+
utils,
11+
context
1012
}) => {
13+
warnRemovedSettings(context, 'valid-types');
14+
15+
const options = context.options[0] || {
16+
allowEmptyNamepaths: true,
17+
checkSeesForNamepaths: false
18+
};
19+
1120
if (!jsdoc.tags) {
1221
return;
1322
}
@@ -66,8 +75,8 @@ export default iterateJsdoc(({
6675

6776
validTypeParsing(thatNamepath);
6877
}
69-
} else if (utils.isNamepathTag(tag.tag)) {
70-
if (utils.passesEmptyNamepathCheck(tag)) {
78+
} else if (utils.isNamepathTag(tag.tag, options.checkSeesForNamepaths)) {
79+
if (utils.passesEmptyNamepathCheck(tag, options.allowEmptyNamepaths)) {
7180
return;
7281
}
7382
validTypeParsing(tag.name, tag.tag);
@@ -78,6 +87,22 @@ export default iterateJsdoc(({
7887
}, {
7988
iterateAllJsdocs: true,
8089
meta: {
90+
schema: [
91+
{
92+
additionalProperies: false,
93+
properties: {
94+
allowEmptyNamepaths: {
95+
default: true,
96+
type: 'boolean'
97+
},
98+
checkSeesForNamepaths: {
99+
default: false,
100+
type: 'boolean'
101+
}
102+
},
103+
type: 'object'
104+
}
105+
],
81106
type: 'suggestion'
82107
}
83108
});

test/rules/assertions/validTypes.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,26 @@ export default {
117117
line: 3,
118118
message: 'Syntax error in type: foo%'
119119
}],
120+
options: [{
121+
checkSeesForNamepaths: true
122+
}]
123+
},
124+
{
125+
code: `
126+
/** */
127+
function foo() {}
128+
`,
129+
errors: [
130+
{
131+
message: '`settings.jsdoc.allowEmptyNamepaths` has been removed, use options in the rule `valid-types` instead.'
132+
},
133+
{
134+
message: '`settings.jsdoc.checkSeesForNamepaths` has been removed, use options in the rule `valid-types` instead.'
135+
}
136+
],
120137
settings: {
121138
jsdoc: {
139+
allowEmptyNamepaths: true,
122140
checkSeesForNamepaths: true
123141
}
124142
}
@@ -164,11 +182,9 @@ export default {
164182
line: 3,
165183
message: 'Syntax error in type: '
166184
}],
167-
settings: {
168-
jsdoc: {
169-
allowEmptyNamepaths: false
170-
}
171-
}
185+
options: [{
186+
allowEmptyNamepaths: false
187+
}]
172188
}
173189
],
174190
valid: [

0 commit comments

Comments
 (0)