Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(match-name): revert to prior correct behavior of ignoring optional and default code surrounding name #1331

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading