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: no-mixed-spaces-and-tabs reports multiline strings #12566

Merged
merged 2 commits into from Dec 23, 2019

Conversation

mdjermanovic
Copy link
Member

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

[X] Bug fix

Tell us about your environment

  • ESLint Version: 6.6.0
  • Node Version: 10.16.0
  • npm Version: 6.9.0

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

default

Please show your full configuration:

Configuration
module.exports = {
    parserOptions: {
        ecmaVersion: 2015
    }
};

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

Online Demo Link

/* eslint no-mixed-spaces-and-tabs: error */

'\
	 ' // tab and space at the beginning of this line

What did you expect to happen?

No errors. Similar to how the rule ignores the content in template literals, it should ignore the content in strings.

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

4:2  error  Mixed spaces and tabs  no-mixed-spaces-and-tabs

What changes did you make? (Give an overview)

Fixed the code to ignore mixed spaces and tabs in strings.

Also, the code is simplified and (should be) optimized.

  • Since the rule checks for mixed spaces and tabs only at the beginning of the lines, there is no need to compare the range with the comments' ranges. Comparing just lines should do the same thing.
  • Multiline strings and template literals with mixed spaces and tabs at the beginning of a line are rare. Seems more optimal to chech this at the very last point before reporting the error, rather than to visit all Literal and TemplateElement nodes.

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

Refactoring, is the code equivalent to the previous version? (apart from the string fix)

column is always same, because the captured index is always 0. This doesn't affect the correctness of this rule, but it would be nice to improve the reported locations. Since this PR already has a big diff and the regexes should be changed to achieve this, it's better to do that in a separate PR.

@mdjermanovic mdjermanovic added bug ESLint is working incorrectly rule Relates to ESLint's core rules evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Nov 14, 2019
@kaicataldo kaicataldo added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Dec 21, 2019
@kaicataldo
Copy link
Member

Agreed that this should be considered a bug 👍

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.

Thank you!

@kaicataldo kaicataldo merged commit 1aff21b into master Dec 23, 2019
@kaicataldo kaicataldo deleted the nomixedst-strings branch December 23, 2019 20:52
@kaicataldo
Copy link
Member

Thanks for contributing!

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Jun 22, 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 Jun 22, 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

2 participants