Add autofix for object-shorthand 'consistent' option
See original GitHub issue(edit by @not-an-aardvark: See this comment for the updated enhancement proposal.)
Tell us about your environment
- ESLint Version: 3.10.1
- Node Version: 6.7.0
- npm Version: 3.10.3
What parser (default, Babel-ESLint, etc.) are you using? default
Please show your full configuration:
{
"parserOptions": {
"ecmaVersion": 6,
},
"rules": {
"object-shorthand": ["error", "consistent"],
}
}
What did you do? Please include the actual source code causing the issue.
let a = 1;
let b = {
a,
hello: 'world',
};
What did you expect to happen?
I expected eslint --fix
to change the a
line to a: a,
.
What actually happened? Please include the actual, raw output from ESLint.
2:9 error Unexpected mix of shorthand and non-shorthand properties object-shorthand
When I change the object-shorthand
rule from consistent
to never
, the autofix works. The autofix also fails for consistent-as-needed
.
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
object-shorthand - ESLint - Pluggable JavaScript Linter
"consistent-as-needed" ensures that either all shorthand or all long-form will be used in an object literal, but ensures all shorthand whenever possible.
Read more >ESLint v2.10.0 released - ESLint中文文档
ESLint v2.10.0 released. We just pushed ESLint v2.10.0, which is a minor release upgrade of ESLint. This release adds some new features and...
Read more >tslint: benefit of "object-literal-shorthand" - Stack Overflow
I guess the rule allows 1. to make you aware of this shorthand syntax 2. to promote consistency in naming by encouraging you...
Read more >tslint-eslint-rules - npm Package Health Analysis | Snyk
In your tslint.json file, insert the rules as described below. ... Not applicable, disallow duplicate keys when creating object literals (recommended).
Read more >eslint-plugin-vue - Awesome JS
#2045 Fixed vue/attribute-hyphenation rule to disable autofix for attributes ... #1982 Added consistent option to vue/padding-line-between-tags rule.
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 Free
Top 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
What rule do you want to change?
object-shorthand
Does this change cause the rule to produce more or fewer warnings?
The same amount
How will the change be implemented? (New option, new default behavior, etc.)?
This will change the default behavior for autofixing.
Please provide some example code that this change will affect:
What does the rule currently do for this code?
It reports an error, but does not autofix it.
What will the rule do after it’s changed?
It will autofix the cases to:
In other words, the
consistent
option will update the object to use longform for all properties. Theconsistent-as-needed
option will use shorthand for all properties if possible, otherwise it will use longform for all properties.I think this is in line with what the user would expect. The only potential surprise would be with the
consistent
option using longform for all properties. However, if people want to prefer shorthand for all properties in cases like this, they can simply useconsistent-as-needed
. (Note that thequote-props
fixer already functions like this.)Thanks for your interest in improving ESLint. Unfortunately, it looks like this issue didn’t get enough support from the team and so I’m closing it. While we wish we’d be able to accommodate everyone’s requests, we do need to prioritize. We’ve found that issues failing to reach consensus after a long time tend to never do it, and as such, we close those issues. This doesn’t mean the idea isn’t interesting, just that it’s not something the team can commit to.