Skip to content

Commit

Permalink
fix(check-param-names): adjusts line numbers to be nearer problemat…
Browse files Browse the repository at this point in the history
…ic item

Also adds test line numbers.
  • Loading branch information
brettz9 committed May 14, 2021
1 parent a977896 commit e6c9ab2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/iterateJsdoc.js
Expand Up @@ -39,6 +39,8 @@ const getBasicUtils = (context, {tagNamePreference, mode}) => {
return jsdocUtils.parseClosureTemplateTag(tag);
};

utils.pathDoesNotBeginWith = jsdocUtils.pathDoesNotBeginWith;

utils.getPreferredTagNameObject = ({tagName}) => {
const ret = jsdocUtils.getPreferredTagName(context, mode, tagName, tagNamePreference);
const isObject = ret && typeof ret === 'object';
Expand Down
6 changes: 6 additions & 0 deletions src/jsdocUtils.js
Expand Up @@ -1219,6 +1219,11 @@ const comparePaths = (name) => {
};
};

const pathDoesNotBeginWith = (name, otherPathName) => {
return !name.startsWith(otherPathName) &&
!dropPathSegmentQuotes(name).startsWith(dropPathSegmentQuotes(otherPathName));
};

const getRegexFromString = (regexString, requiredFlags) => {
const match = regexString.match(/^\/(.*)\/([gimyus]*)$/us);
let flags = 'u';
Expand Down Expand Up @@ -1266,6 +1271,7 @@ export default {
isValidTag,
overrideTagStructure,
parseClosureTemplateTag,
pathDoesNotBeginWith,
setTagStructure,
tagMightHaveNamepath,
tagMightHaveNamePosition,
Expand Down
15 changes: 12 additions & 3 deletions src/rules/checkParamNames.js
Expand Up @@ -99,16 +99,25 @@ const validateParameterNames = (
if (!checkRestProperty && rests[idx]) {
return;
}
missingProperties.push(name);
const missingIndex = actualNames.findIndex((actualName) => {
return utils.pathDoesNotBeginWith(name, actualName);
});
const line = tag.source[0].number - 1 + (missingIndex > -1 ? missingIndex : actualNames.length);
missingProperties.push({
name,
tagPlacement: {
line: line === 0 ? 1 : line,
},
});
} else if (actualTypes[actualNameIdx].search(checkTypesRegex) === -1 && actualTypes[actualNameIdx] !== '') {
notCheckingNames.push(name);
}
});

const hasMissing = missingProperties.length;
if (hasMissing) {
missingProperties.forEach((missingProperty) => {
report(`Missing @${targetTagName} "${missingProperty}"`, null, tag);
missingProperties.forEach(({tagPlacement, name: missingProperty}) => {
report(`Missing @${targetTagName} "${missingProperty}"`, null, tagPlacement);
});
}

Expand Down
2 changes: 2 additions & 0 deletions test/rules/assertions/checkParamNames.js
Expand Up @@ -935,6 +935,7 @@ export default {
`,
errors: [
{
line: 5,
message: 'Missing @param "options.foo.bar"',
},
],
Expand All @@ -951,6 +952,7 @@ export default {
`,
errors: [
{
line: 6,
message: 'Missing @param "options.foo.bar.baz"',
},
],
Expand Down

0 comments on commit e6c9ab2

Please sign in to comment.