Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: object-shorthand providing invalid fixes for typescript #12260

Merged
merged 4 commits into from Sep 14, 2019
Merged

Fix: object-shorthand providing invalid fixes for typescript #12260

merged 4 commits into from Sep 14, 2019

Conversation

bradzacher
Copy link
Contributor

@bradzacher bradzacher commented Sep 11, 2019

What is the purpose of this pull request? (put an "X" next to item)

[x] Bug fix

Related: typescript-eslint/typescript-eslint#124

The bug is that currently the fixer adds extra parentheses when fixing a TS arrow function with a return type:

/* eslint object-shorthand: [1, "always", { avoidExplicitReturnArrows: true }] */

const test = {
  key: (arg: any): any => {}
}

///// fixes to

const test = {
  key((arg: any): any) {}
}

This happens because the rule currently searches backwards from the => to find a ), to determine if it should wrap the arguments in parentheses. It obviously instead finds a return type annotation, hence the breakage.

What changes did you make? (Give an overview)

Adjusted the fix algorithm for arrow functions so that it searches from the start of the arrow function expression instead.

I added a TS-specific test for this - happy to remove it if you don't want the burden.

Copy link
Member

@platinumazure platinumazure left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raising one question.

I'm personally in favor of adding a test that simulates the Typescript case, but I'll defer to team consensus on that one.

lib/rules/object-shorthand.js Outdated Show resolved Hide resolved
@bradzacher
Copy link
Contributor Author

I've refactored the code so it doesn't rely on a check for async to get the first token.

I've also added a test with typescript code to help prevent a regression.

Copy link
Member

@mysticatea mysticatea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@ilyavolodin ilyavolodin added accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Sep 14, 2019
@ilyavolodin ilyavolodin merged commit 365331a into eslint:master Sep 14, 2019
@bradzacher bradzacher deleted the fix-object-shorthand branch September 15, 2019 17:38
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Mar 13, 2020
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Mar 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants