Skip to content

Commit

Permalink
fix(match-name): perform replacements for names appearing after mul…
Browse files Browse the repository at this point in the history
…tiline types
  • Loading branch information
brettz9 committed Mar 12, 2022
1 parent 13f128b commit a23168d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -7685,6 +7685,14 @@ function quux () {
function quux () {}
// "jsdoc/match-name": ["error"|"warn", ]
// Message: Rule `no-restricted-syntax` is missing a `match` option.

/**
* @param {
* someType
* } opt_a
*/
// "jsdoc/match-name": ["error"|"warn", {"match":[{"disallowName":"/^opt_/i","replacement":""}]}]
// Message: Only allowing names not matching `/^opt_/i` but found "opt_a".
````

The following patterns are not considered problems:
Expand Down
11 changes: 8 additions & 3 deletions src/rules/matchName.js
Expand Up @@ -50,9 +50,14 @@ export default iterateJsdoc(({
}

const fixer = () => {
tag.source[0].tokens.name = tag.source[0].tokens.name.replace(
disallowNameRegex, replacement,
);
for (const src of tag.source) {
if (src.tokens.name) {
src.tokens.name = src.tokens.name.replace(
disallowNameRegex, replacement,
);
break;
}
}
};

let {
Expand Down
32 changes: 32 additions & 0 deletions test/rules/assertions/matchName.js
Expand Up @@ -325,6 +325,38 @@ export default {
],
options: [],
},
{
code: `
/**
* @param {
* someType
* } opt_a
*/
`,
errors: [
{
line: 3,
message: 'Only allowing names not matching `/^opt_/i` but found "opt_a".',
},
],
options: [
{
match: [
{
disallowName: '/^opt_/i',
replacement: '',
},
],
},
],
output: `
/**
* @param {
* someType
* } a
*/
`,
},
],
valid: [
{
Expand Down

0 comments on commit a23168d

Please sign in to comment.