Skip to content
Permalink
Browse files

Fix: no-extra-bind autofix removes comments (#12293)

  • Loading branch information
mdjermanovic authored and platinumazure committed Sep 29, 2019
1 parent 6ad7e86 commit 0e68677ec0aaf060a071ecf71e4af954dddb6af0
Showing with 69 additions and 1 deletion.
  1. +7 −1 lib/rules/no-extra-bind.js
  2. +62 −0 tests/lib/rules/no-extra-bind.js
@@ -40,6 +40,7 @@ module.exports = {
},

create(context) {
const sourceCode = context.getSourceCode();
let scopeInfo = null;

/**
@@ -71,8 +72,13 @@ module.exports = {
return null;
}

const firstTokenToRemove = context.getSourceCode()
const firstTokenToRemove = sourceCode
.getFirstTokenBetween(node.parent.object, node.parent.property, astUtils.isNotClosingParenToken);
const lastTokenToRemove = sourceCode.getLastToken(node.parent.parent);

if (sourceCode.commentsExistBetween(firstTokenToRemove, lastTokenToRemove)) {
return null;
}

return fixer.removeRange([firstTokenToRemove.range[0], node.parent.parent.range[1]]);
}
@@ -97,6 +97,68 @@ ruleTester.run("no-extra-bind", rule, {
code: "var a = function() {}.bind(b.c)",
output: null,
errors
},

// Should not autofix if it would remove comments
{
code: "var a = function() {}/**/.bind(b)",
output: "var a = function() {}/**/",
errors
},
{
code: "var a = function() {}/**/['bind'](b)",
output: "var a = function() {}/**/",
errors
},
{
code: "var a = function() {}//comment\n.bind(b)",
output: "var a = function() {}//comment\n",
errors
},
{
code: "var a = function() {}./**/bind(b)",
output: null,
errors
},
{
code: "var a = function() {}[/**/'bind'](b)",
output: null,
errors
},
{
code: "var a = function() {}.//\nbind(b)",
output: null,
errors
},
{
code: "var a = function() {}.bind/**/(b)",
output: null,
errors
},
{
code: "var a = function() {}.bind(\n/**/b)",
output: null,
errors
},
{
code: "var a = function() {}.bind(b/**/)",
output: null,
errors
},
{
code: "var a = function() {}.bind(b//\n)",
output: null,
errors
},
{
code: "var a = function() {}.bind(b\n/**/)",
output: null,
errors
},
{
code: "var a = function() {}.bind(b)/**/",
output: "var a = function() {}/**/",
errors
}
]
});

0 comments on commit 0e68677

Please sign in to comment.
You can’t perform that action at this time.