-
-
Notifications
You must be signed in to change notification settings - Fork 933
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
If you updated the snapshot via the interactive testing prompt, then yes. |
Is the plan here to ignore |
// Replace `url(something)` with `url()` | ||
.replace(/url\(.*\)/ig, "url()") | ||
// Replace `@import "something"` with `@import ""` | ||
.replace(/\@import\s+['"].*['"]/ig, "@import ") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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 😄
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 🔍
There was a problem hiding this comment.
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.
Thanks everyone, it was a hoot deep diving through code for this one 👍 |
Initial tests for #2219