@alfalab/stylelint-core-vars 1.3.0 → 1.4.0

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/index.js CHANGED
@@ -2,6 +2,7 @@ const stylelint = require('stylelint');
2
2
  const toOneLine = require('./utils').toOneLine;
3
3
  const formatVar = require('./utils').formatVar;
4
4
  const findVars = require('./utils').findVars;
5
+ const colorsSet = require('./utils').colorsSet;
5
6
  const findTypographyMixins = require('./utils').findTypographyMixins;
6
7
  const VARS_AVAILABLE = require('./utils').VARS_AVAILABLE;
7
8
 
@@ -14,12 +15,12 @@ const RULE_DO_NOT_USE_DARK_COLORS = 'stylelint-core-vars/do-not-use-dark-colors'
14
15
  const messages = {
15
16
  [RULE_USE_VARS]: stylelint.utils.ruleMessages(RULE_USE_VARS, {
16
17
  expected: (variable, value) => {
17
- return `Use variable '${variable}' instead of plain value '${value}'`;
18
+ return `Use variable 'var(${variable})' instead of plain value '${value}'`;
18
19
  },
19
20
  }),
20
21
  [RULE_USE_ONE_OF_VARS]: stylelint.utils.ruleMessages(RULE_USE_ONE_OF_VARS, {
21
22
  expected: (variables, value) => {
22
- const variablesPart = variables.map((v) => `${v}`).join('\n');
23
+ const variablesPart = variables.map((v) => `var(${v})`).join('\n');
23
24
 
24
25
  return `Use variables instead of plain value '${value}':\n${variablesPart}\n`;
25
26
  },
@@ -149,7 +150,7 @@ const checkDarkColorsUsage = (decl, result, context, ruleName) => {
149
150
 
150
151
  const matches = /--color-dark-[\w-]+/.exec(value);
151
152
 
152
- if (matches) {
153
+ if (matches && colorsSet.has(matches[0])) {
153
154
  stylelint.utils.report({
154
155
  result,
155
156
  ruleName: RULE_DO_NOT_USE_DARK_COLORS,
package/index.test.js CHANGED
@@ -80,6 +80,10 @@ testRule({
80
80
  border-radius: var(--border-radius-xl);
81
81
  border-radius: var(--border-radius-circle);
82
82
  border-radius: var(--border-radius-pill);
83
+ border-top-left-radius: var(--border-radius-s);
84
+ border-top-right-radius: var(--border-radius-s);
85
+ border-bottom-left-radius: var(--border-radius-s);
86
+ border-bottom-right-radius: var(--border-radius-s);
83
87
  }`,
84
88
  description: 'border-radius',
85
89
  },
@@ -215,12 +219,21 @@ testRule({
215
219
  ],
216
220
  },
217
221
  {
218
- code: `.class {\n border-radius: 8px;\n}`,
219
- fixed: `.class {\n border-radius: var(--border-radius-m);\n}`,
222
+ code: `.class {\n border-radius: 8px;\n border-top-left-radius: 4px;\n}`,
223
+ fixed: `.class {\n border-radius: var(--border-radius-m);\n border-top-left-radius: var(--border-radius-s);\n}`,
220
224
  description: 'hardcode border-radius',
221
- message: messages[RULE_USE_VARS].expected(['--border-radius-m'], '8px'),
222
- line: 2,
223
- column: 20,
225
+ warnings: [
226
+ {
227
+ message: messages[RULE_USE_VARS].expected(['--border-radius-m'], '8px'),
228
+ line: 2,
229
+ column: 20,
230
+ },
231
+ {
232
+ message: messages[RULE_USE_VARS].expected(['--border-radius-s'], '4px'),
233
+ line: 3,
234
+ column: 29,
235
+ }
236
+ ]
224
237
  },
225
238
  ...Object.entries(vars.gaps).map(([value, vars]) => {
226
239
  const gapVar = vars[0];
@@ -339,6 +352,10 @@ testRule({
339
352
  border-radius: var(--border-radius-xl);
340
353
  border-radius: var(--border-radius-circle);
341
354
  border-radius: var(--border-radius-pill);
355
+ border-top-left-radius: var(--border-radius-s);
356
+ border-top-right-radius: var(--border-radius-s);
357
+ border-bottom-left-radius: var(--border-radius-s);
358
+ border-bottom-right-radius: var(--border-radius-s);
342
359
  }`,
343
360
  description: 'border-radius',
344
361
  },
@@ -648,6 +665,12 @@ testRule({
648
665
  }`,
649
666
  description: 'allowed colors',
650
667
  },
668
+ {
669
+ code: `.class {
670
+ color: var(--color-dark-indigo);
671
+ }`,
672
+ description: 'old colors',
673
+ },
651
674
  ],
652
675
  reject: [
653
676
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alfalab/stylelint-core-vars",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "core-components css linter",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/utils.js CHANGED
@@ -19,6 +19,12 @@ const vars = {
19
19
  borderRadiuses: loadVars('border-radius.css'),
20
20
  };
21
21
 
22
+ const colorsSet = Object.values(vars.colors).reduce((acc, vars) => {
23
+ vars.forEach(colorVar => acc.add(colorVar));
24
+
25
+ return acc;
26
+ }, new Set());
27
+
22
28
  const mixins = {
23
29
  typography: loadMixins('typography.css'),
24
30
  };
@@ -44,6 +50,10 @@ const varsByProperties = {
44
50
  'border-bottom': vars.colors,
45
51
  'border-left': vars.colors,
46
52
  'border-radius': vars.borderRadiuses,
53
+ 'border-top-left-radius': vars.borderRadiuses,
54
+ 'border-top-right-radius': vars.borderRadiuses,
55
+ 'border-bottom-left-radius': vars.borderRadiuses,
56
+ 'border-bottom-right-radius': vars.borderRadiuses,
47
57
  };
48
58
 
49
59
  const VARS_AVAILABLE = Boolean(getInstalledVarsPackage()) || runInsideCoreComponents();
@@ -258,6 +268,7 @@ function sortVarsByUsage(arr, sortingArr) {
258
268
 
259
269
  module.exports.VARS_AVAILABLE = VARS_AVAILABLE;
260
270
  module.exports.vars = vars;
271
+ module.exports.colorsSet = colorsSet;
261
272
  module.exports.mixins = mixins;
262
273
  module.exports.findVars = findVars;
263
274
  module.exports.formatVar = formatVar;