@dialpad/stylelint-plugin-dialtone 1.4.0-next.2 → 1.4.0-next.3
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
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const noBaseColorTokens = require('./rules/no-base-color-tokens');
|
|
4
4
|
const noDeprecatedSizeTokens = require('./rules/no-deprecated-size-tokens');
|
|
5
5
|
const noDeprecatedSpaceTokens = require('./rules/no-deprecated-space-tokens');
|
|
6
|
+
const noDeprecatedSuccessTokens = require('./rules/no-deprecated-success-tokens');
|
|
6
7
|
const noMixins = require('./rules/no-mixins');
|
|
7
8
|
const recommendFontStyleTokens = require('./rules/recommend-font-style-tokens');
|
|
8
9
|
const useDialtoneTokens = require('./rules/use-dialtone-tokens');
|
|
@@ -12,6 +13,7 @@ module.exports = [
|
|
|
12
13
|
noBaseColorTokens,
|
|
13
14
|
noDeprecatedSizeTokens,
|
|
14
15
|
noDeprecatedSpaceTokens,
|
|
16
|
+
noDeprecatedSuccessTokens,
|
|
15
17
|
noMixins,
|
|
16
18
|
recommendFontStyleTokens,
|
|
17
19
|
useDialtoneTokens,
|
|
@@ -0,0 +1,58 @@
|
|
|
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-deprecated-success-tokens';
|
|
9
|
+
|
|
10
|
+
const messages = ruleMessages(ruleName, {
|
|
11
|
+
deprecated: (successToken, positiveToken) =>
|
|
12
|
+
`Replace "${successToken}" with "${positiveToken}". Run "npx dialtone-migration-helper --config success-to-positive" to migrate automatically.`,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const meta = {
|
|
16
|
+
url: 'https://github.com/dialpad/dialtone/blob/staging/packages/stylelint-plugin-dialtone/docs/rules/no-deprecated-success-tokens.md',
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// Match var(--dt-color-{role}-success{suffix?}) where role is foreground, surface,
|
|
20
|
+
// border, or link, and suffix (if present) is one of the known variants. The
|
|
21
|
+
// suffix list mirrors the `success-to-positive` migration helper so flagged
|
|
22
|
+
// tokens always have a valid `positive*` replacement.
|
|
23
|
+
const SUCCESS_SUFFIX = '(?:-(?:subtle-opaque-inverted|subtle-opaque|subtle-inverted|strong-inverted|opaque-inverted|inverted-hover|subtle|strong|opaque|inverted|hover))?';
|
|
24
|
+
const SUCCESS_TOKEN_RE = new RegExp(`var\\(--dt-color-(?:foreground|surface|border|link)-success${SUCCESS_SUFFIX}\\)`, 'g');
|
|
25
|
+
|
|
26
|
+
/** @type {import('stylelint').Rule} */
|
|
27
|
+
const ruleFunction = (primary) => {
|
|
28
|
+
return (root, result) => {
|
|
29
|
+
const validOptions = validateOptions(result, ruleName, {
|
|
30
|
+
actual: primary,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
if (!validOptions) return;
|
|
34
|
+
|
|
35
|
+
root.walkDecls((declaration) => {
|
|
36
|
+
const matches = declaration.value.match(SUCCESS_TOKEN_RE);
|
|
37
|
+
if (!matches) return;
|
|
38
|
+
|
|
39
|
+
matches.forEach((match) => {
|
|
40
|
+
const successToken = match.replace('var(', '').replace(/\)$/, '');
|
|
41
|
+
const positiveToken = successToken.replace('-success', '-positive');
|
|
42
|
+
|
|
43
|
+
report({
|
|
44
|
+
result,
|
|
45
|
+
ruleName,
|
|
46
|
+
node: declaration,
|
|
47
|
+
message: messages.deprecated(successToken, positiveToken),
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
ruleFunction.ruleName = ruleName;
|
|
55
|
+
ruleFunction.messages = messages;
|
|
56
|
+
ruleFunction.meta = meta;
|
|
57
|
+
|
|
58
|
+
module.exports = createPlugin(ruleName, ruleFunction);
|