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

no-trailing-spaces: Fix produces wrong results for windows style line endings #4050

Closed
gyandeeps opened this issue Oct 5, 2015 · 0 comments
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

Comments

@gyandeeps
Copy link
Member

Eslint: 1.6
Parser: default

Code:

            "var short2 = true;\r\n" +
            "\r\n" +
            "module.exports = {\r\n" +
            "  short: short,    \r\n" +
            "  short2: short\r\n" +
            "}\r\n"

Output:

            "var short2 = true;\r\n" +
            "\r\n" +
            "module.exports = {\r\n" +
            "  short: sho   \r\n" +   //----> this is where the issue is
            "  short2: short\r\n" +
            "}\r\n"

The above code is from existing unit test with \n: https://github.com/eslint/eslint/blob/master/tests/lib/rules/no-trailing-spaces.js#L69

FYI, the above code works fine if you have \n line endings.

Findings:
This is happening because \n occupies one spot on the source code array vs \r\n occupies 2 spots. So when the fixes are calculated by the rule, it only considers one spot of line ending by default.

@gyandeeps gyandeeps 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 labels Oct 5, 2015
nzakas added a commit that referenced this issue Oct 6, 2015
Fix: `no-trailing-spaces` autofix to handle linebreaks (fixes #4050)
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 7, 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 7, 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 rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

1 participant