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: duplicated autofix output for inverted fix ranges (fixes #8116) #8117

Merged
merged 1 commit into from Feb 22, 2017

Conversation

Projects
None yet
7 participants
@not-an-aardvark
Copy link
Member

commented Feb 21, 2017

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

[x] Bug fix (#8116)

What changes did you make? (Give an overview)

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.

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

Nothing in particular

Fix: duplicated autofix output for inverted fix ranges (fixes #8116)
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.
@eslintbot

This comment has been minimized.

Copy link

commented Feb 21, 2017

LGTM

@mention-bot

This comment has been minimized.

Copy link

commented Feb 21, 2017

@not-an-aardvark, thanks for your PR! By analyzing the history of the files in this pull request, we identified @mysticatea, @nzakas and @alberto to be potential reviewers.

@mysticatea
Copy link
Member

left a comment

LGTM, thank you!

@alangpierce

This comment has been minimized.

Copy link
Contributor

commented Feb 21, 2017

Thanks! I just re-ran my failing test suite with this patch applied to eslint and the test suite passes now.

},
{
code: "function foo() { // a\n\n b;\n}",
output: "function foo() {\n // a\n\n b;\n}",

This comment has been minimized.

Copy link
@alberto

alberto Feb 22, 2017

Member

This isn't doing the right thing. Was this the previous behaviour?

This comment has been minimized.

Copy link
@not-an-aardvark

not-an-aardvark Feb 22, 2017

Author Member

Yes.

* the text between the end and the start doesn't get duplicated.
* https://github.com/eslint/eslint/issues/8116
*/
lastPos = Math.max(start, end);

This comment has been minimized.

Copy link
@alberto

alberto Feb 22, 2017

Member

A negative range looks like a problem with the fixer to me. Shouldn't we skip them instead?

This comment has been minimized.

Copy link
@mysticatea

mysticatea Feb 22, 2017

Member

Ah, it's nice as well.

This comment has been minimized.

Copy link
@not-an-aardvark

not-an-aardvark Feb 22, 2017

Author Member

We could do that, but it might be a breaking change. Given that one of the core rules had a negative range, it seems likely that there are custom rules that use a negative range as well. The goal of this PR just is to fix the regression by restoring the previous behavior.

agreed to go with this for the patch release

@gyandeeps gyandeeps merged commit ff8a80c into master Feb 22, 2017

5 checks passed

continuous-integration/appveyor/branch AppVeyor build succeeded
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
licence/cla Contributor License Agreement is signed.
Details

@not-an-aardvark not-an-aardvark deleted the backwards-fix-ranges branch Feb 22, 2017

@eslint eslint bot locked and limited conversation to collaborators Feb 6, 2018

@eslint eslint bot added the archived due to age label Feb 6, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.