Skip to content

Commit

Permalink
feat(valid-types): move settings to options
Browse files Browse the repository at this point in the history
  • Loading branch information
golopot committed Jul 7, 2019
1 parent 76e1e97 commit 06cb22e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 17 deletions.
12 changes: 3 additions & 9 deletions src/iterateJsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ const getUtils = (
jsdocNode,
{
tagNamePreference,
allowEmptyNamepaths,
overrideReplacesDocs,
implementsReplacesDocs,
augmentsExtendsReplacesDocs,
allowOverrideWithoutParam,
allowImplementsWithoutParam,
allowAugmentsExtendsWithoutParam,
checkSeesForNamepaths
allowAugmentsExtendsWithoutParam
},
report,
context
Expand Down Expand Up @@ -158,15 +156,15 @@ const getUtils = (
utils.isNamepathDefiningTag = (tagName) => {
return jsdocUtils.isNamepathDefiningTag(tagName);
};
utils.isNamepathTag = (tagName) => {
utils.isNamepathTag = (tagName, checkSeesForNamepaths) => {
return jsdocUtils.isNamepathTag(tagName, checkSeesForNamepaths);
};

utils.isTagWithType = (tagName) => {
return jsdocUtils.isTagWithType(tagName);
};

utils.passesEmptyNamepathCheck = (tag) => {
utils.passesEmptyNamepathCheck = (tag, allowEmptyNamepaths) => {
return !tag.name && allowEmptyNamepaths &&
jsdocUtils.isPotentiallyEmptyNamepathTag(tag.tag);
};
Expand Down Expand Up @@ -277,10 +275,6 @@ const getSettings = (context) => {
settings.allowImplementsWithoutParam = _.get(context, 'settings.jsdoc.allowImplementsWithoutParam');
settings.allowAugmentsExtendsWithoutParam = _.get(context, 'settings.jsdoc.allowAugmentsExtendsWithoutParam');

// `valid-types` only
settings.allowEmptyNamepaths = _.get(context, 'settings.jsdoc.allowEmptyNamepaths') !== false;
settings.checkSeesForNamepaths = Boolean(_.get(context, 'settings.jsdoc.checkSeesForNamepaths'));

// `require-example` only
settings.avoidExampleOnConstructors = Boolean(_.get(context, 'settings.jsdoc.avoidExampleOnConstructors'));

Expand Down
31 changes: 28 additions & 3 deletions src/rules/validTypes.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import {parse} from 'jsdoctypeparser';
import iterateJsdoc from '../iterateJsdoc';
import warnRemovedSettings from '../warnRemovedSettings';

const asExpression = /as\s+/;

export default iterateJsdoc(({
jsdoc,
report,
utils
utils,
context
}) => {
warnRemovedSettings(context, 'valid-types');

const options = context.options[0] || {
allowEmptyNamepaths: true,
checkSeesForNamepaths: false
};

if (!jsdoc.tags) {
return;
}
Expand Down Expand Up @@ -66,8 +75,8 @@ export default iterateJsdoc(({

validTypeParsing(thatNamepath);
}
} else if (utils.isNamepathTag(tag.tag)) {
if (utils.passesEmptyNamepathCheck(tag)) {
} else if (utils.isNamepathTag(tag.tag, options.checkSeesForNamepaths)) {
if (utils.passesEmptyNamepathCheck(tag, options.allowEmptyNamepaths)) {
return;
}
validTypeParsing(tag.name, tag.tag);
Expand All @@ -78,6 +87,22 @@ export default iterateJsdoc(({
}, {
iterateAllJsdocs: true,
meta: {
schema: [
{
additionalProperies: false,
properties: {
allowEmptyNamepaths: {
default: true,
type: 'boolean'
},
checkSeesForNamepaths: {
default: false,
type: 'boolean'
}
},
type: 'object'
}
],
type: 'suggestion'
}
});
26 changes: 21 additions & 5 deletions test/rules/assertions/validTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,26 @@ export default {
line: 3,
message: 'Syntax error in type: foo%'
}],
options: [{
checkSeesForNamepaths: true
}]
},
{
code: `
/** */
function foo() {}
`,
errors: [
{
message: '`settings.jsdoc.allowEmptyNamepaths` has been removed, use options in the rule `valid-types` instead.'
},
{
message: '`settings.jsdoc.checkSeesForNamepaths` has been removed, use options in the rule `valid-types` instead.'
}
],
settings: {
jsdoc: {
allowEmptyNamepaths: true,
checkSeesForNamepaths: true
}
}
Expand Down Expand Up @@ -164,11 +182,9 @@ export default {
line: 3,
message: 'Syntax error in type: '
}],
settings: {
jsdoc: {
allowEmptyNamepaths: false
}
}
options: [{
allowEmptyNamepaths: false
}]
}
],
valid: [
Expand Down

0 comments on commit 06cb22e

Please sign in to comment.