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

Commit0e68677

Browse files
mdjermanovicplatinumazure
authored andcommitted
Fix: no-extra-bind autofix removes comments (#12293)
1 parent6ad7e86 commit0e68677

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ module.exports = {
4040
},
4141

4242
create(context){
43+
constsourceCode=context.getSourceCode();
4344
letscopeInfo=null;
4445

4546
/**
@@ -71,8 +72,13 @@ module.exports = {
7172
returnnull;
7273
}
7374

74-
constfirstTokenToRemove=context.getSourceCode()
75+
constfirstTokenToRemove=sourceCode
7576
.getFirstTokenBetween(node.parent.object,node.parent.property,astUtils.isNotClosingParenToken);
77+
constlastTokenToRemove=sourceCode.getLastToken(node.parent.parent);
78+
79+
if(sourceCode.commentsExistBetween(firstTokenToRemove,lastTokenToRemove)){
80+
returnnull;
81+
}
7682

7783
returnfixer.removeRange([firstTokenToRemove.range[0],node.parent.parent.range[1]]);
7884
}

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

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,68 @@ ruleTester.run("no-extra-bind", rule, {
9797
code:"var a = function() {}.bind(b.c)",
9898
output:null,
9999
errors
100+
},
101+
102+
// Should not autofix if it would remove comments
103+
{
104+
code:"var a = function() {}/**/.bind(b)",
105+
output:"var a = function() {}/**/",
106+
errors
107+
},
108+
{
109+
code:"var a = function() {}/**/['bind'](b)",
110+
output:"var a = function() {}/**/",
111+
errors
112+
},
113+
{
114+
code:"var a = function() {}//comment\n.bind(b)",
115+
output:"var a = function() {}//comment\n",
116+
errors
117+
},
118+
{
119+
code:"var a = function() {}./**/bind(b)",
120+
output:null,
121+
errors
122+
},
123+
{
124+
code:"var a = function() {}[/**/'bind'](b)",
125+
output:null,
126+
errors
127+
},
128+
{
129+
code:"var a = function() {}.//\nbind(b)",
130+
output:null,
131+
errors
132+
},
133+
{
134+
code:"var a = function() {}.bind/**/(b)",
135+
output:null,
136+
errors
137+
},
138+
{
139+
code:"var a = function() {}.bind(\n/**/b)",
140+
output:null,
141+
errors
142+
},
143+
{
144+
code:"var a = function() {}.bind(b/**/)",
145+
output:null,
146+
errors
147+
},
148+
{
149+
code:"var a = function() {}.bind(b//\n)",
150+
output:null,
151+
errors
152+
},
153+
{
154+
code:"var a = function() {}.bind(b\n/**/)",
155+
output:null,
156+
errors
157+
},
158+
{
159+
code:"var a = function() {}.bind(b)/**/",
160+
output:"var a = function() {}/**/",
161+
errors
100162
}
101163
]
102164
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp