Skip to content

Commit

Permalink
Revert "fix: extend the autofix range in comma-dangle to ensure the l…
Browse files Browse the repository at this point in the history
…ast element (eslint#15669)"

This reverts commit ac4bb45.
  • Loading branch information
srijan-deepsource committed May 30, 2022
1 parent 59997e5 commit f569d7d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 108 deletions.
28 changes: 4 additions & 24 deletions lib/rules/comma-dangle.js
Expand Up @@ -243,18 +243,8 @@ module.exports = {
node: lastItem,
loc: trailingToken.loc,
messageId: "unexpected",
*fix(fixer) {
yield fixer.remove(trailingToken);

/*
* Extend the range of the fix to include surrounding tokens to ensure
* that the element after which the comma is removed stays _last_.
* This intentionally makes conflicts in fix ranges with rules that may be
* adding or removing elements in the same autofix pass.
* https://github.com/eslint/eslint/issues/15660
*/
yield fixer.insertTextBefore(sourceCode.getTokenBefore(trailingToken), "");
yield fixer.insertTextAfter(sourceCode.getTokenAfter(trailingToken), "");
fix(fixer) {
return fixer.remove(trailingToken);
}
});
}
Expand Down Expand Up @@ -292,18 +282,8 @@ module.exports = {
end: astUtils.getNextLocation(sourceCode, trailingToken.loc.end)
},
messageId: "missing",
*fix(fixer) {
yield fixer.insertTextAfter(trailingToken, ",");

/*
* Extend the range of the fix to include surrounding tokens to ensure
* that the element after which the comma is inserted stays _last_.
* This intentionally makes conflicts in fix ranges with rules that may be
* adding or removing elements in the same autofix pass.
* https://github.com/eslint/eslint/issues/15660
*/
yield fixer.insertTextBefore(trailingToken, "");
yield fixer.insertTextAfter(sourceCode.getTokenAfter(trailingToken), "");
fix(fixer) {
return fixer.insertTextAfter(trailingToken, ",");
}
});
}
Expand Down
84 changes: 0 additions & 84 deletions tests/lib/rules/comma-dangle.js
Expand Up @@ -10,7 +10,6 @@
//------------------------------------------------------------------------------

const path = require("path"),
{ unIndent } = require("../../_utils"),
rule = require("../../../lib/rules/comma-dangle"),
{ RuleTester } = require("../../../lib/rule-tester");

Expand All @@ -36,29 +35,6 @@ function parser(name) {

const ruleTester = new RuleTester();

ruleTester.defineRule("add-named-import", {
meta: {
fixable: "code"
},
create(context) {
return {
ImportDeclaration(node) {
const sourceCode = context.getSourceCode();
const closingBrace = sourceCode.getLastToken(node, token => token.value === "}");
const addComma = sourceCode.getTokenBefore(closingBrace).value !== ",";

context.report({
message: "Add I18nManager.",
node,
fix(fixer) {
return fixer.insertTextBefore(closingBrace, `${addComma ? "," : ""}I18nManager`);
}
});
}
};
}
});

ruleTester.run("comma-dangle", rule, {
valid: [
"var foo = { bar: 'baz' }",
Expand Down Expand Up @@ -1790,66 +1766,6 @@ let d = 0;export {d,};
output: "foo(a)",
parserOptions: { ecmaVersion: 8 },
errors: [{ messageId: "unexpected" }]
},

// https://github.com/eslint/eslint/issues/15660
{
code: unIndent`
/*eslint add-named-import:1*/
import {
StyleSheet,
View,
TextInput,
ImageBackground,
Image,
TouchableOpacity,
SafeAreaView
} from 'react-native';
`,
output: unIndent`
/*eslint add-named-import:1*/
import {
StyleSheet,
View,
TextInput,
ImageBackground,
Image,
TouchableOpacity,
SafeAreaView,
} from 'react-native';
`,
options: [{ imports: "always-multiline" }],
parserOptions: { ecmaVersion: 6, sourceType: "module" },
errors: 2
},
{
code: unIndent`
/*eslint add-named-import:1*/
import {
StyleSheet,
View,
TextInput,
ImageBackground,
Image,
TouchableOpacity,
SafeAreaView,
} from 'react-native';
`,
output: unIndent`
/*eslint add-named-import:1*/
import {
StyleSheet,
View,
TextInput,
ImageBackground,
Image,
TouchableOpacity,
SafeAreaView
} from 'react-native';
`,
options: [{ imports: "never" }],
parserOptions: { ecmaVersion: 6, sourceType: "module" },
errors: 2
}
]
});

0 comments on commit f569d7d

Please sign in to comment.