-
Notifications
You must be signed in to change notification settings - Fork 153
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
[TASK] Use sabberworm/php-css-parser to parse the CSS #1015
Conversation
fdcc73e
to
f51de35
Compare
|
f51de35
to
df8f1a6
Compare
Last release was 10 months ago. Last commit was 5 months ago. But I'm not aware of any new CSS syntaxes being introduced, so there may be no pressing reason to update anything particularly regularly. Of course new PHP 7 or Psalm-compatible type hints would be nice. Inevitably the new tests are failing since rebase due to CSS whitespace differences (and |
df8f1a6
to
15c4a7a
Compare
I'm mostly worried about situations where we need a particular bug fix or a compatibility fix for newer PHP versions. (And I'm hopeful that we can contribute to the project, and that the maintainer will accept our changes.) |
15c4a7a
to
5a326c0
Compare
In the meantime, it looks like the maintainers of the Sabberworm CSS parser review and merge new PRs (slowly but steadily). We might need to take care of updating old PRs and fixing old bugs ourselves, though (including bugs reported by Nikita Popov from the PHP core team). |
5a326c0
to
e8d4f16
Compare
139680f
to
c73a134
Compare
I think adding Sabberworm CSS parser is a good idea. With respect to other libraries, the only other one I'm aware of is https://github.com/Cerdic/CSSTidy but I think you'll find similar issues with this one. |
Thanks, I was not aware of that library. I think it would certainly be worth looking into before committing more heavily to the other one - e.g. starting to use its classes further downstream (which this PR doesn't go as far as). |
c73a134
to
7a4226f
Compare
This is currently a demonstration to see the code changes and potential test failures involved with using this CSS parsing package rather than `sabberworm/php-css-parser` as proposed in #1015.
This is currently a demonstration to see the code changes and potential test failures involved with using this CSS parsing package rather than `sabberworm/php-css-parser` as proposed in #1015.
7a4226f
to
112a73d
Compare
I should have been getting on with something else, but thought it worth checking out how CSSTidy might pan out if we were to decide to go with that instead. I've created a draft PR, #1076, for that alternative, so you can see what the code changes look like and what tests would have to be modified or disabled. The advantages of one vs the other appear to be as follows: CSSTidy
Sabberworm
Coincidentally, this PR itself is now ready for review, should we decide to proceed with the Sabberworm parser... |
112a73d
to
3eda043
Compare
Marked as draft again, pending #1077. |
3eda043
to
b84f00c
Compare
This is currently a demonstration to see the code changes and potential test failures involved with using this CSS parsing package rather than `sabberworm/php-css-parser` as proposed in #1015.
This is currently a demonstration to see the code changes and potential test failures involved with using this CSS parsing package rather than `sabberworm/php-css-parser` as proposed in #1015.
This is currently a demonstration to see the code changes and potential test failures involved with using this CSS parsing package rather than `sabberworm/php-css-parser` as proposed in #1015.
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've added my thoughts on reading through the first version.
src/Utilities/CssDocument.php
Outdated
continue; | ||
} | ||
} | ||
$media = '@media ' . $mediaQueryList; |
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'm not a big fan of having the types in variable names. Maybe we can rename the variable to $mediaQueries
?
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.
According to the spec, or at least MDN, it is quite specifically called a "media query list". Changing it to something else I think could sow more confusion.
src/Utilities/CssDocument.php
Outdated
&& $rule->getRules('font-family') !== [] | ||
&& $rule->getRules('src') !== []; | ||
default: | ||
return true; |
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.
Please let's have early returns only for guard clauses.
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 there can be a case for breaking this rule, if all of the following apply:
- The
swtich
statement is the only statement in the method; - All
case
branches have areturn
statment and not abreak
statement, except where a 'follow-through' is allowed or for the lastcase
ordefault
ifnull
orvoid
is the obviosuly desired return value in that case.
However, maintaining that standard through future code changes may be harder than it seems. So I will probably change it when I revisit the code changes on this - perhaps tomorrow.
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.
if all of the following apply
Such a method would be atomic. If there was any future need to add pre-amble or post-amble code, then it should be moved to a new atomic method, with the original method becoming a wrapper with the additional pre- or post- code. Though we know from experience it often doesn't turn out that way.
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.
Please let's have early returns only for guard clauses.
I've changed the switch
statement, though not the preceding code.
I don't think I agree with a "one size fits all" approach regarding where a return statement is or isn't acceptable, provided the complexity of an individual method can be kept low, as I've indicated above.
b84f00c
to
fb7a7f3
Compare
I've hopefully now resolved all the code review issues, and rebased to include #1081. Unfortunately the latter has uncovered a bug in the Sabberworm CSS parser which is beyond the scope of this PR, so it will still not be as clean a commit as desired, because some newly-added tests must now be temporarily disabled. |
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.
Looks very good! Now we only need the final polish.
Have made suggested changes. Do I get the prize of not having to make a rebase involving a file rename? ;)) |
|
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.
Beautiful!
No description provided.