@dialpad/stylelint-plugin-dialtone 1.1.0 → 1.2.1
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/lib/index.js +2 -1
- package/lib/rules/use-dialtone-tokens.js +69 -0
- package/package.json +7 -2
package/lib/index.js
CHANGED
|
@@ -2,5 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
const noMixins = require("./rules/no-mixins");
|
|
4
4
|
const recommendFontStyleTokens = require("./rules/recommend-font-style-tokens");
|
|
5
|
+
const useDialtoneTokens = require("./rules/use-dialtone-tokens");
|
|
5
6
|
|
|
6
|
-
module.exports = [noMixins, recommendFontStyleTokens];
|
|
7
|
+
module.exports = [noMixins, recommendFontStyleTokens, useDialtoneTokens];
|
|
@@ -0,0 +1,69 @@
|
|
|
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/use-dialtone-tokens';
|
|
9
|
+
|
|
10
|
+
const messages = ruleMessages(ruleName, {
|
|
11
|
+
useDialtoneTokens: (value) => `Use a Dialtone token instead of "${value}".
|
|
12
|
+
A list of available tokens can be found here: https://dialtone.dialpad.com/tokens.
|
|
13
|
+
Consult with design on which token should be used and only with their approval ignore this rule.`,
|
|
14
|
+
useRemInsteadOfPx: (value) => `If it's not possible to use a Dialtone token, use ${pxToRem(value)} instead of ${value}.`,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const pxToRem = (value) => {
|
|
18
|
+
const val = parseFloat(value.replace('px', ''));
|
|
19
|
+
return val / 10 + 'rem';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const meta = {
|
|
23
|
+
url: "https://github.com/dialpad/dialtone/blob/staging/packages/stylelint-plugin-dialtone/docs/rules/use-dialtone-tokens.md",
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** @type {import('stylelint').Rule} */
|
|
27
|
+
const ruleFunction = (primary) => {
|
|
28
|
+
// detects the use of px or rem in properties and suggests to use a Dialtone token
|
|
29
|
+
// or rem instead of px if a Dialtone token is not available
|
|
30
|
+
return (root, result) => {
|
|
31
|
+
const validOptions = validateOptions(result, ruleName, {
|
|
32
|
+
actual: primary,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
if (!validOptions) return;
|
|
36
|
+
|
|
37
|
+
// This iterates through one selector at a time, so you don't have to worry about checking for nested selectors.
|
|
38
|
+
root.walkDecls((declNode) => {
|
|
39
|
+
const hasRemUnit = declNode.value.includes('rem');
|
|
40
|
+
const hasPxUnit = declNode.value.includes('px');
|
|
41
|
+
if (hasRemUnit || hasPxUnit) {
|
|
42
|
+
report({
|
|
43
|
+
result,
|
|
44
|
+
ruleName,
|
|
45
|
+
node: declNode,
|
|
46
|
+
start: declNode.source.start,
|
|
47
|
+
end: declNode.source.end,
|
|
48
|
+
message: messages.useDialtoneTokens(declNode.value),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (hasPxUnit) {
|
|
52
|
+
report({
|
|
53
|
+
result,
|
|
54
|
+
ruleName,
|
|
55
|
+
node: declNode,
|
|
56
|
+
start: declNode.source.start,
|
|
57
|
+
end: declNode.source.end,
|
|
58
|
+
message: messages.useRemInsteadOfPx(declNode.value),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
ruleFunction.ruleName = ruleName;
|
|
66
|
+
ruleFunction.messages = messages;
|
|
67
|
+
ruleFunction.meta = meta;
|
|
68
|
+
|
|
69
|
+
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.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "dialtone stylelint plugin",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Dialpad",
|
|
@@ -44,7 +44,6 @@
|
|
|
44
44
|
],
|
|
45
45
|
"exports": "./lib/index.js",
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"stylelint": "15.11.0",
|
|
48
47
|
"stylelint-test-rule-node": "^0.2.1"
|
|
49
48
|
},
|
|
50
49
|
"engines": {
|
|
@@ -53,6 +52,12 @@
|
|
|
53
52
|
"peerDependencies": {
|
|
54
53
|
"stylelint": "^14.0.0 || ^15.0.0"
|
|
55
54
|
},
|
|
55
|
+
"nx": {
|
|
56
|
+
"includedScripts": [
|
|
57
|
+
"lint",
|
|
58
|
+
"test"
|
|
59
|
+
]
|
|
60
|
+
},
|
|
56
61
|
"scripts": {
|
|
57
62
|
"lint": "run-s lint:docs lint:code",
|
|
58
63
|
"lint:code": "eslint '**/*.js'",
|