Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

[Feature Request] Add more granularity to object-literal-shorthand rule options #3778

Closed
UselessPickles opened this issue Mar 16, 2018 · 3 comments · Fixed by #4842
Closed

Comments

@UselessPickles
Copy link
Contributor

The object-literal-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-literal-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.

@JoshuaKGoldberg
Copy link
Contributor

JoshuaKGoldberg commented Jul 4, 2019

Note: per #4534, this issue will be closed in less than a month if no PR is sent to add the rule. If you really need the rule, custom rules are always an option and can be maintained outside this repo!

Edit: never mind!

@pablobirukov
Copy link
Contributor

Reopened #4139 would resolve the issue, if you consider releasing a new version

@JoshuaKGoldberg
Copy link
Contributor

Oh hey, this actually won't be closed, as it's a feature request and not a rule suggestion. Whoops!

And yes, absolutely! If you're up for reopening (or recreating) #4139, we'd be happy to review it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants