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

Commitf5537b2

Browse files
mdjermanovickaicataldo
authored andcommitted
Fix: prefer-numeric-literals autofix removes comments (#12313)
1 parent11ae6fc commitf5537b2

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

‎lib/rules/prefer-numeric-literals.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ module.exports = {
9696
fix(fixer){
9797
constnewPrefix=prefixMap[node.arguments[1].value];
9898

99+
if(sourceCode.getCommentsInside(node).length){
100+
returnnull;
101+
}
102+
99103
if(+(newPrefix+node.arguments[0].value)!==parseInt(node.arguments[0].value,node.arguments[1].value)){
100104

101105
/*

‎tests/lib/rules/prefer-numeric-literals.js‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,68 @@ ruleTester.run("prefer-numeric-literals", rule, {
9090
code:"Number.parseInt('1️⃣3️⃣3️⃣7️⃣', 16);",
9191
output:null,// not fixed, javascript doesn't support emoji literals
9292
errors:[{message:"Use hexadecimal literals instead of Number.parseInt()."}]
93+
},
94+
95+
// Should not autofix if it would remove comments
96+
{
97+
code:"/* comment */Number.parseInt('11', 2);",
98+
output:"/* comment */0b11;",
99+
errors:1
100+
},
101+
{
102+
code:"Number/**/.parseInt('11', 2);",
103+
output:null,
104+
errors:1
105+
},
106+
{
107+
code:"Number//\n.parseInt('11', 2);",
108+
output:null,
109+
errors:1
110+
},
111+
{
112+
code:"Number./**/parseInt('11', 2);",
113+
output:null,
114+
errors:1
115+
},
116+
{
117+
code:"Number.parseInt(/**/'11', 2);",
118+
output:null,
119+
errors:1
120+
},
121+
{
122+
code:"Number.parseInt('11', /**/2);",
123+
output:null,
124+
errors:1
125+
},
126+
{
127+
code:"Number.parseInt('11', 2)/* comment */;",
128+
output:"0b11/* comment */;",
129+
errors:1
130+
},
131+
{
132+
code:"parseInt/**/('11', 2);",
133+
output:null,
134+
errors:1
135+
},
136+
{
137+
code:"parseInt(//\n'11', 2);",
138+
output:null,
139+
errors:1
140+
},
141+
{
142+
code:"parseInt('11'/**/, 2);",
143+
output:null,
144+
errors:1
145+
},
146+
{
147+
code:"parseInt('11', 2 /**/);",
148+
output:null,
149+
errors:1
150+
},
151+
{
152+
code:"parseInt('11', 2)//comment\n;",
153+
output:"0b11//comment\n;",
154+
errors:1
93155
}
94156
]
95157
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp