Skip to content

Conversation

@not-an-aardvark
Copy link
Member

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

[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[x] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

Please check each item to ensure your pull request is ready:

  • I've read the pull request guide
  • I've included tests for my change
  • I've updated documentation for my change (if appropriate)

What changes did you make? (Give an overview)

This adds an autofixer for no-useless-escape. When a character is being uselessly escaped (e.g. "\z"), the fixer removes the backslash ("z").

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

Nothing in particular.

@mention-bot
Copy link

@not-an-aardvark, thanks for your PR! By analyzing the annotation information on this pull request, we identified @pmcelhaney, @vitorbal and @platinumazure to be potential reviewers

@eslintbot
Copy link

LGTM

@platinumazure
Copy link
Member

I'm not sure we should have a fixer for this rule. Most of the time, when someone is asking in chat about why the rule reported a particular character sequence, it turns out they were intending to have a backslash literal all along, so the correct fix was to double up the backslashes.

I don't think we can know with certainty what the user's intent was (\\: vs :), so I am 👎 to including autofix on this rule.

@not-an-aardvark
Copy link
Member Author

@platinumazure Note that there are already a lot of existing fixers that do things like this. For example, indent will fix this:

if (condition)
  doTheFirstThing();
  doTheSecondThing();

...to this:

if (condition)
  doTheFirstThing();
doTheSecondThing();

...which is semantically the same, even though the user might have intended to do this:

if (condition) {
  doTheFirstThing();
  doTheSecondThing();
}

@mysticatea
Copy link
Member

mysticatea commented Sep 19, 2016

Thank you for this PR!

I had thought the fixing is very clear until I read @platinumazure 's comment.

Granted, there are issues about that: #5831, #6148, #6514, #6842
Their intentions were \\, and no-useless-escape helped them to fix the bug.

@mysticatea mysticatea added enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Sep 19, 2016
@mysticatea
Copy link
Member

Personally, I like this fixing. 😟

@platinumazure
Copy link
Member

Sorry, but I'm not convinced fixing is a good idea here. The reason is because, as far as I can tell, it's almost 50/50 whether the correct fix is to add an extra backslash, or to remove the existing backslash and use the unescaped character. I don't think that's something we can predict with any accuracy.

If someone can convince me of how we can reliably predict what the correct fix is for a given report, I'll reconsider. But until then, I remain opposed.

@nzakas
Copy link
Member

nzakas commented Oct 18, 2016

I'm inclined to agree with @platinumazure that the correct fix in this case isn't always obvious, so it would be best not to try to fix it.

As this has already been open for a month and there's some 👎s here, I'm closing.

@nzakas nzakas closed this Oct 18, 2016
@not-an-aardvark not-an-aardvark deleted the no-useless-escape-autofix branch October 18, 2016 18:12
@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

archived due to age This issue has been archived; please open a new issue for any further discussion enhancement This change enhances an existing feature of ESLint evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants