Using Autofix's .remove to remove an object property results in invalid code
See original GitHub issueTell us about your environment
- ESLint Version: 4.10.0
- Node Version: 9.0.0
- npm Version: 5.5.1
What parser (default, Babel-ESLint, etc.) are you using? babel-eslint
Please show your full configuration:
Configuration
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
export default {
meta: {
fixable: "code"
},
create(context) {
return {
Property(node) {
if (node.key.name === "b") {
context.report({
node,
message: "Remove b",
fix(fixer) {
return fixer.remove(node);
}
});
}
}
};
}
};
Running --fix
with this rule on the following code:
const hey = {
a: 'a',
b: 'b',
c: 'c'
}
eslint --fix
What did you expect to happen? It produces:
const hey = {
a: 'a',
c: 'c'
}
What actually happened? Please include the actual, raw output from ESLint. It produces:
const hey = {
a: 'a',
,
c: 'c'
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Removing all properties from a object - Stack Overflow
@VisioN's answer works if you want to clear that specific reference, but if you actually want to clear an object I found that...
Read more >java.util.Properties.remove java code examples - Tabnine
Extracts properties that start with or are equals to the specific prefix and returns them in a new Properties * object with the...
Read more >delete object inside object javascript Code Example
How do I remove a property from a JavaScript object? how remove prperty or object in javscript · remove object from array of...
Read more >Chapter 1. eXoJCR - JBoss.org
Returns an iterator * over the resulting <code>NodeType</code> objects. ... Node type is possible to remove only when the repository does not contain...
Read more >Using and Operating Ceph - CERN
We provide here a script to help user make sure all versions of their objects are deleted. Usage: $> ./s3-delete-all-object-versions.sh -b <bucket> [- ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Oh, sorry, the 2nd example does not regard the case multiple properties exist on the same line…
It needs to handle tokens around the property with
SourceCode
object.But whitespaces are not token, so this code does not remove whitespaces. If you remove whitespaces as well, you have to use
fixer.removeRange()
method.