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: arrow-body-style crash with object literal body (fixes #12884) #12886

Merged
merged 1 commit into from Feb 28, 2020

Conversation

mdjermanovic
Copy link
Member

Prerequisites checklist

  • I have read the contributing guidelines.
  • The team has reached consensus on the changes proposed in this pull request. If not, I understand that the evaluation process will begin with this pull request and won't be merged until the team has reached consensus.

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

[x] Bug fix

Fixes #12884

arrow-body-style autofix crashes or produces invalid code while trying to convert object literal expression body to a block body, whenever ( and { are not adjacent:

  • This works well: () => ({})
  • This throws (there's a space between): () => ( {}) Demo
  • This removes the wrong closing paren: (() => ( {})) fixed to (() => {return {})} Demo

What changes did you make? (Give an overview)

Fixed to code to pass the brace token instead of the paren token to sourceCode#getNodeByRangeIndex

Is there anything you'd like reviewers to focus on?

In this branch, auto-fixer has also to account for the ASI (it used to crash in all situations where ASI can happen, so it wasn't observable). In particular, for a code where ( and { are not on the same line. This is solved by replacing ( with a block { and inserting return before the object's {. Is it okay?

The code from the original issue:

/* eslint  "arrow-body-style": ["error", "always"] */

parsedYears     = _map(years, (year) => (
      {
          index : year,
          title : splitYear(year)
      }
));

will be auto-fixed to:

/* eslint  "arrow-body-style": ["error", "always"] */

parsedYears     = _map(years, (year) => {
      return {
          index : year,
          title : splitYear(year)
      }
});

@mdjermanovic mdjermanovic added bug ESLint is working incorrectly rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion autofix This change is related to ESLint's autofixing capabilities labels Feb 8, 2020
Copy link
Member

@kaicataldo kaicataldo left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@nzakas nzakas merged commit 4797fb2 into master Feb 28, 2020
@nzakas nzakas deleted the issue12884 branch February 28, 2020 01:19
montmanu pushed a commit to montmanu/eslint that referenced this pull request Mar 4, 2020
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Aug 28, 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 Aug 28, 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 autofix This change is related to ESLint's autofixing capabilities 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.

TypeError: Cannot read property 'range' of null with arrow-body-style
3 participants