@dialpad/stylelint-plugin-dialtone 1.2.1 → 1.3.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.
@@ -0,0 +1,49 @@
1
+ const stylelint = require('stylelint');
2
+
3
+ const {
4
+ createPlugin,
5
+ utils: { report, ruleMessages, validateOptions },
6
+ } = stylelint;
7
+
8
+ const ruleName = '@dialpad/stylelint-plugin-dialtone/no-base-color-tokens';
9
+
10
+ const messages = ruleMessages(ruleName, {
11
+ noBaseColorsRejected: (colorToken) => `Please avoid using base color tokens: "${colorToken}"`,
12
+ });
13
+
14
+ const meta = {
15
+ url: 'https://github.com/dialpad/dialtone/blob/staging/packages/stylelint-plugin-dialtone/docs/rules/no-base-color-tokens.md',
16
+ };
17
+
18
+ /** @type {import('stylelint').Rule} */
19
+ const ruleFunction = (primary) => {
20
+ return (root, result) => {
21
+ const validOptions = validateOptions(result, ruleName, {
22
+ actual: primary,
23
+ });
24
+
25
+ if (!validOptions) return;
26
+
27
+ // This iterates through one selector at a time, so you don't have to worry about checking for nested selectors.
28
+ root.walkDecls((declaration) => {
29
+ if (!declaration.value.match(/var\(--dt-color-\w+-\d{2,4}\)/)) return;
30
+
31
+ const tokenName = declaration.value.replace('var(', '').replace(')', '');
32
+
33
+ report({
34
+ result,
35
+ ruleName,
36
+ node: declaration,
37
+ start: declaration.source.start,
38
+ end: declaration.source.end,
39
+ message: messages.noBaseColorsRejected(tokenName),
40
+ });
41
+ });
42
+ };
43
+ };
44
+
45
+ ruleFunction.ruleName = ruleName;
46
+ ruleFunction.messages = messages;
47
+ ruleFunction.meta = meta;
48
+
49
+ module.exports = createPlugin(ruleName, ruleFunction);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dialpad/stylelint-plugin-dialtone",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "description": "dialtone stylelint plugin",
5
5
  "keywords": [
6
6
  "Dialpad",