stylelint-gamut 1.3.3 → 1.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,9 +6,9 @@
6
6
 
7
7
  # Rules
8
8
 
9
- * [`color-no-out-gamut-range`](./src/README.md): Throw warning if color goes out of sRGB color space and is not wrapped in `@media (color-gamut: p3) {}` or `@media (color-gamut: rec2020) {}`.
9
+ - [`color-no-out-gamut-range`](./src/README.md): Throw warning if color goes out of sRGB color space and is not wrapped in `@media (color-gamut: p3) {}` or `@media (color-gamut: rec2020) {}`.
10
10
 
11
- # Requirements
11
+ # Requirements
12
12
 
13
13
  - **node version ≥ 12.0.0**
14
14
  - **Stylelint version ≥ 14.0.0**.
@@ -33,22 +33,23 @@ Add `stylelint-gamut` to your Stylelint config `plugins` array, then add rules y
33
33
 
34
34
  ```json
35
35
  {
36
- "plugins": [
37
- "stylelint-gamut"
38
- ],
36
+ "plugins": ["stylelint-gamut"],
39
37
  "rules": {
40
- "gamut/color-no-out-gamut-range": true,
38
+ "gamut/color-no-out-gamut-range": true
41
39
  }
42
40
  }
43
41
  ```
44
42
 
45
43
  # More
44
+
46
45
  It is already used by the creator of [PostCSS] [Andrey Sitnik].
47
46
 
48
47
  Read more about color spaces in css:
48
+
49
49
  - [OKLCH in CSS: why we moved from RGB and HSL](https://evilmartians.com/chronicles/oklch-in-css-why-quit-rgb-hsl)
50
50
  - [LCH colors in CSS: what, why, and how?](https://lea.verou.me/2020/04/lch-colors-in-css-what-why-and-how/)
51
51
  - [A Guide To Modern CSS Colors](https://www.smashingmagazine.com/2021/11/guide-modern-css-colors/)
52
+ - [Better dynamic themes in Tailwind with OKLCH color magic](https://evilmartians.com/chronicles/better-dynamic-themes-in-tailwind-with-oklch-color-magic)
52
53
 
53
54
  [Stylelint]: https://stylelint.io/
54
55
  [npm-version-img]: https://img.shields.io/npm/v/stylelint-gamut.svg
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "stylelint-gamut",
3
- "version": "1.3.3",
3
+ "version": "1.3.4",
4
4
  "description": "Stylelint plugin for working with different color spaces",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
7
- "format": "prettier --write",
8
- "lint": "eslint --fix",
7
+ "format": "prettier --write .",
8
+ "lint": "eslint --fix *.js",
9
9
  "test": "jest",
10
10
  "prepare": "husky install"
11
11
  },
12
12
  "lint-staged": {
13
- "*.js": "npm run lint",
14
- ".": "npm run format"
13
+ "*.js": "eslint --fix",
14
+ ".": "prettier -write"
15
15
  },
16
16
  "engines": {
17
17
  "node": ">=16.0.0"
@@ -40,11 +40,11 @@
40
40
  },
41
41
  "homepage": "https://github.com/fpetrakov/stylelint-gamut#readme",
42
42
  "peerDependencies": {
43
- "stylelint": "^14.0.0 || ^15.0.0"
43
+ "stylelint": "^14.0.0 || ^15.0.0 || ^16.0.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "eslint": "^8.43.0",
47
- "eslint-config-prettier": "^8.8.0",
47
+ "eslint-config-prettier": "^9.0.0",
48
48
  "eslint-config-standard": "^17.1.0",
49
49
  "eslint-plugin-import": "^2.27.5",
50
50
  "eslint-plugin-n": "^16.0.0",
@@ -53,8 +53,8 @@
53
53
  "jest": "^29.5.0",
54
54
  "jest-cli": "^29.5.0",
55
55
  "jest-preset-stylelint": "^6.1.0",
56
- "lint-staged": "^13.2.2",
57
- "prettier": "^2.8.8",
56
+ "lint-staged": "^15.0.2",
57
+ "prettier": "^3.0.3",
58
58
  "stylelint": "^15.7.0"
59
59
  },
60
60
  "dependencies": {
package/src/README.md CHANGED
@@ -15,7 +15,7 @@ This rule checks if the color is in sRGB, p3 or rec2020 space. If it's not in sR
15
15
  @media (color-gamut: p3) {
16
16
  a {
17
17
  color: lch(29.8% 42.5 109.485);
18
- /* This color is in p3 gamut range */
18
+ /* This color is in p3 gamut range */
19
19
  }
20
20
  }
21
21
  ```
@@ -24,7 +24,7 @@ This rule checks if the color is in sRGB, p3 or rec2020 space. If it's not in sR
24
24
  @media (color-gamut: rec2020) {
25
25
  a {
26
26
  color: lch(25.1% 42.5 109.485);
27
- /* This color is in rec2020 gamut range */
27
+ /* This color is in rec2020 gamut range */
28
28
  }
29
29
  }
30
30
  ```
@@ -38,6 +38,7 @@ In case of **css custom properties** you should wrap either the custom property
38
38
  }
39
39
  }
40
40
  ```
41
+
41
42
  or the rule that uses the custom property:
42
43
 
43
44
  ```css
@@ -51,7 +52,9 @@ or the rule that uses the custom property:
51
52
  Custom properties inside color declaration are ignored:
52
53
 
53
54
  ```css
54
- background-color: oklch(var(--oklch-primary) / var(--alpha-bg)); /* not checked */
55
+ background-color: oklch(
56
+ var(--oklch-primary) / var(--alpha-bg)
57
+ ); /* not checked */
55
58
  ```
56
59
 
57
60
  Please note that conditional imports are not checked, e.g.:
package/src/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  const stylelint = require("stylelint");
4
4
  const Color = require("colorjs.io").default;
5
+
5
6
  const {
6
7
  isInColorGamutP3MediaQuery,
7
8
  isStandardSyntaxProperty,
@@ -13,7 +14,7 @@ const {
13
14
  const ruleName = "gamut/color-no-out-gamut-range";
14
15
 
15
16
  const messages = stylelint.utils.ruleMessages(ruleName, {
16
- rejected: color => `Unexpected color out of gamut range "${color}"`,
17
+ rejected: (color) => `Unexpected color out of gamut range "${color}"`,
17
18
  });
18
19
 
19
20
  const meta = {
@@ -21,7 +22,7 @@ const meta = {
21
22
  };
22
23
 
23
24
  /** @type {import('stylelint').Rule} */
24
- const ruleFunction = primary => {
25
+ const ruleFunction = (primary) => {
25
26
  return (root, result) => {
26
27
  const validOptions = stylelint.utils.validateOptions(result, ruleName, {
27
28
  actual: primary,
@@ -33,19 +34,20 @@ const ruleFunction = primary => {
33
34
 
34
35
  const customProperties = {};
35
36
 
36
- root.walkDecls(decl => {
37
+ root.walkDecls((decl) => {
37
38
  if (!isStandardSyntaxProperty(decl.prop)) return;
38
39
 
39
40
  const values = decl.value.match(
40
41
  /(oklch|oklab|lab|lch|var)\([^)]+\)/g,
41
42
  );
42
- if (values) {
43
- for (const value of values) {
44
- check(value);
45
- }
46
- }
43
+
44
+ if (!values) return;
47
45
 
48
46
  // value is e.g. lch(48% 82 283 / 67%)
47
+ for (const value of values) {
48
+ check(value);
49
+ }
50
+
49
51
  function check(value) {
50
52
  const shouldBeIgnored =
51
53
  !value.startsWith("var(--") &&
package/src/utils.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * @param {import('postcss').Declaration} decl
7
7
  * @returns {number}
8
8
  */
9
- function declarationValueIndex(decl) {
9
+ const declarationValueIndex = (decl) => {
10
10
  const raws = decl.raws;
11
11
 
12
12
  return [
@@ -22,7 +22,7 @@ function declarationValueIndex(decl) {
22
22
 
23
23
  return count;
24
24
  }, 0);
25
- }
25
+ };
26
26
 
27
27
  /**
28
28
  * Check whether a property is standard
@@ -30,7 +30,7 @@ function declarationValueIndex(decl) {
30
30
  * @param {string} property
31
31
  * @return {boolean} If `true`, the property is standard
32
32
  */
33
- function isStandardSyntaxProperty(property) {
33
+ const isStandardSyntaxProperty = (property) => {
34
34
  // SCSS var (e.g. $var: x), list (e.g. $list: (x)) or map (e.g. $map: (key:value))
35
35
  if (property.startsWith("$")) {
36
36
  return false;
@@ -47,13 +47,13 @@ function isStandardSyntaxProperty(property) {
47
47
  }
48
48
 
49
49
  return true;
50
- }
50
+ };
51
51
 
52
52
  /**
53
53
  * @param {import('postcss').Declaration} decl
54
54
  * @returns {boolean}
55
55
  */
56
- function isInColorGamutP3MediaQuery(decl) {
56
+ const isInColorGamutP3MediaQuery = (decl) => {
57
57
  const parentMediaQuery = getMediaQueryParent(decl);
58
58
 
59
59
  if (
@@ -64,13 +64,13 @@ function isInColorGamutP3MediaQuery(decl) {
64
64
  }
65
65
 
66
66
  return false;
67
- }
67
+ };
68
68
 
69
69
  /**
70
70
  * @param {import('postcss').Declaration} decl
71
71
  * @returns {boolean}
72
72
  */
73
- function isInColorGamutRec2020MediaQuery(decl) {
73
+ const isInColorGamutRec2020MediaQuery = (decl) => {
74
74
  const parentMediaQuery = getMediaQueryParent(decl);
75
75
 
76
76
  if (
@@ -81,13 +81,13 @@ function isInColorGamutRec2020MediaQuery(decl) {
81
81
  }
82
82
 
83
83
  return false;
84
- }
84
+ };
85
85
 
86
86
  /**
87
87
  * @param {import('postcss').Declaration} decl
88
88
  * @returns {boolean | decl}
89
89
  */
90
- function getMediaQueryParent(decl) {
90
+ const getMediaQueryParent = (decl) => {
91
91
  let parent = decl.parent;
92
92
 
93
93
  if (parent && isMediaQuery(parent)) return parent;
@@ -95,19 +95,15 @@ function getMediaQueryParent(decl) {
95
95
  parent = parent.parent;
96
96
 
97
97
  return isMediaQuery(parent) && parent;
98
- }
98
+ };
99
99
 
100
100
  /**
101
101
  * @param {import('postcss').Declaration} decl
102
102
  * @returns {boolean}
103
103
  */
104
- function isMediaQuery(decl) {
105
- return decl.type === "atrule" && decl.name === "media";
106
- }
104
+ const isMediaQuery = (decl) => decl.type === "atrule" && decl.name === "media";
107
105
 
108
- function startsWithNumber(str) {
109
- return /^\d/.test(str);
110
- }
106
+ const startsWithNumber = (str) => /^\d/.test(str);
111
107
 
112
108
  module.exports = {
113
109
  isStandardSyntaxProperty,