Skip to content

Commit

Permalink
fix(check-tag-names): loosen tag replacement to allow for no-space if…
Browse files Browse the repository at this point in the history
… at word boundary (as at end of line)
  • Loading branch information
brettz9 committed Jul 12, 2019
1 parent 15424f8 commit 1145cd0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/rules/checkTagNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ export default iterateJsdoc(({

if (preferredTagName !== tagName) {
report(message, (fixer) => {
const replacement = sourceCode.getText(jsdocNode).replace(`@${tagName} `, `@${preferredTagName} `);
const replacement = sourceCode.getText(jsdocNode).replace(
new RegExp(`@${_.escapeRegExp(tagName)}\\b`),
`@${preferredTagName}`
);

return fixer.replaceText(jsdocNode, replacement);
}, jsdocTag);
Expand Down
33 changes: 33 additions & 0 deletions test/rules/assertions/checkTagNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,39 @@ export default {
}
}
}
},
{
code: `
/**
* @abc
* @abcd
*/
function quux () {
}
`,
errors: [
{
line: 3,
message: 'Invalid JSDoc tag (preference). Replace "abc" JSDoc tag with "abcd".'
}
],
output: `
/**
* @abcd
* @abcd
*/
function quux () {
}
`,
settings: {
jsdoc: {
tagNamePreference: {
abc: 'abcd'
}
}
}
}
],
valid: [
Expand Down

0 comments on commit 1145cd0

Please sign in to comment.