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

Feat: postcss lowercase text #867

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

anikethsaha
Copy link
Member

@anikethsaha anikethsaha commented Jan 16, 2020

Moved postcss-lowercase-text to cssnano-preset-default
Updated few integration tests.

@codecov-io
Copy link

codecov-io commented Jan 16, 2020

Codecov Report

Merging #867 into master will increase coverage by 0.00%.
The diff coverage is 97.53%.

Impacted file tree graph

@@           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           
Impacted Files Coverage Δ
packages/cssnano-preset-default/src/index.js 100.00% <ø> (ø)
packages/postcss-lowercase-text/src/atRules.js 88.23% <88.23%> (ø)
...wercase-text/src/__tests__/data/pseudo-elements.js 100.00% <100.00%> (ø)
packages/postcss-lowercase-text/src/index.js 100.00% <100.00%> (ø)
packages/postcss-lowercase-text/src/selector.js 100.00% <100.00%> (ø)
packages/postcss-lowercase-text/src/units.js 100.00% <100.00%> (ø)
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8dd5c44...da03b82. Read the comment docs.

@anikethsaha
Copy link
Member Author

cc @evilebottnawi

Copy link
Member

@alexander-akait alexander-akait left a 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

packages/postcss-lowercase-text/package.json Outdated Show resolved Hide resolved
Copy link
Member

@alexander-akait alexander-akait left a 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.

Copy link
Member Author

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

Copy link
Member

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

@anikethsaha
Copy link
Member Author

anikethsaha commented Feb 4, 2020

@evilebottnawi Can you please check this allowed transformation

 [at rule]            [allowed lowercasing]
  keyframes -> nameAndPropsTransform,
  counter-style  -> namePropsTransform,
  namespace  ->  nameTransformOnly,
  import  ->  nameTransformOnly,
  font-face  ->   nameAndPropsTransform,
  font-feature-values   ->  nameTransformOnly,
  page   ->  nameAndPropsTransform,
  supports   ->   nameAndPropsTransform,
  media  ->   nameParamsPropsTransform,
  charset  ->  nameTransformOnly,
  document  ->   nameTransformOnly,
  viewport  ->   nameAndPropsTransform,

@alexander-akait
Copy link
Member

Need fix CI

@anikethsaha
Copy link
Member Author

Need fix CI

working on it

@anikethsaha
Copy link
Member Author

cc @evilebottnawi finally the CI is green. Can you review this.
we need to rebase other PR in order to fix their CI as there is some issue with @babel/preset-env and node13 for which I had to update it to 7.9 so after merging this, we need to rebase other PR.

@@ -9,6 +9,7 @@ module.exports = {
'_processCSS.js',
'_processCss.js',
'_webpack.config.js',
'packages/postcss-lowercase-text/src/__tests__/data/',
Copy link
Member

Choose a reason for hiding this comment

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

Why it here?

Copy link
Member Author

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": "*",
Copy link
Member

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

Copy link
Member Author

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"
Copy link
Member

Choose a reason for hiding this comment

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

No need .0

Copy link
Member Author

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);
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

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){}'
);
});
Copy link
Member

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) {}

Copy link
Member Author

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";'
Copy link
Member

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

Copy link
Member Author

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;`
);
Copy link
Member

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;

Copy link
Member Author

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);'
Copy link
Member

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;}}'
Copy link
Member

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;}}'
Copy link
Member

Choose a reason for hiding this comment

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

URL should be lowercased

Copy link
Member Author

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;}'
Copy link
Member

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%);}}'
Copy link
Member

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;
Copy link
Member

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?

Copy link
Member Author

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;}'
Copy link
Member

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;}'
Copy link
Member

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;}'
);
Copy link
Member

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;}'
Copy link
Member

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',
Copy link
Member

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;}',
Copy link
Member

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);}'
Copy link
Member

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));

Copy link
Member Author

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);
Copy link
Member

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') {
Copy link
Member

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

Copy link
Member Author

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) {
Copy link
Member

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

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

Successfully merging this pull request may close these issues.

None yet

3 participants