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

Avoid line ending inconsistencies #3231

Merged
merged 4 commits into from
Jan 7, 2019

Conversation

ddbeck
Copy link
Collaborator

@ddbeck ddbeck commented Dec 21, 2018

Prompted by #3224, this PR replaces line endings and some other invisible characters in the linter diff output with their respective escape sequences.

For example, if you have CRLF line endings in a JSON file, then the resulting linter diff makes it seem as if both the expected and actual lines are the same.

Unfortunately, I suspect my implementation is rather naive. I really want to believe there's some kind of regex trickery that would generalize this to any invisible character. I did some fruitless searching, then gave up and did the simplest thing that worked for me. 🤷‍♂️

@ddbeck ddbeck added the linter 🏡 Issues or pull requests regarding the tests / linter of the JSON files. label Dec 21, 2018
@ddbeck ddbeck requested a review from Elchi3 December 21, 2018 13:34
@ddbeck ddbeck mentioned this pull request Dec 21, 2018
@connorshea
Copy link
Contributor

connorshea commented Dec 22, 2018

@ddbeck This article might be helpful: https://www.edwardthomson.com/blog/advent_day_1_gitattributes_for_text_files.html

Essentially, if we add a .gitattributes file like this it should have git force LF line endings on every new/edited JSON file committed to the repository:

*.json text eol=lf

@ddbeck ddbeck changed the title Highlight line endings in linter diff Avoid line ending inconsistencies Dec 24, 2018
@ddbeck
Copy link
Collaborator Author

ddbeck commented Dec 24, 2018

@connorshea thanks for the link! I think that's a good idea too. I've added that to the PR and updated the title to reflect the slightly broadened scope of the changes here. Thank you!

test/test-style.js Outdated Show resolved Hide resolved
Co-Authored-By: ddbeck <daniel@ddbeck.com>
@Elchi3
Copy link
Member

Elchi3 commented Jan 7, 2019

This looks like a great idea to me. The code looks good to me, too.
Do all files pass right away with this additional test? I'm surprised. Do we need a rebase against latest master to see if our HEAD is all green as well?

@ddbeck
Copy link
Collaborator Author

ddbeck commented Jan 7, 2019

Fortunately, there's not a new test here. It only changes the output of an existing test. Also fortunately, I did test renormalizing the line endings, and all of the JSON currently in the repo have the proper line endings already. I just re-tested this on master and we're good there (as of five minutes ago, at least).

@Elchi3
Copy link
Member

Elchi3 commented Jan 7, 2019

Ahh yes, this is no new test strictness, but reporting is improved!

Previously, this would have been reported as:

  Style – Error on line #1
    Actual:   {
    Expected: {

And now it is reported as:

  Style – Error on line #1
    Actual:   {\r
    Expected: {

Sorry for being slow! Just getting back to work after the holidays 😆

Copy link
Member

@Elchi3 Elchi3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love this, it came up a few times in PRs already I think. Great work @ddbeck and thanks for the helpful comments everyone!

@Elchi3 Elchi3 merged commit 57919a1 into mdn:master Jan 7, 2019
@ddbeck
Copy link
Collaborator Author

ddbeck commented Jan 7, 2019

Good idea to have some sample output in here, @Elchi3. I don't know why I didn't think of that. 🤦‍♂️ But yes, that is exactly right. And welcome back!

@ddbeck ddbeck deleted the linter-highlight-invisibles branch January 7, 2019 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linter 🏡 Issues or pull requests regarding the tests / linter of the JSON files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants