Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6ad7e86

Browse files
mdjermanovicplatinumazure
authored andcommitted
Fix: no-extra-label autofix removes comments (#12298)
1 parentacec201 commit6ad7e86

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

‎lib/rules/no-extra-label.js‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,15 @@ module.exports = {
116116
node:labelNode,
117117
messageId:"unexpected",
118118
data:labelNode,
119-
fix:fixer=>fixer.removeRange([sourceCode.getFirstToken(node).range[1],labelNode.range[1]])
119+
fix(fixer){
120+
constbreakOrContinueToken=sourceCode.getFirstToken(node);
121+
122+
if(sourceCode.commentsExistBetween(breakOrContinueToken,labelNode)){
123+
returnnull;
124+
}
125+
126+
returnfixer.removeRange([breakOrContinueToken.range[1],labelNode.range[1]]);
127+
}
120128
});
121129
}
122130
return;

‎tests/lib/rules/no-extra-label.js‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,48 @@ ruleTester.run("no-extra-label", rule, {
106106
}
107107
`,
108108
errors:[{messageId:"unexpected",data:{name:"A"},type:"Identifier",line:2}]
109+
},
110+
111+
// Should not autofix if it would remove comments
112+
{
113+
code:"A: while(true) { /*comment*/break A; }",
114+
output:"A: while(true) { /*comment*/break; }",
115+
errors:[{messageId:"unexpected",data:{name:"A"}}]
116+
},
117+
{
118+
code:"A: while(true) { break/**/ A; }",
119+
output:null,
120+
errors:[{messageId:"unexpected",data:{name:"A"}}]
121+
},
122+
{
123+
code:"A: while(true) { continue /**/ A; }",
124+
output:null,
125+
errors:[{messageId:"unexpected",data:{name:"A"}}]
126+
},
127+
{
128+
code:"A: while(true) { break /**/A; }",
129+
output:null,
130+
errors:[{messageId:"unexpected",data:{name:"A"}}]
131+
},
132+
{
133+
code:"A: while(true) { continue/**/A; }",
134+
output:null,
135+
errors:[{messageId:"unexpected",data:{name:"A"}}]
136+
},
137+
{
138+
code:"A: while(true) { continue A/*comment*/; }",
139+
output:"A: while(true) { continue/*comment*/; }",
140+
errors:[{messageId:"unexpected",data:{name:"A"}}]
141+
},
142+
{
143+
code:"A: while(true) { break A//comment\n }",
144+
output:"A: while(true) { break//comment\n }",
145+
errors:[{messageId:"unexpected",data:{name:"A"}}]
146+
},
147+
{
148+
code:"A: while(true) { break A/*comment*/\nfoo() }",
149+
output:"A: while(true) { break/*comment*/\nfoo() }",
150+
errors:[{messageId:"unexpected",data:{name:"A"}}]
109151
}
110152
]
111153
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp