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

Handle spaceless multiplication in unit-* rules #2948

Merged
merged 3 commits into from Oct 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/rules/unit-blacklist/__tests__/index.js
Expand Up @@ -48,6 +48,9 @@ testRule(rule, {
{
code: "a { top: calc(10em - 3em); }"
},
{
code: "a { top: calc(10em*2rem); }"
},
{
code:
"a { background-image: linear-gradient(to right, white calc(100% - 50em), silver); }"
Expand Down Expand Up @@ -189,6 +192,12 @@ testRule(rule, {
line: 1,
column: 15
},
{
code: "a { top: calc(100px*2); }",
message: messages.rejected("px"),
line: 1,
column: 15
},
{
code:
"a { background-image: linear-gradient(to right, white calc(100vh - 5vmin), silver); }",
Expand Down
3 changes: 3 additions & 0 deletions lib/rules/unit-blacklist/index.js
Expand Up @@ -40,6 +40,9 @@ const rule = function(blacklistInput, options) {
}

function check(node, value, getIndex) {
// make sure multiplication operations (*) are divided - not handled
// by postcss-value-parser
value = value.replace(/\*/g, ",");
valueParser(value).walk(function(valueNode) {
// Ignore wrong units within `url` function
if (
Expand Down
9 changes: 9 additions & 0 deletions lib/rules/unit-case/__tests__/index.js
Expand Up @@ -38,6 +38,9 @@ testRule(rule, {
{
code: "a { top: calc(10em - 3em); }"
},
{
code: "a { top: calc(10px*2rem); }"
},
{
code:
"a { background-image: linear-gradient(to right, white calc(100% - 50em), silver); }"
Expand Down Expand Up @@ -174,6 +177,12 @@ testRule(rule, {
line: 1,
column: 25
},
{
code: "a { top: calc(10px*2REM); }",
message: messages.expected("REM", "rem"),
line: 1,
column: 20
},
{
code: "a { margin: -webkit-calc(13PX + 10px); }",
message: messages.expected("PX", "px"),
Expand Down
3 changes: 3 additions & 0 deletions lib/rules/unit-case/index.js
Expand Up @@ -25,6 +25,9 @@ const rule = function(expectation) {
}

function check(node, value, getIndex) {
// make sure multiplication operations (*) are divided - not handled
// by postcss-value-parser
value = value.replace(/\*/g, ",");
valueParser(value).walk(valueNode => {
// Ignore wrong units within `url` function
if (
Expand Down
3 changes: 3 additions & 0 deletions lib/rules/unit-no-unknown/__tests__/index.js
Expand Up @@ -92,6 +92,9 @@ testRule(rule, {
{
code: "a { top: calc(10px*2); }"
},
{
code: "a { top: calc(10px*2%*2); }"
},
{
code: "a { top: calc(2*10px); }",
description: "No whitespace"
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/unit-no-unknown/index.js
Expand Up @@ -39,7 +39,7 @@ const rule = function(actual, options) {
function check(node, value, getIndex) {
// make sure multiplication operations (*) are divided - not handled
// by postcss-value-parser
value = value.replace("*", ",");
value = value.replace(/\*/g, ",");
valueParser(value).walk(function(valueNode) {
// Ignore wrong units within `url` function
if (
Expand Down
9 changes: 9 additions & 0 deletions lib/rules/unit-whitelist/__tests__/index.js
Expand Up @@ -45,6 +45,9 @@ testRule(rule, {
{
code: "a { top: calc(10em - 3em); }"
},
{
code: "a { top: calc(10em*3); }"
},
{
code:
"a { background-image: linear-gradient(to right, white calc(100px - 50em), silver); }"
Expand Down Expand Up @@ -180,6 +183,12 @@ testRule(rule, {
line: 1,
column: 41
},
{
code: "a { top: calc(2vh*3); }",
message: messages.rejected("vh"),
line: 1,
column: 15
},
{
code: "a { top: calc(100px - 30vh); }",
message: messages.rejected("vh"),
Expand Down
3 changes: 3 additions & 0 deletions lib/rules/unit-whitelist/index.js
Expand Up @@ -40,6 +40,9 @@ const rule = function(whitelistInput, options) {
}

function check(node, value, getIndex) {
// make sure multiplication operations (*) are divided - not handled
// by postcss-value-parser
value = value.replace(/\*/g, ",");
valueParser(value).walk(function(valueNode) {
// Ignore wrong units within `url` function
if (
Expand Down