Skip to content

Commit

Permalink
fix(match-name): revert to prior correct behavior of ignoring optio…
Browse files Browse the repository at this point in the history
…nal and default code surrounding name
  • Loading branch information
brettz9 committed Oct 14, 2024
1 parent c63da46 commit 7c0b8c6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/rules/match-name.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,6 @@ class A {
* @typedef {object} Test
* @property {T} test
*/
// "jsdoc/match-name": ["error"|"warn", {"match":[{"allowName":"/^\\[?[A-Z]{1}(=.*\\])$/","message":"The name should be a single capital letter.","tags":["template"]}]}]
// "jsdoc/match-name": ["error"|"warn", {"match":[{"allowName":"/^[A-Z]{1}$/","message":"The name should be a single capital letter.","tags":["template"]}]}]
````

13 changes: 7 additions & 6 deletions src/rules/matchName.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ export default iterateJsdoc(({

let reported = false;
for (const tag of applicableTags) {
const allowed = !allowNameRegex || allowNameRegex.test(tag.name);
const disallowed = disallowNameRegex && disallowNameRegex.test(tag.name);
const tagName = tag.name.replace(/^\[/u, '').replace(/(=.*)?\]$/u, '');
const allowed = !allowNameRegex || allowNameRegex.test(tagName);
const disallowed = disallowNameRegex && disallowNameRegex.test(tagName);
const hasRegex = allowNameRegex || disallowNameRegex;
if (hasRegex && allowed && !disallowed) {
continue;
Expand All @@ -66,10 +67,10 @@ export default iterateJsdoc(({
if (!message) {
if (hasRegex) {
message = disallowed ?
`Only allowing names not matching \`${disallowNameRegex}\` but found "${tag.name}".` :
`Only allowing names matching \`${allowNameRegex}\` but found "${tag.name}".`;
`Only allowing names not matching \`${disallowNameRegex}\` but found "${tagName}".` :
`Only allowing names matching \`${allowNameRegex}\` but found "${tagName}".`;
} else {
message = `Prohibited context for "${tag.name}".`;
message = `Prohibited context for "${tagName}".`;
}
}

Expand All @@ -86,7 +87,7 @@ export default iterateJsdoc(({
// Could also supply `context`, `comment`, `tags`
allowName,
disallowName,
name: tag.name,
name: tagName,
},
);
if (!hasRegex) {
Expand Down
2 changes: 1 addition & 1 deletion test/rules/assertions/matchName.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ export default {
`,
options: [{
match: [{
allowName: "/^\\[?[A-Z]{1}(=.*\\])$/",
allowName: "/^[A-Z]{1}$/",
message: "The name should be a single capital letter.",
tags: ["template"],
}],
Expand Down

0 comments on commit 7c0b8c6

Please sign in to comment.