More granular config for 'object-shorthand'
See original GitHub issue_Duplicating the rationale from https://github.com/palantir/tslint/issues/3778_
The object-shorthand
rule currently does not offer granularity for enforcing/disallowing shorthand separately for property assignment vs method declarations.
I would prefer to allow (but not enforce!) shorthand for method declarations, but disallow shorthand for property assignments.
Here’s an example of how I would like to configure the object-shorthand
rule:
const someValue = 20;
const myObj = {
// error: shorthand property assignment not allowed
someValue,
// valid
anotherValue: someValue,
// valid
someMethod(): number {
return 42;
},
// also valid
anotherMethod: (): number => {
return 42;
}
};
The motivation for this is that shorthand method declaration is very convenient and improves readability, while shorthand property assignment creates a coupling between the object’s property name and a local variable name that can lead to bugs when refactoring code later.
What rule do you want to change?
object-shorthand
Does this change cause the rule to produce more or fewer warnings?
Number of warnings stays the same
How will the change be implemented? (New option, new default behavior, etc.)?
More granular config options similar to TSLint version
Are you willing to submit a pull request to implement this change?
Yes
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:11 (5 by maintainers)
Top GitHub Comments
@katerberg thanks, I remember that, and that’s what I’m waiting for 👍
The team has made the difficult decision to freeze stylistic rules (please see https://eslint.org/blog/2020/05/changes-to-rules-policies for more details), and we unfortunately won’t be able to accept this proposal.
Thanks for contributing to ESLint and for being willing to implement your proposal.