From 6f5c3b5e04656c62213ba277391b09651cd8420b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Peixoto?= Date: Wed, 22 Jan 2020 10:53:46 +0000 Subject: [PATCH 01/13] feat: enforce use of variables to colors (hex, rgb, hsl and named) --- rules/base.js | 6 +++++ rules/declaration-strict-value.js | 3 --- test/__snapshots__/index.spec.js.snap | 36 ++++++++++++++++++--------- test/fixtures/basic.bad.css | 5 ++-- test/fixtures/basic.good.css | 7 +++--- test/fixtures/order.bad.css | 10 ++++---- test/fixtures/order.good.css | 10 ++++---- 7 files changed, 47 insertions(+), 30 deletions(-) diff --git a/rules/base.js b/rules/base.js index 8b8316c..667b532 100644 --- a/rules/base.js +++ b/rules/base.js @@ -17,6 +17,9 @@ module.exports = { 'block-opening-brace-space-before': 'always', 'color-hex-case': 'lower', 'color-hex-length': 'short', + 'color-named': ['never', { + 'ignoreProperties': ['/^(--).*/'], + }], 'color-no-invalid-hex': true, 'comment-empty-line-before': ['always', { 'except': ['first-nested'], @@ -38,6 +41,9 @@ module.exports = { 'declaration-colon-newline-after': 'always-multi-line', 'declaration-colon-space-after': 'always-single-line', 'declaration-colon-space-before': 'never', + 'declaration-property-value-blacklist': { + '/^(?!--).*(background|color|fill|stroke|border|shadow|outline).*/': ['/#([a-f0-9]{3,})*/i', '/(rgb|hsl)a?\\(/'], + }, 'function-calc-no-unspaced-operator': true, 'function-comma-newline-after': 'always-multi-line', 'function-comma-space-after': 'always-single-line', diff --git a/rules/declaration-strict-value.js b/rules/declaration-strict-value.js index 8911d84..055cc04 100644 --- a/rules/declaration-strict-value.js +++ b/rules/declaration-strict-value.js @@ -3,11 +3,8 @@ // See https://github.com/AndyOGo/stylelint-declaration-strict-value const properties = [ - '/color/', - 'fill', 'font-family', 'font-weight', - 'stroke', 'z-index', ]; diff --git a/test/__snapshots__/index.spec.js.snap b/test/__snapshots__/index.spec.js.snap index 98a7b4f..7ed3293 100644 --- a/test/__snapshots__/index.spec.js.snap +++ b/test/__snapshots__/index.spec.js.snap @@ -27,9 +27,9 @@ Array [ "severity": "error", }, Object { - "column": 5, + "column": 12, "line": 11, - "rule": "scale-unlimited/declaration-strict-value", + "rule": "color-named", "severity": "error", }, Object { @@ -57,9 +57,9 @@ Array [ "severity": "error", }, Object { - "column": 5, + "column": 12, "line": 19, - "rule": "scale-unlimited/declaration-strict-value", + "rule": "color-named", "severity": "error", }, Object { @@ -69,9 +69,9 @@ Array [ "severity": "error", }, Object { - "column": 9, + "column": 23, "line": 25, - "rule": "scale-unlimited/declaration-strict-value", + "rule": "color-named", "severity": "error", }, Object { @@ -81,15 +81,15 @@ Array [ "severity": "error", }, Object { - "column": 9, + "column": 15, "line": 32, - "rule": "scale-unlimited/declaration-strict-value", + "rule": "color-named", "severity": "error", }, Object { - "column": 9, + "column": 17, "line": 33, - "rule": "scale-unlimited/declaration-strict-value", + "rule": "color-named", "severity": "error", }, Object { @@ -112,19 +112,31 @@ Array [ }, Object { "column": 5, + "line": 50, + "rule": "declaration-property-value-blacklist", + "severity": "error", + }, + Object { + "column": 30, "line": 51, + "rule": "color-named", + "severity": "error", + }, + Object { + "column": 5, + "line": 52, "rule": "comment-empty-line-before", "severity": "error", }, Object { "column": 1, - "line": 54, + "line": 55, "rule": "comment-empty-line-before", "severity": "error", }, Object { "column": 18, - "line": 61, + "line": 62, "rule": "length-zero-no-unit", "severity": "error", }, diff --git a/test/fixtures/basic.bad.css b/test/fixtures/basic.bad.css index e59a8e4..23885fb 100644 --- a/test/fixtures/basic.bad.css +++ b/test/fixtures/basic.bad.css @@ -16,7 +16,7 @@ } .bar { /* */ - color: red; + color: green; } @media (width <= 600px) { @@ -47,7 +47,8 @@ /* Tertiary comment block & line/inline comments */ .tags { /* Line comment */ - background: red; + background: rgba(255, 1, 1, 0.5); + box-shadow: 10px 5px 5px red; /* Line comment 2.1 */ transition: color 0.2s ease-out; /* Inline comment */ } diff --git a/test/fixtures/basic.good.css b/test/fixtures/basic.good.css index a75c7c2..c617728 100644 --- a/test/fixtures/basic.good.css +++ b/test/fixtures/basic.good.css @@ -32,7 +32,7 @@ @media (width <= 400px) { .foo { - color: color(#fff a(0%)); + color: color(var(--main-color) a(0%)); font-size: 10px; fill: transparent; stroke: inherit; @@ -59,7 +59,7 @@ .tags { /* Line comment */ - background: red; + background: var(--color-red); /* Entry and exit of passphrase dots */ &:last-child { @@ -67,7 +67,8 @@ } @nest .foo & { - background: red; + background: var(--main-color); + box-shadow: 10px 5px 5px var(--color-black); } /* Line comment 2 */ diff --git a/test/fixtures/order.bad.css b/test/fixtures/order.bad.css index 1968a9c..88ca9da 100644 --- a/test/fixtures/order.bad.css +++ b/test/fixtures/order.bad.css @@ -82,17 +82,17 @@ div { table-layout: fixed; /* asthethic */ - border: 1px solid red; + border: 1px solid var(--main-color); list-style: none; - outline: 1px solid red; + outline: 1px solid var(--main-color); object-fit: contain; opacity: 1; object-position: center; clip-path: none; - background: #000; + background: inherit; - box-shadow: 10px 5px 5px black; + box-shadow: 10px 5px 5px var(--main-color); border-radius: 5px; filter: blur(5px); @@ -114,7 +114,7 @@ div { text-underline-position: under; text-decoration: unline; text-transform: uppercase; - text-shadow: 1px 1px 2px black; + text-shadow: 1px 1px 2px var(--main-color); text-overflow: ellipsis; text-align: left; text-justify: inter-word; diff --git a/test/fixtures/order.good.css b/test/fixtures/order.good.css index 0ddf812..139ed45 100644 --- a/test/fixtures/order.good.css +++ b/test/fixtures/order.good.css @@ -113,7 +113,7 @@ div { list-style-position: auto; list-style-type: auto; - border: 1px solid red; + border: 1px solid var(--main-color); border-width: auto; border-style: auto; border-color: var(--main-color); @@ -134,7 +134,7 @@ div { border-right-style: auto; border-right-color: var(--main-color); - outline: 1px solid red; + outline: 1px solid var(--main-color); outline-color: var(--main-color); outline-width: auto; outline-style: auto; @@ -145,7 +145,7 @@ div { object-position: center; clip-path: none; - background: #000; + background: inherit; background-color: var(--main-color); background-image: auto; background-position: auto; @@ -162,7 +162,7 @@ div { border-bottom-right-radius: auto; border-bottom-left-radius: auto; - box-shadow: 10px 5px 5px black; + box-shadow: 10px 5px 5px var(--main-color); filter: blur(5px); /* text */ @@ -196,7 +196,7 @@ div { text-decoration-color: var(--main-color); text-underline-position: under; text-transform: uppercase; - text-shadow: 1px 1px 2px black; + text-shadow: 1px 1px 2px var(--main-color); text-overflow: ellipsis; text-align: left; text-align-last: auto; From a810272afe88d9783532504c080a86ee1edd3542 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Peixoto?= Date: Wed, 22 Jan 2020 10:53:46 +0000 Subject: [PATCH 02/13] feat: enforce use of variables to colors (hex, rgb, hsl and named) --- rules/base.js | 6 +++++ rules/declaration-strict-value.js | 3 --- test/__snapshots__/index.spec.js.snap | 36 ++++++++++++++++++--------- test/fixtures/basic.bad.css | 5 ++-- test/fixtures/basic.good.css | 7 +++--- test/fixtures/order.bad.css | 10 ++++---- test/fixtures/order.good.css | 10 ++++---- 7 files changed, 47 insertions(+), 30 deletions(-) diff --git a/rules/base.js b/rules/base.js index 179dbf5..834d7fc 100644 --- a/rules/base.js +++ b/rules/base.js @@ -17,6 +17,9 @@ module.exports = { 'block-opening-brace-space-before': 'always', 'color-hex-case': 'lower', 'color-hex-length': 'short', + 'color-named': ['never', { + 'ignoreProperties': ['/^(--).*/'], + }], 'color-no-invalid-hex': true, 'comment-empty-line-before': ['always', { 'except': ['first-nested'], @@ -38,6 +41,9 @@ module.exports = { 'declaration-colon-newline-after': 'always-multi-line', 'declaration-colon-space-after': 'always-single-line', 'declaration-colon-space-before': 'never', + 'declaration-property-value-blacklist': { + '/^(?!--).*(background|color|fill|stroke|border|shadow|outline).*/': ['/#([a-f0-9]{3,})*/i', '/(rgb|hsl)a?\\(/'], + }, 'function-calc-no-unspaced-operator': true, 'function-comma-newline-after': 'always-multi-line', 'function-comma-space-after': 'always-single-line', diff --git a/rules/declaration-strict-value.js b/rules/declaration-strict-value.js index 8911d84..055cc04 100644 --- a/rules/declaration-strict-value.js +++ b/rules/declaration-strict-value.js @@ -3,11 +3,8 @@ // See https://github.com/AndyOGo/stylelint-declaration-strict-value const properties = [ - '/color/', - 'fill', 'font-family', 'font-weight', - 'stroke', 'z-index', ]; diff --git a/test/__snapshots__/index.spec.js.snap b/test/__snapshots__/index.spec.js.snap index 8c3ab88..aa1b050 100644 --- a/test/__snapshots__/index.spec.js.snap +++ b/test/__snapshots__/index.spec.js.snap @@ -27,9 +27,9 @@ Array [ "severity": "error", }, Object { - "column": 5, + "column": 12, "line": 11, - "rule": "scale-unlimited/declaration-strict-value", + "rule": "color-named", "severity": "error", }, Object { @@ -57,9 +57,9 @@ Array [ "severity": "error", }, Object { - "column": 5, + "column": 12, "line": 19, - "rule": "scale-unlimited/declaration-strict-value", + "rule": "color-named", "severity": "error", }, Object { @@ -93,9 +93,9 @@ Array [ "severity": "error", }, Object { - "column": 9, + "column": 23, "line": 37, - "rule": "scale-unlimited/declaration-strict-value", + "rule": "color-named", "severity": "error", }, Object { @@ -105,15 +105,15 @@ Array [ "severity": "error", }, Object { - "column": 9, + "column": 15, "line": 44, - "rule": "scale-unlimited/declaration-strict-value", + "rule": "color-named", "severity": "error", }, Object { - "column": 9, + "column": 17, "line": 45, - "rule": "scale-unlimited/declaration-strict-value", + "rule": "color-named", "severity": "error", }, Object { @@ -136,19 +136,31 @@ Array [ }, Object { "column": 5, + "line": 62, + "rule": "declaration-property-value-blacklist", + "severity": "error", + }, + Object { + "column": 30, "line": 63, + "rule": "color-named", + "severity": "error", + }, + Object { + "column": 5, + "line": 64, "rule": "comment-empty-line-before", "severity": "error", }, Object { "column": 1, - "line": 66, + "line": 67, "rule": "comment-empty-line-before", "severity": "error", }, Object { "column": 18, - "line": 73, + "line": 74, "rule": "length-zero-no-unit", "severity": "error", }, diff --git a/test/fixtures/basic.bad.css b/test/fixtures/basic.bad.css index 6243667..7852ed0 100644 --- a/test/fixtures/basic.bad.css +++ b/test/fixtures/basic.bad.css @@ -16,7 +16,7 @@ } .bar { /* */ - color: red; + color: green; } @media (min-width: 100px) and (max-width: 60rem) { @@ -59,7 +59,8 @@ /* Tertiary comment block & line/inline comments */ .tags { /* Line comment */ - background: red; + background: rgba(255, 1, 1, 0.5); + box-shadow: 10px 5px 5px red; /* Line comment 2.1 */ transition: color 0.2s ease-out; /* Inline comment */ } diff --git a/test/fixtures/basic.good.css b/test/fixtures/basic.good.css index f705de9..fe82b9c 100644 --- a/test/fixtures/basic.good.css +++ b/test/fixtures/basic.good.css @@ -51,7 +51,7 @@ @media (width <= 400px) { .foo { - color: color(#fff a(0%)); + color: color(var(--main-color) a(0%)); font-size: 10px; fill: transparent; stroke: inherit; @@ -78,7 +78,7 @@ .tags { /* Line comment */ - background: red; + background: var(--color-red); /* Entry and exit of passphrase dots */ &:last-child { @@ -86,7 +86,8 @@ } @nest .foo & { - background: red; + background: var(--main-color); + box-shadow: 10px 5px 5px var(--color-black); } /* Line comment 2 */ diff --git a/test/fixtures/order.bad.css b/test/fixtures/order.bad.css index 75187dd..3bc821b 100644 --- a/test/fixtures/order.bad.css +++ b/test/fixtures/order.bad.css @@ -84,17 +84,17 @@ div { table-layout: fixed; /* asthethic */ - border: 1px solid red; + border: 1px solid var(--main-color); list-style: none; - outline: 1px solid red; + outline: 1px solid var(--main-color); object-fit: contain; opacity: 1; object-position: center; clip-path: none; - background: #000; + background: inherit; - box-shadow: 10px 5px 5px black; + box-shadow: 10px 5px 5px var(--main-color); border-radius: 5px; filter: blur(5px); @@ -116,7 +116,7 @@ div { text-underline-position: under; text-decoration: unline; text-transform: uppercase; - text-shadow: 1px 1px 2px black; + text-shadow: 1px 1px 2px var(--main-color); text-overflow: ellipsis; text-align: left; text-justify: inter-word; diff --git a/test/fixtures/order.good.css b/test/fixtures/order.good.css index 8d7e227..3dfb0bd 100644 --- a/test/fixtures/order.good.css +++ b/test/fixtures/order.good.css @@ -113,7 +113,7 @@ div { list-style-position: auto; list-style-type: auto; - border: 1px solid red; + border: 1px solid var(--main-color); border-width: auto; border-style: auto; border-color: var(--main-color); @@ -134,7 +134,7 @@ div { border-left-style: auto; border-left-color: var(--main-color); - outline: 1px solid red; + outline: 1px solid var(--main-color); outline-color: var(--main-color); outline-width: auto; outline-style: auto; @@ -145,7 +145,7 @@ div { object-position: center; clip-path: none; - background: #000; + background: inherit; background-color: var(--main-color); background-image: auto; background-position: auto; @@ -162,7 +162,7 @@ div { border-bottom-right-radius: auto; border-bottom-left-radius: auto; - box-shadow: 10px 5px 5px black; + box-shadow: 10px 5px 5px var(--main-color); filter: blur(5px); /* text */ @@ -196,7 +196,7 @@ div { text-decoration-color: var(--main-color); text-underline-position: under; text-transform: uppercase; - text-shadow: 1px 1px 2px black; + text-shadow: 1px 1px 2px var(--main-color); text-overflow: ellipsis; text-align: left; text-align-last: auto; From 1de972a50318c5d0ff6c7ba76e5d673b70772139 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joa=CC=83o=20Peixoto?= Date: Thu, 23 Jan 2020 18:17:24 +0000 Subject: [PATCH 03/13] feat: improve regex expressions --- rules/base.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rules/base.js b/rules/base.js index 834d7fc..1beaaa3 100644 --- a/rules/base.js +++ b/rules/base.js @@ -18,7 +18,7 @@ module.exports = { 'color-hex-case': 'lower', 'color-hex-length': 'short', 'color-named': ['never', { - 'ignoreProperties': ['/^(--).*/'], + 'ignoreProperties': ['/^--\\w/'], }], 'color-no-invalid-hex': true, 'comment-empty-line-before': ['always', { @@ -42,7 +42,7 @@ module.exports = { 'declaration-colon-space-after': 'always-single-line', 'declaration-colon-space-before': 'never', 'declaration-property-value-blacklist': { - '/^(?!--).*(background|color|fill|stroke|border|shadow|outline).*/': ['/#([a-f0-9]{3,})*/i', '/(rgb|hsl)a?\\(/'], + '/^(?!--).*(background|color|fill|stroke|border|text-shadow|box-shadow|outline)\\b/': ['/#([a-f0-9]{3,})*/i', '/(rgb|hsl)a?\\(/'], }, 'function-calc-no-unspaced-operator': true, 'function-comma-newline-after': 'always-multi-line', From c8e7c7c27d5154ea1f39f9becdd1e3214097629b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joa=CC=83o=20Peixoto?= Date: Thu, 23 Jan 2020 18:18:26 +0000 Subject: [PATCH 04/13] feat: change error to warning for declaration-strict-value --- rules/declaration-strict-value.js | 1 + 1 file changed, 1 insertion(+) diff --git a/rules/declaration-strict-value.js b/rules/declaration-strict-value.js index 055cc04..9b714d8 100644 --- a/rules/declaration-strict-value.js +++ b/rules/declaration-strict-value.js @@ -11,6 +11,7 @@ const properties = [ const options = { 'ignoreKeywords': ['currentColor', 'transparent', 'inherit'], 'disableFix': true, + 'severity': 'warning', }; module.exports = { From d10fb6a574573791cd902d35a8a705bf9d538830 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joa=CC=83o=20Peixoto?= Date: Thu, 23 Jan 2020 18:19:02 +0000 Subject: [PATCH 05/13] feat: change severity from error to warning for some rules --- rules/base.js | 10 ++++++++-- test/__snapshots__/index.spec.js.snap | 10 +++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/rules/base.js b/rules/base.js index 1beaaa3..5f001f6 100644 --- a/rules/base.js +++ b/rules/base.js @@ -41,9 +41,12 @@ module.exports = { 'declaration-colon-newline-after': 'always-multi-line', 'declaration-colon-space-after': 'always-single-line', 'declaration-colon-space-before': 'never', - 'declaration-property-value-blacklist': { + 'declaration-property-value-blacklist': [{ '/^(?!--).*(background|color|fill|stroke|border|text-shadow|box-shadow|outline)\\b/': ['/#([a-f0-9]{3,})*/i', '/(rgb|hsl)a?\\(/'], }, + { + 'severity': 'warning', + }], 'function-calc-no-unspaced-operator': true, 'function-comma-newline-after': 'always-multi-line', 'function-comma-space-after': 'always-single-line', @@ -61,9 +64,12 @@ module.exports = { 'media-feature-colon-space-after': 'always', 'media-feature-colon-space-before': 'never', 'media-feature-name-no-vendor-prefix': true, - 'media-feature-name-value-whitelist': { + 'media-feature-name-value-whitelist': [{ '/\\b(width|height)$/': ['/\\dem$/'], }, + { + 'severity': 'warning', + }], 'media-feature-parentheses-space-inside': 'never', 'media-feature-range-operator-space-after': 'always', 'media-feature-range-operator-space-before': 'always', diff --git a/test/__snapshots__/index.spec.js.snap b/test/__snapshots__/index.spec.js.snap index aa1b050..ba51f50 100644 --- a/test/__snapshots__/index.spec.js.snap +++ b/test/__snapshots__/index.spec.js.snap @@ -66,25 +66,25 @@ Array [ "column": 20, "line": 22, "rule": "media-feature-name-value-whitelist", - "severity": "error", + "severity": "warning", }, Object { "column": 43, "line": 22, "rule": "media-feature-name-value-whitelist", - "severity": "error", + "severity": "warning", }, Object { "column": 21, "line": 28, "rule": "media-feature-name-value-whitelist", - "severity": "error", + "severity": "warning", }, Object { "column": 45, "line": 28, "rule": "media-feature-name-value-whitelist", - "severity": "error", + "severity": "warning", }, Object { "column": 5, @@ -138,7 +138,7 @@ Array [ "column": 5, "line": 62, "rule": "declaration-property-value-blacklist", - "severity": "error", + "severity": "warning", }, Object { "column": 30, From 823c4295bb8ea40fca6e6649aae47fba66f8f18a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joa=CC=83o=20Peixoto?= Date: Thu, 23 Jan 2020 18:26:40 +0000 Subject: [PATCH 06/13] feat: add custom message for rules that enforce the use of variables --- rules/base.js | 4 ++++ rules/declaration-strict-value.js | 1 + 2 files changed, 5 insertions(+) diff --git a/rules/base.js b/rules/base.js index 5f001f6..f1b72d1 100644 --- a/rules/base.js +++ b/rules/base.js @@ -19,6 +19,8 @@ module.exports = { 'color-hex-length': 'short', 'color-named': ['never', { 'ignoreProperties': ['/^--\\w/'], + 'severity': 'warning', + 'message': 'Using plain values directly is not allowed, please use a CSS custom property instead.', }], 'color-no-invalid-hex': true, 'comment-empty-line-before': ['always', { @@ -46,6 +48,7 @@ module.exports = { }, { 'severity': 'warning', + 'message': 'Using plain values directly is not allowed, please use a CSS custom property instead.', }], 'function-calc-no-unspaced-operator': true, 'function-comma-newline-after': 'always-multi-line', @@ -69,6 +72,7 @@ module.exports = { }, { 'severity': 'warning', + 'message': 'Using plain values directly is not allowed, please use a CSS custom property instead.', }], 'media-feature-parentheses-space-inside': 'never', 'media-feature-range-operator-space-after': 'always', diff --git a/rules/declaration-strict-value.js b/rules/declaration-strict-value.js index 9b714d8..444ffd7 100644 --- a/rules/declaration-strict-value.js +++ b/rules/declaration-strict-value.js @@ -12,6 +12,7 @@ const options = { 'ignoreKeywords': ['currentColor', 'transparent', 'inherit'], 'disableFix': true, 'severity': 'warning', + 'message': 'Using plain values directly is not allowed, please use a CSS custom property instead.', }; module.exports = { From edf1715fbbb3d3fb3774eb5c0b9c6c68a6ad6e94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joa=CC=83o=20Peixoto?= Date: Thu, 23 Jan 2020 18:30:45 +0000 Subject: [PATCH 07/13] test: fix tests --- test/__snapshots__/index.spec.js.snap | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/__snapshots__/index.spec.js.snap b/test/__snapshots__/index.spec.js.snap index ba51f50..8d0687b 100644 --- a/test/__snapshots__/index.spec.js.snap +++ b/test/__snapshots__/index.spec.js.snap @@ -24,25 +24,25 @@ Array [ "column": 5, "line": 9, "rule": "scale-unlimited/declaration-strict-value", - "severity": "error", + "severity": "warning", }, Object { "column": 12, "line": 11, "rule": "color-named", - "severity": "error", + "severity": "warning", }, Object { "column": 5, "line": 12, "rule": "scale-unlimited/declaration-strict-value", - "severity": "error", + "severity": "warning", }, Object { "column": 5, "line": 14, "rule": "scale-unlimited/declaration-strict-value", - "severity": "error", + "severity": "warning", }, Object { "column": 1, @@ -60,7 +60,7 @@ Array [ "column": 12, "line": 19, "rule": "color-named", - "severity": "error", + "severity": "warning", }, Object { "column": 20, @@ -96,7 +96,7 @@ Array [ "column": 23, "line": 37, "rule": "color-named", - "severity": "error", + "severity": "warning", }, Object { "column": 1, @@ -108,13 +108,13 @@ Array [ "column": 15, "line": 44, "rule": "color-named", - "severity": "error", + "severity": "warning", }, Object { "column": 17, "line": 45, "rule": "color-named", - "severity": "error", + "severity": "warning", }, Object { "column": 1, @@ -144,7 +144,7 @@ Array [ "column": 30, "line": 63, "rule": "color-named", - "severity": "error", + "severity": "warning", }, Object { "column": 5, From c8ab72d174de55c66dda4e7ccd63eb41e3d5a6c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joa=CC=83o=20Peixoto?= Date: Fri, 24 Jan 2020 12:04:10 +0000 Subject: [PATCH 08/13] fix: improve custom messages --- rules/base.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rules/base.js b/rules/base.js index f1b72d1..653a6ca 100644 --- a/rules/base.js +++ b/rules/base.js @@ -20,7 +20,7 @@ module.exports = { 'color-named': ['never', { 'ignoreProperties': ['/^--\\w/'], 'severity': 'warning', - 'message': 'Using plain values directly is not allowed, please use a CSS custom property instead.', + 'message': 'Using named colors is not allowed, please use a CSS custom property instead.', }], 'color-no-invalid-hex': true, 'comment-empty-line-before': ['always', { @@ -48,7 +48,7 @@ module.exports = { }, { 'severity': 'warning', - 'message': 'Using plain values directly is not allowed, please use a CSS custom property instead.', + 'message': 'Using color values directly is not allowed, please use a CSS custom property instead.', }], 'function-calc-no-unspaced-operator': true, 'function-comma-newline-after': 'always-multi-line', @@ -72,7 +72,7 @@ module.exports = { }, { 'severity': 'warning', - 'message': 'Using plain values directly is not allowed, please use a CSS custom property instead.', + 'message': 'Please use em units inside media queries.', }], 'media-feature-parentheses-space-inside': 'never', 'media-feature-range-operator-space-after': 'always', From 6bf3058795014ca2bac6095f06997e6eacc714c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joa=CC=83o=20Peixoto?= Date: Fri, 24 Jan 2020 12:09:01 +0000 Subject: [PATCH 09/13] fix: improve custom messages --- rules/base.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rules/base.js b/rules/base.js index f1b72d1..653a6ca 100644 --- a/rules/base.js +++ b/rules/base.js @@ -20,7 +20,7 @@ module.exports = { 'color-named': ['never', { 'ignoreProperties': ['/^--\\w/'], 'severity': 'warning', - 'message': 'Using plain values directly is not allowed, please use a CSS custom property instead.', + 'message': 'Using named colors is not allowed, please use a CSS custom property instead.', }], 'color-no-invalid-hex': true, 'comment-empty-line-before': ['always', { @@ -48,7 +48,7 @@ module.exports = { }, { 'severity': 'warning', - 'message': 'Using plain values directly is not allowed, please use a CSS custom property instead.', + 'message': 'Using color values directly is not allowed, please use a CSS custom property instead.', }], 'function-calc-no-unspaced-operator': true, 'function-comma-newline-after': 'always-multi-line', @@ -72,7 +72,7 @@ module.exports = { }, { 'severity': 'warning', - 'message': 'Using plain values directly is not allowed, please use a CSS custom property instead.', + 'message': 'Please use em units inside media queries.', }], 'media-feature-parentheses-space-inside': 'never', 'media-feature-range-operator-space-after': 'always', From dc93af373e722678d5a03a3d334e8742328dd897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joa=CC=83o=20Peixoto?= Date: Fri, 24 Jan 2020 16:27:48 +0000 Subject: [PATCH 10/13] fix: update ignored keywords for declaration-strict-value --- rules/declaration-strict-value.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/declaration-strict-value.js b/rules/declaration-strict-value.js index 444ffd7..8a3d438 100644 --- a/rules/declaration-strict-value.js +++ b/rules/declaration-strict-value.js @@ -9,7 +9,7 @@ const properties = [ ]; const options = { - 'ignoreKeywords': ['currentColor', 'transparent', 'inherit'], + 'ignoreKeywords': ['inherit', 'initial', 'unset'], 'disableFix': true, 'severity': 'warning', 'message': 'Using plain values directly is not allowed, please use a CSS custom property instead.', From c6bdab935636c9b3aabfc70ae7a720355eb7ceba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joa=CC=83o=20Peixoto?= Date: Fri, 24 Jan 2020 16:28:54 +0000 Subject: [PATCH 11/13] feat: add rule unit-blacklist --- rules/base.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rules/base.js b/rules/base.js index 653a6ca..57f1398 100644 --- a/rules/base.js +++ b/rules/base.js @@ -99,6 +99,9 @@ module.exports = { 'selector-no-vendor-prefix': true, 'selector-pseudo-element-colon-notation': 'double', 'string-quotes': 'double', + 'unit-blacklist': [['px', 'pt', 'pc', 'in', 'cm', 'mm'], { + 'severity': 'warning', + }], 'value-list-comma-newline-after': 'always-multi-line', 'value-list-comma-space-after': 'always-single-line', 'value-list-comma-space-before': 'never', From c9eb52f28abab4d22d72989dccaaf8c77bbde6fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joa=CC=83o=20Peixoto?= Date: Fri, 24 Jan 2020 16:29:27 +0000 Subject: [PATCH 12/13] test: update tests according to the new rule --- test/__snapshots__/index.spec.js.snap | 90 +++++++++++++++++++++++++++ test/fixtures/basic.good.css | 19 +++--- test/fixtures/order.bad.css | 40 ++++++------ test/fixtures/order.good.css | 48 +++++++------- 4 files changed, 143 insertions(+), 54 deletions(-) diff --git a/test/__snapshots__/index.spec.js.snap b/test/__snapshots__/index.spec.js.snap index 8d0687b..dbd2b80 100644 --- a/test/__snapshots__/index.spec.js.snap +++ b/test/__snapshots__/index.spec.js.snap @@ -38,6 +38,12 @@ Array [ "rule": "scale-unlimited/declaration-strict-value", "severity": "warning", }, + Object { + "column": 16, + "line": 13, + "rule": "unit-blacklist", + "severity": "warning", + }, Object { "column": 5, "line": 14, @@ -68,12 +74,24 @@ Array [ "rule": "media-feature-name-value-whitelist", "severity": "warning", }, + Object { + "column": 20, + "line": 22, + "rule": "unit-blacklist", + "severity": "warning", + }, Object { "column": 43, "line": 22, "rule": "media-feature-name-value-whitelist", "severity": "warning", }, + Object { + "column": 20, + "line": 24, + "rule": "unit-blacklist", + "severity": "warning", + }, Object { "column": 21, "line": 28, @@ -86,6 +104,24 @@ Array [ "rule": "media-feature-name-value-whitelist", "severity": "warning", }, + Object { + "column": 45, + "line": 28, + "rule": "unit-blacklist", + "severity": "warning", + }, + Object { + "column": 20, + "line": 30, + "rule": "unit-blacklist", + "severity": "warning", + }, + Object { + "column": 18, + "line": 34, + "rule": "unit-blacklist", + "severity": "warning", + }, Object { "column": 5, "line": 36, @@ -98,12 +134,30 @@ Array [ "rule": "color-named", "severity": "warning", }, + Object { + "column": 20, + "line": 38, + "rule": "unit-blacklist", + "severity": "warning", + }, Object { "column": 1, "line": 41, "rule": "at-rule-empty-line-before", "severity": "error", }, + Object { + "column": 18, + "line": 41, + "rule": "unit-blacklist", + "severity": "warning", + }, + Object { + "column": 20, + "line": 43, + "rule": "unit-blacklist", + "severity": "warning", + }, Object { "column": 15, "line": 44, @@ -122,12 +176,24 @@ Array [ "rule": "comment-empty-line-before", "severity": "error", }, + Object { + "column": 16, + "line": 52, + "rule": "unit-blacklist", + "severity": "warning", + }, Object { "column": 1, "line": 54, "rule": "comment-empty-line-before", "severity": "error", }, + Object { + "column": 16, + "line": 57, + "rule": "unit-blacklist", + "severity": "warning", + }, Object { "column": 1, "line": 59, @@ -140,6 +206,24 @@ Array [ "rule": "declaration-property-value-blacklist", "severity": "warning", }, + Object { + "column": 17, + "line": 63, + "rule": "unit-blacklist", + "severity": "warning", + }, + Object { + "column": 22, + "line": 63, + "rule": "unit-blacklist", + "severity": "warning", + }, + Object { + "column": 26, + "line": 63, + "rule": "unit-blacklist", + "severity": "warning", + }, Object { "column": 30, "line": 63, @@ -158,6 +242,12 @@ Array [ "rule": "comment-empty-line-before", "severity": "error", }, + Object { + "column": 17, + "line": 74, + "rule": "unit-blacklist", + "severity": "warning", + }, Object { "column": 18, "line": 74, diff --git a/test/fixtures/basic.good.css b/test/fixtures/basic.good.css index fe82b9c..8eec3d4 100644 --- a/test/fixtures/basic.good.css +++ b/test/fixtures/basic.good.css @@ -5,7 +5,7 @@ @mixin bar .foo; :root { - --zero-unit-var: 0px; + --zero-unit-var: 0; --main-color: red; --font-family: "Arial", "Helvetica", sans-serif; --font-weight-regular: 400; @@ -18,7 +18,7 @@ display: block; color: var(--main-color); font-family: var(--font-family); - font-size: 20px; + font-size: 2.5em; font-weight: var(--font-weight-regular); @mixin bar; } @@ -26,7 +26,7 @@ @media (width: 60em) { .foo { border-color: currentColor; - font-size: 15px; + font-size: 2em; } } @@ -42,17 +42,17 @@ } } -@media (width <= 600px) { +@media (width <= 60em) { .foo { border-color: currentColor; - font-size: 15px; + font-size: 2em; } } -@media (width <= 400px) { +@media (width <= 40em) { .foo { color: color(var(--main-color) a(0%)); - font-size: 10px; + font-size: 1em; fill: transparent; stroke: inherit; } @@ -64,14 +64,13 @@ .title { font-size: 1em; - font-size: 20px; } /* Secondary comment block ============================================= */ .description { - font-size: 15px; + font-size: 1.5em; } /* Tertiary comment block & line/inline comments */ @@ -87,7 +86,7 @@ @nest .foo & { background: var(--main-color); - box-shadow: 10px 5px 5px var(--color-black); + box-shadow: 1em 0.5em 0.5em var(--color-black); } /* Line comment 2 */ diff --git a/test/fixtures/order.bad.css b/test/fixtures/order.bad.css index 3bc821b..50705a2 100644 --- a/test/fixtures/order.bad.css +++ b/test/fixtures/order.bad.css @@ -16,23 +16,23 @@ div { bottom: 0; left: 0; - min-width: 1000px; - width: 100px; - max-width: 50px; - min-height: 1000px; - height: 100px; - max-height: 50px; + min-width: 100rem; + width: 10rem; + max-width: 5rem; + min-height: 100rem; + height: 10rem; + max-height: 5rem; overflow: hidden; z-index: var(--z-index-base); overflow-x: auto; overflow-y: auto; - margin-top: 5px; + margin-top: 0.5rem; margin: 0; - margin-left: 5px; - margin-right: 5px; - padding-top: 5px; + margin-left: 0.5rem; + margin-right: 0.5rem; + padding-top: 0.5rem; padding: 0; zoom: 1; @@ -41,7 +41,7 @@ div { /* display */ display: inline-block; - flex-basis: 100px; + flex-basis: 0.5rem; flex: 0 1 auto; flex-grow: 1; flex-shrink: 1; @@ -84,9 +84,9 @@ div { table-layout: fixed; /* asthethic */ - border: 1px solid var(--main-color); + border: 0.1rem solid var(--main-color); list-style: none; - outline: 1px solid var(--main-color); + outline: 0.1rem solid var(--main-color); object-fit: contain; opacity: 1; @@ -94,9 +94,9 @@ div { clip-path: none; background: inherit; - box-shadow: 10px 5px 5px var(--main-color); - border-radius: 5px; - filter: blur(5px); + box-shadow: 1rem 0.5rem 0.5rem var(--main-color); + border-radius: 0.5rem; + filter: blur(0.5rem); /* text */ color: var(--main-color); @@ -104,7 +104,7 @@ div { font-family: var(--font-family); font: 2em "Open Sans", sans-serif; font-variant: small-caps; - font-size: 12px; + font-size: 1.2em; font-size-adjust: 0.5; font-kerning: auto; font-weight: var(--font-weight-bold); @@ -116,14 +116,14 @@ div { text-underline-position: under; text-decoration: unline; text-transform: uppercase; - text-shadow: 1px 1px 2px var(--main-color); + text-shadow: 0.1rem 0.1rem 0.2rem var(--main-color); text-overflow: ellipsis; text-align: left; text-justify: inter-word; - text-indent: 40px; + text-indent: 4rem; tab-size: 4; - line-height: 10px; + line-height: 1rem; white-space: nowrap; word-spacing: normal; word-wrap: break-word; diff --git a/test/fixtures/order.good.css b/test/fixtures/order.good.css index 3dfb0bd..0575809 100644 --- a/test/fixtures/order.good.css +++ b/test/fixtures/order.good.css @@ -12,12 +12,12 @@ div { bottom: 0; left: 0; - width: 100px; - min-width: 1000px; - max-width: 50px; - height: 100px; - min-height: 1000px; - max-height: 50px; + width: 10rem; + min-width: 100rem; + max-width: 5rem; + height: 10rem; + min-height: 100rem; + max-height: 5rem; z-index: var(--z-index-base); overflow: hidden; @@ -25,15 +25,15 @@ div { overflow-y: auto; margin: 0; - margin-top: 5px; - margin-right: 5px; - margin-bottom: 5px; - margin-left: 5px; + margin-top: 0.5rem; + margin-right: 0.5rem; + margin-bottom: 0.5rem; + margin-left: 0.5rem; padding: 0; - padding-top: 5px; - padding-right: 5px; - padding-bottom: 5px; - padding-left: 5px; + padding-top: 0.5rem; + padding-right: 0.5rem; + padding-bottom: 0.5rem; + padding-left: 0.5rem; transform: translateX(0); transform-box: auto; @@ -48,7 +48,7 @@ div { display: inline-block; flex: 0 1 auto; - flex-basis: 100px; + flex-basis: 10rem; flex-grow: 1; flex-shrink: 1; flex-flow: row wrap; @@ -113,7 +113,7 @@ div { list-style-position: auto; list-style-type: auto; - border: 1px solid var(--main-color); + border: 0.1rem solid var(--main-color); border-width: auto; border-style: auto; border-color: var(--main-color); @@ -134,7 +134,7 @@ div { border-left-style: auto; border-left-color: var(--main-color); - outline: 1px solid var(--main-color); + outline: 0.1rem solid var(--main-color); outline-color: var(--main-color); outline-width: auto; outline-style: auto; @@ -156,14 +156,14 @@ div { background-attachment: auto; background-blend-mode: auto; - border-radius: 5px; + border-radius: 0.5rem; border-top-left-radius: auto; border-top-right-radius: auto; border-bottom-right-radius: auto; border-bottom-left-radius: auto; - box-shadow: 10px 5px 5px var(--main-color); - filter: blur(5px); + box-shadow: 1rem 0.5rem 0.5rem var(--main-color); + filter: blur(0.5rem); /* text */ color: var(--main-color); @@ -177,7 +177,7 @@ div { font-variant-ligatures: auto; font-variant-numeric: auto; font-variant-position: auto; - font-size: 12px; + font-size: 1.2rem; font-size-adjust: 0.5; font-kerning: auto; font-weight: var(--font-weight-bold); @@ -196,12 +196,12 @@ div { text-decoration-color: var(--main-color); text-underline-position: under; text-transform: uppercase; - text-shadow: 1px 1px 2px var(--main-color); + text-shadow: 0.1rem 0.1rem 0.2rem var(--main-color); text-overflow: ellipsis; text-align: left; text-align-last: auto; text-justify: inter-word; - text-indent: 40px; + text-indent: 4rem; text-emphasis: auto; text-emphasis-color: var(--main-color); text-emphasis-position: auto; @@ -210,7 +210,7 @@ div { text-rendering: auto; text-combine-upright: auto; - line-height: 10px; + line-height: 1rem; tab-size: 4; white-space: nowrap; letter-spacing: normal; From d0f4c0f983c724a7477caa28ae55b7fa3977ca27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joa=CC=83o=20Peixoto?= Date: Fri, 24 Jan 2020 18:14:15 +0000 Subject: [PATCH 13/13] feat: improve custom messages --- rules/base.js | 7 ++++--- rules/declaration-strict-value.js | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/rules/base.js b/rules/base.js index 57f1398..052c9d2 100644 --- a/rules/base.js +++ b/rules/base.js @@ -20,7 +20,7 @@ module.exports = { 'color-named': ['never', { 'ignoreProperties': ['/^--\\w/'], 'severity': 'warning', - 'message': 'Using named colors is not allowed, please use a CSS custom property instead.', + 'message': 'Using named colors is not recommended, please consider using a CSS custom property instead.', }], 'color-no-invalid-hex': true, 'comment-empty-line-before': ['always', { @@ -48,7 +48,7 @@ module.exports = { }, { 'severity': 'warning', - 'message': 'Using color values directly is not allowed, please use a CSS custom property instead.', + 'message': 'Using color values directly is not recommended, please consider using a CSS custom property instead.', }], 'function-calc-no-unspaced-operator': true, 'function-comma-newline-after': 'always-multi-line', @@ -72,7 +72,7 @@ module.exports = { }, { 'severity': 'warning', - 'message': 'Please use em units inside media queries.', + 'message': 'Using units other than em is not recommended. You can understand why by reading: https://zellwk.com/blog/media-query-units/', }], 'media-feature-parentheses-space-inside': 'never', 'media-feature-range-operator-space-after': 'always', @@ -101,6 +101,7 @@ module.exports = { 'string-quotes': 'double', 'unit-blacklist': [['px', 'pt', 'pc', 'in', 'cm', 'mm'], { 'severity': 'warning', + 'message': 'Using absolute units is not recommended. Consider using relative units: https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units#Relative_length_units', }], 'value-list-comma-newline-after': 'always-multi-line', 'value-list-comma-space-after': 'always-single-line', diff --git a/rules/declaration-strict-value.js b/rules/declaration-strict-value.js index 8a3d438..19a0faa 100644 --- a/rules/declaration-strict-value.js +++ b/rules/declaration-strict-value.js @@ -9,10 +9,10 @@ const properties = [ ]; const options = { - 'ignoreKeywords': ['inherit', 'initial', 'unset'], + 'ignoreKeywords': ['auto', 'inherit', 'initial', 'unset'], 'disableFix': true, 'severity': 'warning', - 'message': 'Using plain values directly is not allowed, please use a CSS custom property instead.', + 'message': 'Using plain values directly is not recommended, please consider using a CSS custom property instead.', }; module.exports = {