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

3.16.0 regression: padded-blocks autofix can generate incorrect code #8116

Closed
alangpierce opened this issue Feb 21, 2017 · 1 comment · Fixed by renovatebot/renovate#116 · May be fixed by iamhunter/teammates#4
Closed

3.16.0 regression: padded-blocks autofix can generate incorrect code #8116

alangpierce opened this issue Feb 21, 2017 · 1 comment · Fixed by renovatebot/renovate#116 · May be fixed by iamhunter/teammates#4
Assignees
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 core Relates to ESLint's core APIs and features patch candidate This issue may necessitate a patch release in the next few days regression Something broke

Comments

@alangpierce
Copy link
Contributor

Tell us about your environment

  • ESLint Version: 3.16.0
  • Node Version: 6.9.1
  • npm Version: 3.10.8

What parser (default, Babel-ESLint, etc.) are you using?
default

Please show your full configuration:

module.exports = {
  rules: {
    "padded-blocks": ['error', 'never'],
  }
};

(This is the value specified by eslint-config-airbnb.)

What did you do? Please include the actual source code causing the issue.

I ran eslint --fix on this source code:

function f() { // a

  b;
}

What did you expect to happen?

I expected it to fix the formatting and generate correct code.

What actually happened? Please include the actual, raw output from ESLint.

eslint generated this output:

➜  eslint_test_3 git:(master) ./node_modules/.bin/eslint --fix test.js

/Users/alanpierce/code/eslint_test_3/test.js
  6:1  error  Parsing error: Unexpected token

✖ 1 problem (1 error, 0 warnings)

And the JS file was changed to have these contents:

function f() {
function f() { // a

  b;
}

This is a syntax error, so the file fails to parse after this change.

When I try this on eslint 3.15.0, it doesn't have any problems.

This is breaking the coffeelint example build for the decaffeinate project. The lexical_linter.js file has two static initClass lines near the start, which causes a syntax error. (The example builds are a bit like eslint-canary for the decaffeinate project, and one of the conversion steps is to run eslint --fix on the resulting JS code.)

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Feb 21, 2017
@not-an-aardvark
Copy link
Member

I can reproduce this, thanks for reporting.

Based on git bisect it was introduced in fcc38db.

@not-an-aardvark not-an-aardvark added accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly core Relates to ESLint's core APIs and features regression Something broke and removed triage An ESLint team member will look at this issue soon labels Feb 21, 2017
@not-an-aardvark not-an-aardvark self-assigned this Feb 21, 2017
not-an-aardvark added a commit that referenced this issue Feb 21, 2017
The padded-blocks rule sometimes produces a fix range where the start index of the range is larger than the end index. Due to the changes in fcc38db, when source-code-fixer encountered such a range, it would output the text between the end index and the start index twice. This commit ensures that source-code-fixer behaves the same way as it previously did when it encounters an inverted fix range (it should act as if the start and end indices were equal). In the future, we should also update padded-blocks to avoid producing inverted fix ranges.
@not-an-aardvark not-an-aardvark added the patch candidate This issue may necessitate a patch release in the next few days label Feb 21, 2017
not-an-aardvark added a commit that referenced this issue Feb 21, 2017
The padded-blocks rule sometimes produces a fix range where the start index of the range is larger than the end index. Due to the changes in fcc38db, when source-code-fixer encountered such a range, it would output the text between the end index and the start index twice. This commit ensures that source-code-fixer behaves the same way as it previously did when it encounters an inverted fix range (it should act as if the start and end indices were equal). In the future, we should also update padded-blocks to avoid producing inverted fix ranges.
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@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 Feb 6, 2018
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 core Relates to ESLint's core APIs and features patch candidate This issue may necessitate a patch release in the next few days regression Something broke
Projects
None yet
3 participants