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
Feat: postcss lowercase text #867
base: master
Are you sure you want to change the base?
Feat: postcss lowercase text #867
Conversation
Codecov Report
@@ Coverage Diff @@
## master #867 +/- ##
=======================================
Coverage 97.28% 97.28%
=======================================
Files 118 123 +5
Lines 3458 3539 +81
Branches 1040 1054 +14
=======================================
+ Hits 3364 3443 +79
- Misses 86 88 +2
Partials 8 8
Continue to review full report at Codecov.
|
packages/postcss-lowercase-text/src/__tests__/data/pseudo-elements.js
Outdated
Show resolved
Hide resolved
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 good, we need more improvement - let's do 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.
Can we add more tests?
run( | ||
'should not transform css variable declarations', | ||
':root { --BG-COLOR: coral; --TEXT-COLOR: RED;}', | ||
':root { --BG-COLOR: coral; --TEXT-COLOR: red;}' |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
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.
they are css values, they can be transformed as well just like the rest of the values.
Like this
https://github.com/cssnano/cssnano/pull/867/files#diff-fe88a57283a0a1a5c792a3000e5badbaR43-R53
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 will read spec, maybe you are right
@evilebottnawi Can you please check this allowed transformation
|
Need fix CI |
working on it |
57998c5
to
b1b0698
Compare
b6a1db5
to
af8a940
Compare
cc @evilebottnawi finally the CI is green. Can you review this. |
@@ -9,6 +9,7 @@ module.exports = { | |||
'_processCSS.js', | |||
'_processCss.js', | |||
'_webpack.config.js', | |||
'packages/postcss-lowercase-text/src/__tests__/data/', |
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.
Why it here?
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.
jest was running the test running in this directory as well as there is an .js
file which is true for jest's default test file pattern. So I added them. this directory should not be tested as it has data only.
@@ -24,6 +24,7 @@ | |||
"postcss-discard-duplicates": "^4.0.2", | |||
"postcss-discard-empty": "^4.0.1", | |||
"postcss-discard-overridden": "^4.0.1", | |||
"postcss-lowercase-text": "*", |
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.
Use 1.0.0
verison
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 didnt publish v1
. so it will through error if we build it locally. I will release it manually after merging of this.
@@ -24,6 +24,6 @@ | |||
"url": "https://github.com/cssnano/cssnano/issues" | |||
}, | |||
"engines": { | |||
"node": ">=10.13" | |||
"node": ">=10.13.0" |
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.
No need .0
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.
ok 👍
@@ -1,5 +1,7 @@ | |||
import processCss from './_processCss'; | |||
|
|||
jest.setTimeout(30000); |
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.
Avoid it and use setupFilesAfterEnv
https://jestjs.io/docs/en/jest-object#jestsettimeouttimeout
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.
ok cool, I will try this 👍
'@MEDIA SCREEN and (min-width: 480px){}', | ||
'@media screen and (min-width: 480px){}' | ||
); | ||
}); |
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 add test: @MEDIA SCREEN AND (MIN-WIDTH: 480PX) {}
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.
ok cool 👍
run( | ||
'should safely transform the @charset', | ||
'@CHARSET "iso-8859-15";', | ||
'@charset "iso-8859-15";' |
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 touch charset
never, it should b always in lowercase, we should keep @CHARSET
as is
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.
is it case sensitive?
'should transform the @import ', | ||
`@IMPORT url("fineprint.css") print;@import url("bluish.css") speech;@ImPoRt 'custom.css';@import url("CHROME://communicator/SKIN/");@import "common.css" screen;`, | ||
`@import url("fineprint.css") print;@import url("bluish.css") speech;@import 'custom.css';@import url("CHROME://communicator/SKIN/");@import "common.css" screen;` | ||
); |
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 add test: @IMPORT URL("fineprint.css") PRINT;
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.
ok cool 👍
run( | ||
'should safely transform the @namespace', | ||
'@NAMESPACE prefix url(http://www.w3.org/1999/xhtml);', | ||
'@namespace prefix url(http://www.w3.org/1999/xhtml);' |
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 add test @NAMESPACE SVG URL(http://www.w3.org/2000/svg);
, SVG
should be in uppercase (keep as is)
run( | ||
'should safely transform the @supports ', | ||
'@SUPPORTS (display: grid) {div {display: grid;}};@supports not (display: GRID) {div {float: right;}}', | ||
'@supports (display: grid) {div {display: grid;}};@supports not (display: GRID) {div {float: 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.
Please add test: @SUPPORTS (DISPLAY: GRID) {}
run( | ||
'should safely transform the @document ', | ||
'@DOCUMENT URL("https://www.EXAMPLE.com/") {h1 {COLOR: green;}}', | ||
'@document URL("https://www.EXAMPLE.com/") {h1 {color: green;}}' |
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.
URL
should be lowercased
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.
@evilebottnawi, it will lowercase the argument ("https://www.EXAMPLE.com/"
) as well which is not saved as lowercasing anything after domain name in URLs are not safe.
postcss will parse URL("https://www.EXAMPLE.com/")
whole as params
so we cant lowercase only URL
.
let me know what you think!
run( | ||
'should safely transform the @page ', | ||
'@PAGE {margin: 1cm;};@page :FIRST {margin: 2cm;}', | ||
'@page {margin: 1cm;};@page :FIRST {margin: 2cm;}' |
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 add test: @PAGE :FIRST
(all should be lowercased)
run( | ||
'should safely transform the @keyframes', | ||
'@KEYFRAMES slidein {from {transform: translateX(0%);}};@KEYFRAMES important2 {FROM {TRANSFORM: translateX(0%);}}', | ||
'@keyframes slidein {from {transform: translateX(0%);}};@keyframes important2 {from {transform: translateX(0%);}}' |
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 add test - @KEYFRAMES SLIDEIN {}
, SLIDEIN
should not be lowercased (keep as is)
}, | ||
}; | ||
|
||
export default pseudoElementsList; |
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.
Can we write a script and get it from mdn
?
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 don't know of any API to request from MDN !
can you share any link.
run( | ||
'should safely transform the CSS attribute Selectors to lowercase', | ||
'[NAME="newname"]{border: 1px solid black;}', | ||
'[name="newname"]{border: 1px solid black;}' |
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 add tests:
A[HREF*="insensitive" I]
->a[href*="insensitive" i]
A[HREF*="insensitive" S]
->a[href*="insensitive" s]
run( | ||
'should safely transform the CSS attribute Selectors to lowercase', | ||
'[NAME="newname"]{border: 1px solid black;}', | ||
'[name="newname"]{border: 1px solid black;}' |
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 add test: DIV:NOT([LANG])
'should safely transform the CSS attribute Selectors to lowercase', | ||
'[NAME="newname"]{border: 1px solid black;}', | ||
'[name="newname"]{border: 1px solid black;}' | ||
); |
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 add test: LI[DATA-VALUE|="1900"]
, we should not lowercase DATA-VALUE
(keep as is) because https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes
run( | ||
'should not transform the CSS :active pseudo class Selectors to lowercase', | ||
'a:ACTIVE{border: 1px solid black;}', | ||
'a:ACTIVE{border: 1px solid black;}' |
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.
Why we do not lowercased?
); | ||
|
||
run( | ||
'should safely transform the CSS nested classname Selectors to lowercase', |
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.
Bad name test
describe('transforming CSS units', () => { | ||
run( | ||
'should safely transform the absolute units to lowercase : px', | ||
'classname{border: 1PX solid black;}', |
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.
change classname
to .classname
run( | ||
'should safely transform Property ', | ||
':root { --main-BG-color: coral;} .classname { color : RED; background-color: var(--main-BG-color);}', | ||
':root { --main-BG-color: coral;} .classname { color : red; background-color: var(--main-BG-color);}' |
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 add test - background-color: VAR(--MY-VAR, VAR(--MY-BACKGROUND, PING));
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.
should PING
be lowercased too ?
let allAtRulesNames = []; // ignored list for transforming values | ||
css.walkAtRules((rule) => { | ||
const allowedTransformingTypes = Object.keys(atRulesTranformerMap); | ||
const allowedTransformingTypeSet = new Set(allowedTransformingTypes); |
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.
No need initialize inside walk, it is reduce perf
decl.prop = decl.prop.toLowerCase(); | ||
} | ||
// font-family is case sensitive prop, its value should be left as it is | ||
if (decl.prop === 'font-family') { |
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 have many properties which we should lowercased
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.
can you name them ? may all font
as well ?
decl.value = valueParser(decl.value) | ||
.walk((node) => { | ||
i += 1; | ||
if (node.type === 'word' && i === 1) { |
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.
Avoid using counter, need rewrite
Moved
postcss-lowercase-text
tocssnano-preset-default
Updated few integration tests.