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
Upgrade css declaration sorter #855
Upgrade css declaration sorter #855
Conversation
Codecov Report
@@ Coverage Diff @@
## master #855 +/- ##
==========================================
- Coverage 97.33% 97.27% -0.06%
==========================================
Files 118 118
Lines 3452 3452
Branches 1035 1035
==========================================
- Hits 3360 3358 -2
- Misses 84 86 +2
Partials 8 8
Continue to review full report at Codecov.
|
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.
We lose yarn lock file, also can we add simple tests?
@evilebottnawi tests are here in the package: https://github.com/Siilwyn/css-declaration-sorter/blob/master/tests/test.js I've reset the yarn lock files. |
@evilebottnawi since you did not reply I assumed you want tests in this project too, I have added test with commit d16ccfb. |
@ben-eb could you review this PR? Only the framework integration tests are failing even after running |
I'm pretty sure the integration tests work on diffing the whole CSS file, which unfortunately makes it difficult to know what changed. If you have changed the order then it's likely to have affected a lot of the integration tests; but there should be a command you can use to rebuild them and then verify the output in some way. Ideas on changing the integration tests to make the output more human-readable of course welcomed. 🙂 |
@ben-eb thanks for your reply, what command would rebuild them? As I mentioned |
Ah, sorry I misread that part of your message. Seems strange that running those didn't fix it. 😞 |
@evilebottnawi ready for review. |
@@ -106,15 +106,15 @@ Note that you may wish to publish your own preset to npm for reusability, should | |||
|
|||
## Plugins | |||
|
|||
### [`autoprefixer`](https://github.com/postcss/autoprefixer) (external) | |||
### [`autoprefixer`](shortcut://github.com/postcss/autoprefixer) (external) |
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 use https
@@ -342,5 +342,5 @@ See [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTOR | |||
|
|||
## License | |||
|
|||
MIT © [Ben Briggs](http://beneb.info) | |||
[MIT](https://opensource.org/licenses/MIT) © [Ben Briggs](http://beneb.info) |
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.
Do not change 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.
Please remove changes that are not related to the issue, like
import processCss, { passthrough } from './_processCss';
->
import processCss from './_processCss';
It pollutes the git history, let's do it in a different PR
Alright I tried to reduce the diff amount @evilebottnawi 👍 Removing the |
@evilebottnawi ah yes didn't think of that. I have published a new version that uses postcss to strip the vendor prefix before comparing properties. Also updated the tests. |
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.
Great!
Can we add tests for at-rules - @media
, @supports
, @font-face
. For example:
/cc @ben-eb Can you look at this? Maybe i missed something?
@evilebottnawi the sorter only runs within at-rules so PostCSS will handle the AST, what do you want to test? Things like, for example the following? test(
'keep order of short- and longhand properties, within at-rule',
passthroughCSS('@supports (display: grid) {div {animation: a; animation-name: b}}')
); |
@Siilwyn yes, also we should sort properties inside |
@Siilwyn please avoid using |
Also const postcss = require('postcss');
const cssDeclarationSorter = require('css-declaration-sorter');
const code = /* CSS */ `
a {
animation-name: Three;
animation: Two 2s;
-webkit-animation: One 2s;
-webkit-name: Four;
}
`;
postcss([cssDeclarationSorter({ order: 'alphabetical', keepOverrides: true })])
.process(code)
.then((result) => console.log(result.css)); Still broken, output: a {
-webkit-name: Four;
animation-name: Three;
animation: Two 2s;
-webkit-animation: One 2s;
}
|
What is |
The FS promises API is stable and won't produce a warning with |
@Siilwyn oh, my mistake, sorry, all work fine, i mean |
@Siilwyn it is stable for LTS release, but for non LTS releases it outputs the warning, for example use |
Also please fix conflicts |
Also we have interesting case: const postcss = require('postcss');
const cssDeclarationSorter = require('css-declaration-sorter');
const code = /* CSS */ `
a {
animation-name: Three;
animation: Two 2s;
animation-future-new-long-property: 20s;
}
`;
postcss([cssDeclarationSorter({ order: 'alphabetical', keepOverrides: true })])
.process(code)
.then((result) => console.log(result.css)); Output: a {
animation-future-new-short-property: 20px;
animation-name: Three;
animation: Two 2s;
} But will be great to keep that property in current place: a {
animation-name: Three;
animation: Two 2s;
animation-future-new-short-property: 20px;
} In theory, in future any short property can have a new long property, so we should keep them in right place, what do you think? I known it is the rare case, but for the full safe mode, we should consider this |
/cc @Siilwyn friendly ping |
@evilebottnawi I can keep unkown properties in place but it does 'block' the surrounding properties from being sorted. Update: this looks hard to do actually since properties not direct to an unkown property will 'jump' over: Since CSS properties first go through a draft stage before getting accepted and such would you be okay with not handling future unknown properties? I'm keeping the properties up-to-date by scraping from MDN. |
@Siilwyn Yes, new unknown properties is very rare edge case, let's finish this PR:
|
@evilebottnawi All done! :) |
@Siilwyn Good job! To be honesty we can change order of variables too For example: :root {
--b: var(--a);
--a: 10px;
} It is work. But it is feature. Let's open issue in |
Already exists Siilwyn/css-declaration-sorter#54 😄 |
Haha yes, but should not be needed for this PR right? Anything I need to change? |
Yes, we can solve this late, not high priority |
Yes! 🎉 |
🎐 A fresh take on PR #580 to resolve issue #535 making
css-declaration-sorter
safe by adding a new optionkeepOverrides
.For now I'm using the GitHub repository to get some feedback on this PR, once it's reviewed I'll publish the changes as a new major version 5.0.
I do need some help to get all tests working, I did update the snapshots but can't get the integration tests to pass.