Skip to content

Commit 7c0b8c6

Browse files
committed
fix(match-name): revert to prior correct behavior of ignoring optional and default code surrounding name
1 parent c63da46 commit 7c0b8c6

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

docs/rules/match-name.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,6 @@ class A {
251251
* @typedef {object} Test
252252
* @property {T} test
253253
*/
254-
// "jsdoc/match-name": ["error"|"warn", {"match":[{"allowName":"/^\\[?[A-Z]{1}(=.*\\])$/","message":"The name should be a single capital letter.","tags":["template"]}]}]
254+
// "jsdoc/match-name": ["error"|"warn", {"match":[{"allowName":"/^[A-Z]{1}$/","message":"The name should be a single capital letter.","tags":["template"]}]}]
255255
````
256256

src/rules/matchName.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ export default iterateJsdoc(({
3838

3939
let reported = false;
4040
for (const tag of applicableTags) {
41-
const allowed = !allowNameRegex || allowNameRegex.test(tag.name);
42-
const disallowed = disallowNameRegex && disallowNameRegex.test(tag.name);
41+
const tagName = tag.name.replace(/^\[/u, '').replace(/(=.*)?\]$/u, '');
42+
const allowed = !allowNameRegex || allowNameRegex.test(tagName);
43+
const disallowed = disallowNameRegex && disallowNameRegex.test(tagName);
4344
const hasRegex = allowNameRegex || disallowNameRegex;
4445
if (hasRegex && allowed && !disallowed) {
4546
continue;
@@ -66,10 +67,10 @@ export default iterateJsdoc(({
6667
if (!message) {
6768
if (hasRegex) {
6869
message = disallowed ?
69-
`Only allowing names not matching \`${disallowNameRegex}\` but found "${tag.name}".` :
70-
`Only allowing names matching \`${allowNameRegex}\` but found "${tag.name}".`;
70+
`Only allowing names not matching \`${disallowNameRegex}\` but found "${tagName}".` :
71+
`Only allowing names matching \`${allowNameRegex}\` but found "${tagName}".`;
7172
} else {
72-
message = `Prohibited context for "${tag.name}".`;
73+
message = `Prohibited context for "${tagName}".`;
7374
}
7475
}
7576

@@ -86,7 +87,7 @@ export default iterateJsdoc(({
8687
// Could also supply `context`, `comment`, `tags`
8788
allowName,
8889
disallowName,
89-
name: tag.name,
90+
name: tagName,
9091
},
9192
);
9293
if (!hasRegex) {

test/rules/assertions/matchName.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ export default {
553553
`,
554554
options: [{
555555
match: [{
556-
allowName: "/^\\[?[A-Z]{1}(=.*\\])$/",
556+
allowName: "/^[A-Z]{1}$/",
557557
message: "The name should be a single capital letter.",
558558
tags: ["template"],
559559
}],

0 commit comments

Comments
 (0)