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

Add @import tests for max-line-length rule #2221

Merged
merged 5 commits into from
Jan 28, 2017
Merged

Add @import tests for max-line-length rule #2221

merged 5 commits into from
Jan 28, 2017

Conversation

ntwb
Copy link
Member

@ntwb ntwb commented Dec 30, 2016

Which issue, if any, is this issue related to?

Initial tests for #2219

@ntwb
Copy link
Member Author

ntwb commented Dec 30, 2016

Following the changes in 926e35e the jest snapshot for 005 needed updating, is this the correct way to do that in this commit fdbd4fa ?

Copy link
Member

@jeddy3 jeddy3 left a comment

Choose a reason for hiding this comment

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

LGTM

@jeddy3
Copy link
Member

jeddy3 commented Jan 8, 2017

is this the correct way to do that in this commit fdbd4fa ?

If you updated the snapshot via the interactive testing prompt, then yes.

@jeddy3
Copy link
Member

jeddy3 commented Jan 8, 2017

Is the plan here to ignore @import statements by default and in addition to adding an ignorePattern option?

// Replace `url(something)` with `url()`
.replace(/url\(.*\)/ig, "url()")
// Replace `@import "something"` with `@import ""`
.replace(/\@import\s+['"].*['"]/ig, "@import ")
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately, I do not think this regexp is exact enough. for example, @import 'svg-something<id="horse">'; will become @important ">';, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @davidtheclark, I think what I have is OK (for my sanity I use http://regexr.com/ to test/explain regexes). There is probably room for improvement as I'm not the greatest regex architect.

Using \@import\s+['"].*['"] and replacing with @import

With this string: @import 'svg-something<id="horse">';

Results in @import ; (There is a single space between the t and ;)

I've added a test to accept that the length of this @import 'svg-something<id=\"horse\">' projection; string is 20 characters or under, stripping 'svg-something<id=\"horse\">' leaves @import projection; which is exactly 20 characters in length.

I've also added a failing test using @import 'svg-something<id=\"horse\">' screens, tv; which once stripping 'svg-something<id=\"horse\">' leaves @import screens, tv; which is 21 characters in length.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ooooo, I think my misunderstanding was in forgetting that the * is non-greedy by default, so the last ['"] will match the last possible quotation mark instead of first one it finds. You're right: carry on!

"column": 5,
"line": 146,
"column": 25,
"line": 145,
Copy link
Contributor

Choose a reason for hiding this comment

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

Something seems wrong with this system test. Am I right that these line numbers do not correspond with lines in 005/stylesheet.css that make sense? Let's sort this out before accepting changes to it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Trying to wrap my head around this and it's not going so well 😏

Currently in master before changes by this PR we have:

https://github.com/stylelint/stylelint/blob/master/system-tests/005/stylesheet.css#L146

b a {} <- 6 characters in length

https://github.com/stylelint/stylelint/blob/master/system-tests/005/__snapshots__/005.test.js.snap#L11767-L11773

      Object {
        "column": 5,
        "line": 146,
        "rule": "max-line-length",
        "severity": "error",
        "text": "Expected line length to be no more than 20 characters (max-line-length)",
      },

Once applying the changes in this PR the above warning for line 146 is no longer reported in the test snapshot but a new one is, line 149 with .bar, is now reported in the test snapshot whereas it wasn't previously.

It appears that there are numerous cases of the above, the only sane piece of data I've been able to extract thus far is that both before and after this PR there are a total of 84 max-line-length warnings, when i manually remove all lines from the stylesheet.css file less than 20 characters in length I indeed have 84 lines greater than 20 characters which correlates.

Line numbers, are at best a crap shoot 🎲

If anyone else in @stylelint/core can make any sense of this it'd be appreciated 😄

Copy link
Member

Choose a reason for hiding this comment

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

There's something going on here, but I'm not sure what. If I can reproduce a smaller test case I'll post it up.

Copy link
Member Author

Choose a reason for hiding this comment

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

One possability is that Jest is serializing the snapshot.css file:
https://facebook.github.io/jest/docs/configuration.html#snapshotserializers-array-string

Unconfirmed at this stage though, need to read more docs and or code to confirm.

Copy link
Member

Choose a reason for hiding this comment

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

I think this is the problem: #2286

Copy link
Member Author

@ntwb ntwb Jan 24, 2017

Choose a reason for hiding this comment

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

@m-allanson I actually didn't even get to the stage of checking if the column number was correct, I've only really tested line numbers, and it's been clear that the line numbers referenced are not 20 characters in length (based on this PRs settings)

Edit: I've just read the Extra example in the #2286 issue in that multiple errors can be reported for a single line rather, let's get that fixed and test the results 👍

p.s. Great sleuthing @m-allanson 🔍

Copy link
Member

@m-allanson m-allanson Jan 24, 2017

Choose a reason for hiding this comment

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

@ntwb Yeah it's a funny one - the incorrect column numbers can compound and spill over into incorrect line numbers too. I added an extra example to the bottom of the issue to demonstrate.

@davidtheclark
Copy link
Contributor

@ntwb Looks like the problems with the max-line-length warnings in the snapshot are being addressed in #2286, so I'll merge this PR. There are no changes for the changelog here, right? Just new tests?

@ntwb
Copy link
Member Author

ntwb commented Feb 1, 2017

Thanks everyone, it was a hoot deep diving through code for this one 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants