@metamask/eslint-plugin-design-tokens 1.1.1 → 2.0.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.
Files changed (45) hide show
  1. package/CHANGELOG.md +23 -5
  2. package/{LICENSE.MIT → LICENSE} +1 -1
  3. package/README.md +44 -66
  4. package/dist/{index.js → index.cjs} +2 -1
  5. package/dist/index.cjs.map +1 -0
  6. package/dist/index.d.cts +6 -0
  7. package/dist/index.d.cts.map +1 -0
  8. package/dist/index.d.mts +6 -0
  9. package/dist/index.d.mts.map +1 -0
  10. package/dist/index.mjs +6 -206
  11. package/dist/index.mjs.map +1 -0
  12. package/dist/rules/{color-no-hex.js → color-no-hex.cjs} +6 -2
  13. package/dist/rules/color-no-hex.cjs.map +1 -0
  14. package/dist/rules/color-no-hex.d.cts +6 -0
  15. package/dist/rules/color-no-hex.d.cts.map +1 -0
  16. package/dist/rules/color-no-hex.d.mts +6 -0
  17. package/dist/rules/color-no-hex.d.mts.map +1 -0
  18. package/dist/rules/color-no-hex.mjs +50 -43
  19. package/dist/rules/color-no-hex.mjs.map +1 -0
  20. package/dist/rules/{index.js → index.cjs} +4 -3
  21. package/dist/rules/index.cjs.map +1 -0
  22. package/dist/rules/index.d.cts +4 -0
  23. package/dist/rules/index.d.cts.map +1 -0
  24. package/dist/rules/index.d.mts +4 -0
  25. package/dist/rules/index.d.mts.map +1 -0
  26. package/dist/rules/index.mjs +4 -202
  27. package/dist/rules/index.mjs.map +1 -0
  28. package/dist/rules/{no-deprecated-classnames.js → no-deprecated-classnames.cjs} +2 -2
  29. package/dist/rules/no-deprecated-classnames.cjs.map +1 -0
  30. package/dist/rules/no-deprecated-classnames.d.cts +8 -0
  31. package/dist/rules/no-deprecated-classnames.d.cts.map +1 -0
  32. package/dist/rules/no-deprecated-classnames.d.mts +8 -0
  33. package/dist/rules/no-deprecated-classnames.d.mts.map +1 -0
  34. package/dist/rules/no-deprecated-classnames.mjs +56 -53
  35. package/dist/rules/no-deprecated-classnames.mjs.map +1 -0
  36. package/dist/rules/{prefer-theme-color-classnames.js → prefer-theme-color-classnames.cjs} +29 -31
  37. package/dist/rules/prefer-theme-color-classnames.cjs.map +1 -0
  38. package/dist/rules/prefer-theme-color-classnames.d.cts +29 -0
  39. package/dist/rules/prefer-theme-color-classnames.d.cts.map +1 -0
  40. package/dist/rules/prefer-theme-color-classnames.d.mts +29 -0
  41. package/dist/rules/prefer-theme-color-classnames.d.mts.map +1 -0
  42. package/dist/rules/prefer-theme-color-classnames.mjs +102 -100
  43. package/dist/rules/prefer-theme-color-classnames.mjs.map +1 -0
  44. package/package.json +42 -61
  45. package/LICENSE.APACHE2 +0 -201
@@ -0,0 +1,4 @@
1
+ export { noDeprecatedClassnames } from "./no-deprecated-classnames.mjs";
2
+ export { preferThemeColorClassnames } from "./prefer-theme-color-classnames.mjs";
3
+ export { colorNoHex } from "./color-no-hex.mjs";
4
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,uCAAmC;AACpE,OAAO,EAAE,0BAA0B,EAAE,4CAAwC;AAC7E,OAAO,EAAE,UAAU,EAAE,2BAAuB"}
@@ -1,202 +1,4 @@
1
- // src/rules/no-deprecated-classnames.ts
2
- var noDeprecatedClassnames = {
3
- meta: {
4
- type: "suggestion",
5
- docs: {
6
- description: "No deprecated classnames allowed",
7
- recommended: false,
8
- // Make sure to replace the URL with the actual location of your rule's documentation
9
- url: "https://github.com/MetaMask/eslint-plugin-design-tokens/blob/main/docs/rules/no-deprecated-classnames.md"
10
- },
11
- // Define the schema to accept an object of deprecated classnames
12
- schema: [
13
- {
14
- type: "object",
15
- additionalProperties: {
16
- type: "string"
17
- }
18
- }
19
- ]
20
- },
21
- /**
22
- * The `create` method that gets executed by ESLint when linting files.
23
- * It checks for deprecated classnames and reports them.
24
- *
25
- * @param context - The ESLint rule context providing interfaces to report node information.
26
- * @returns An object with methods targeting specific nodes in the AST.
27
- */
28
- create(context) {
29
- const deprecatedClassnames = context.options[0] || {};
30
- return {
31
- /**
32
- * Listener for Literal nodes in the AST. It splits class names in string literals
33
- * and checks each against the list of deprecated class names.
34
- *
35
- * @param node - The AST node being visited.
36
- */
37
- Literal(node) {
38
- if (typeof node.value === "string") {
39
- const classNames = node.value.split(" ");
40
- classNames.forEach((className) => {
41
- if (Object.keys(deprecatedClassnames).includes(className)) {
42
- context.report({
43
- node,
44
- message: `${className} is a deprecated TailwindCSS class. ${deprecatedClassnames[className] ?? "No alternative available."}`
45
- });
46
- }
47
- });
48
- }
49
- }
50
- };
51
- }
52
- };
53
-
54
- // src/rules/prefer-theme-color-classnames.ts
55
- var preferThemeColorClassnames = {
56
- meta: {
57
- type: "suggestion",
58
- docs: {
59
- description: "Encourage the use of theme color class names instead of literal color class names.",
60
- recommended: true,
61
- url: "https://github.com/MetaMask/eslint-plugin-design-tokens/blob/main/docs/rules/prefer-theme-color-classnames.md"
62
- },
63
- // Adding a schema to accept options
64
- schema: [
65
- {
66
- type: "object",
67
- properties: {
68
- discouragedColors: {
69
- type: "array",
70
- items: {
71
- type: "string",
72
- minLength: 1
73
- // This ensures that the string is not empty but does not prevent whitespace-only strings.
74
- },
75
- default: [
76
- "blue",
77
- "red",
78
- "gray",
79
- "slateGray",
80
- "green",
81
- "orange",
82
- "black",
83
- "white",
84
- "indigo",
85
- "yellow",
86
- "purple",
87
- "pink",
88
- "teal"
89
- ]
90
- }
91
- },
92
- additionalProperties: false
93
- }
94
- ],
95
- messages: {
96
- discouragedColorUsage: `'{{className}}' usage of literal color class names is discouraged. Consider using theme color class names instead.`
97
- }
98
- },
99
- create(context) {
100
- const options = context.options[0] || {};
101
- const discouragedColors = options.discouragedColors || [
102
- "blue",
103
- "red",
104
- "gray",
105
- "slateGray",
106
- "green",
107
- "orange",
108
- "black",
109
- "white",
110
- "indigo",
111
- "yellow",
112
- "purple",
113
- "pink",
114
- "teal"
115
- ];
116
- const validColors = discouragedColors.filter(
117
- (color) => color.trim().length > 0
118
- );
119
- if (validColors.length === 0) {
120
- return {};
121
- }
122
- const colorRegex = new RegExp(
123
- `\\b(\\w+-)?(${discouragedColors.join("|")})-?\\d*\\b`,
124
- "iu"
125
- );
126
- function checkLiteralOrTemplateValue(value, node) {
127
- if (!value.trim()) {
128
- return;
129
- }
130
- const matches = value.match(colorRegex);
131
- if (matches?.[0]) {
132
- context.report({
133
- node,
134
- messageId: "discouragedColorUsage",
135
- data: {
136
- className: matches[0]
137
- }
138
- });
139
- }
140
- }
141
- return {
142
- Literal(node) {
143
- if (typeof node.value === "string") {
144
- checkLiteralOrTemplateValue(node.value, node);
145
- }
146
- },
147
- TemplateLiteral(node) {
148
- node.quasis.forEach((quasi) => {
149
- checkLiteralOrTemplateValue(quasi.value.raw, quasi);
150
- });
151
- }
152
- };
153
- }
154
- };
155
-
156
- // src/rules/color-no-hex.ts
157
- var hexColorRegex = /(#\p{Hex_Digit}{3,6})\b/u;
158
- var colorNoHex = {
159
- meta: {
160
- type: "problem",
161
- docs: {
162
- description: "Prevent the use of hex color values.",
163
- recommended: true,
164
- url: "https://github.com/MetaMask/eslint-plugin-design-tokens/blob/main/docs/rules/color-no-hex.md"
165
- },
166
- schema: []
167
- // This rule does not take any options
168
- },
169
- create(context) {
170
- return {
171
- Literal(node) {
172
- if (typeof node.value === "string") {
173
- const matches = node.value.match(hexColorRegex);
174
- if (matches) {
175
- const hexValue = matches[1];
176
- context.report({
177
- node,
178
- message: `'${hexValue}' Hex color values are not allowed. Consider using design tokens instead. For support reach out to the design system team #metamask-design-system on Slack.`
179
- });
180
- }
181
- }
182
- },
183
- TemplateLiteral(node) {
184
- node.quasis.forEach((part) => {
185
- const matches = part.value.raw.match(hexColorRegex);
186
- if (matches) {
187
- const hexValue = matches[1];
188
- context.report({
189
- node: part,
190
- message: `'${hexValue}' Hex color values are not allowed. Consider using design tokens instead. For support reach out to the design system team #metamask-design-system on Slack.`
191
- });
192
- }
193
- });
194
- }
195
- };
196
- }
197
- };
198
- export {
199
- colorNoHex,
200
- noDeprecatedClassnames,
201
- preferThemeColorClassnames
202
- };
1
+ export { noDeprecatedClassnames } from "./no-deprecated-classnames.mjs";
2
+ export { preferThemeColorClassnames } from "./prefer-theme-color-classnames.mjs";
3
+ export { colorNoHex } from "./color-no-hex.mjs";
4
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,uCAAmC;AACpE,OAAO,EAAE,0BAA0B,EAAE,4CAAwC;AAC7E,OAAO,EAAE,UAAU,EAAE,2BAAuB","sourcesContent":["export { noDeprecatedClassnames } from './no-deprecated-classnames';\nexport { preferThemeColorClassnames } from './prefer-theme-color-classnames';\nexport { colorNoHex } from './color-no-hex';\n"]}
@@ -12,8 +12,7 @@ exports.noDeprecatedClassnames = {
12
12
  docs: {
13
13
  description: 'No deprecated classnames allowed',
14
14
  recommended: false,
15
- // Make sure to replace the URL with the actual location of your rule's documentation
16
- url: 'https://github.com/MetaMask/eslint-plugin-design-tokens/blob/main/docs/rules/no-deprecated-classnames.md',
15
+ url: 'https://github.com/MetaMask/metamask-design-system/blob/main/packages/eslint-plugin-design-tokens/docs/rules/no-deprecated-classnames.md',
17
16
  },
18
17
  // Define the schema to accept an object of deprecated classnames
19
18
  schema: [
@@ -59,3 +58,4 @@ exports.noDeprecatedClassnames = {
59
58
  };
60
59
  },
61
60
  };
61
+ //# sourceMappingURL=no-deprecated-classnames.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-deprecated-classnames.cjs","sourceRoot":"","sources":["../../src/rules/no-deprecated-classnames.ts"],"names":[],"mappings":";;;AAUA;;;;GAIG;AACU,QAAA,sBAAsB,GAAoB;IACrD,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EAAE,kCAAkC;YAC/C,WAAW,EAAE,KAAK;YAClB,GAAG,EAAE,0IAA0I;SAChJ;QACD,iEAAiE;QACjE,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,oBAAoB,EAAE;oBACpB,IAAI,EAAE,QAAQ;iBACf;aACF;SACF;KACF;IACD;;;;;;OAMG;IACH,MAAM,CAAC,OAAO;QACZ,6DAA6D;QAC7D,MAAM,oBAAoB,GAAyB,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAE5E,OAAO;YACL;;;;;eAKG;YACH,OAAO,CAAC,IAAI;gBACV,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;oBACnC,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;oBACzC,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;wBAC/B,IAAI,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;4BAC1D,oEAAoE;4BACpE,OAAO,CAAC,MAAM,CAAC;gCACb,IAAI;gCACJ,OAAO,EAAE,GAAG,SAAS,uCACnB,oBAAoB,CAAC,SAAS,CAAC,IAAI,2BACrC,EAAE;6BACH,CAAC,CAAC;wBACL,CAAC;oBACH,CAAC,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["import type { Rule } from 'eslint';\n\n/**\n * Type definition for deprecated class names.\n * Maps deprecated TailwindCSS class names to suggestion messages.\n */\ntype DeprecatedClassnames = {\n [key: string]: string;\n};\n\n/**\n * The main rule module for detecting deprecated TailwindCSS class names.\n * This ESLint rule checks for the usage of deprecated TailwindCSS class names\n * and suggests updated alternatives based on a configurable list.\n */\nexport const noDeprecatedClassnames: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n docs: {\n description: 'No deprecated classnames allowed',\n recommended: false,\n url: 'https://github.com/MetaMask/metamask-design-system/blob/main/packages/eslint-plugin-design-tokens/docs/rules/no-deprecated-classnames.md',\n },\n // Define the schema to accept an object of deprecated classnames\n schema: [\n {\n type: 'object',\n additionalProperties: {\n type: 'string',\n },\n },\n ],\n },\n /**\n * The `create` method that gets executed by ESLint when linting files.\n * It checks for deprecated classnames and reports them.\n *\n * @param context - The ESLint rule context providing interfaces to report node information.\n * @returns An object with methods targeting specific nodes in the AST.\n */\n create(context) {\n // Access the first option as the deprecatedClassnames object\n const deprecatedClassnames: DeprecatedClassnames = context.options[0] || {};\n\n return {\n /**\n * Listener for Literal nodes in the AST. It splits class names in string literals\n * and checks each against the list of deprecated class names.\n *\n * @param node - The AST node being visited.\n */\n Literal(node) {\n if (typeof node.value === 'string') {\n const classNames = node.value.split(' ');\n classNames.forEach((className) => {\n if (Object.keys(deprecatedClassnames).includes(className)) {\n // Report the deprecated class name usage with a suggestion message.\n context.report({\n node,\n message: `${className} is a deprecated TailwindCSS class. ${\n deprecatedClassnames[className] ?? 'No alternative available.'\n }`,\n });\n }\n });\n }\n },\n };\n },\n};\n"]}
@@ -0,0 +1,8 @@
1
+ import type { Rule } from "eslint";
2
+ /**
3
+ * The main rule module for detecting deprecated TailwindCSS class names.
4
+ * This ESLint rule checks for the usage of deprecated TailwindCSS class names
5
+ * and suggests updated alternatives based on a configurable list.
6
+ */
7
+ export declare const noDeprecatedClassnames: Rule.RuleModule;
8
+ //# sourceMappingURL=no-deprecated-classnames.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-deprecated-classnames.d.cts","sourceRoot":"","sources":["../../src/rules/no-deprecated-classnames.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,eAAe;AAUnC;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAE,IAAI,CAAC,UAsDzC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { Rule } from "eslint";
2
+ /**
3
+ * The main rule module for detecting deprecated TailwindCSS class names.
4
+ * This ESLint rule checks for the usage of deprecated TailwindCSS class names
5
+ * and suggests updated alternatives based on a configurable list.
6
+ */
7
+ export declare const noDeprecatedClassnames: Rule.RuleModule;
8
+ //# sourceMappingURL=no-deprecated-classnames.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-deprecated-classnames.d.mts","sourceRoot":"","sources":["../../src/rules/no-deprecated-classnames.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,eAAe;AAUnC;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAE,IAAI,CAAC,UAsDzC,CAAC"}
@@ -1,55 +1,58 @@
1
- // src/rules/no-deprecated-classnames.ts
2
- var noDeprecatedClassnames = {
3
- meta: {
4
- type: "suggestion",
5
- docs: {
6
- description: "No deprecated classnames allowed",
7
- recommended: false,
8
- // Make sure to replace the URL with the actual location of your rule's documentation
9
- url: "https://github.com/MetaMask/eslint-plugin-design-tokens/blob/main/docs/rules/no-deprecated-classnames.md"
1
+ /**
2
+ * The main rule module for detecting deprecated TailwindCSS class names.
3
+ * This ESLint rule checks for the usage of deprecated TailwindCSS class names
4
+ * and suggests updated alternatives based on a configurable list.
5
+ */
6
+ export const noDeprecatedClassnames = {
7
+ meta: {
8
+ type: 'suggestion',
9
+ docs: {
10
+ description: 'No deprecated classnames allowed',
11
+ recommended: false,
12
+ url: 'https://github.com/MetaMask/metamask-design-system/blob/main/packages/eslint-plugin-design-tokens/docs/rules/no-deprecated-classnames.md',
13
+ },
14
+ // Define the schema to accept an object of deprecated classnames
15
+ schema: [
16
+ {
17
+ type: 'object',
18
+ additionalProperties: {
19
+ type: 'string',
20
+ },
21
+ },
22
+ ],
23
+ },
24
+ /**
25
+ * The `create` method that gets executed by ESLint when linting files.
26
+ * It checks for deprecated classnames and reports them.
27
+ *
28
+ * @param context - The ESLint rule context providing interfaces to report node information.
29
+ * @returns An object with methods targeting specific nodes in the AST.
30
+ */
31
+ create(context) {
32
+ // Access the first option as the deprecatedClassnames object
33
+ const deprecatedClassnames = context.options[0] || {};
34
+ return {
35
+ /**
36
+ * Listener for Literal nodes in the AST. It splits class names in string literals
37
+ * and checks each against the list of deprecated class names.
38
+ *
39
+ * @param node - The AST node being visited.
40
+ */
41
+ Literal(node) {
42
+ if (typeof node.value === 'string') {
43
+ const classNames = node.value.split(' ');
44
+ classNames.forEach((className) => {
45
+ if (Object.keys(deprecatedClassnames).includes(className)) {
46
+ // Report the deprecated class name usage with a suggestion message.
47
+ context.report({
48
+ node,
49
+ message: `${className} is a deprecated TailwindCSS class. ${deprecatedClassnames[className] ?? 'No alternative available.'}`,
50
+ });
51
+ }
52
+ });
53
+ }
54
+ },
55
+ };
10
56
  },
11
- // Define the schema to accept an object of deprecated classnames
12
- schema: [
13
- {
14
- type: "object",
15
- additionalProperties: {
16
- type: "string"
17
- }
18
- }
19
- ]
20
- },
21
- /**
22
- * The `create` method that gets executed by ESLint when linting files.
23
- * It checks for deprecated classnames and reports them.
24
- *
25
- * @param context - The ESLint rule context providing interfaces to report node information.
26
- * @returns An object with methods targeting specific nodes in the AST.
27
- */
28
- create(context) {
29
- const deprecatedClassnames = context.options[0] || {};
30
- return {
31
- /**
32
- * Listener for Literal nodes in the AST. It splits class names in string literals
33
- * and checks each against the list of deprecated class names.
34
- *
35
- * @param node - The AST node being visited.
36
- */
37
- Literal(node) {
38
- if (typeof node.value === "string") {
39
- const classNames = node.value.split(" ");
40
- classNames.forEach((className) => {
41
- if (Object.keys(deprecatedClassnames).includes(className)) {
42
- context.report({
43
- node,
44
- message: `${className} is a deprecated TailwindCSS class. ${deprecatedClassnames[className] ?? "No alternative available."}`
45
- });
46
- }
47
- });
48
- }
49
- }
50
- };
51
- }
52
- };
53
- export {
54
- noDeprecatedClassnames
55
57
  };
58
+ //# sourceMappingURL=no-deprecated-classnames.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-deprecated-classnames.mjs","sourceRoot":"","sources":["../../src/rules/no-deprecated-classnames.ts"],"names":[],"mappings":"AAUA;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAoB;IACrD,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EAAE,kCAAkC;YAC/C,WAAW,EAAE,KAAK;YAClB,GAAG,EAAE,0IAA0I;SAChJ;QACD,iEAAiE;QACjE,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,oBAAoB,EAAE;oBACpB,IAAI,EAAE,QAAQ;iBACf;aACF;SACF;KACF;IACD;;;;;;OAMG;IACH,MAAM,CAAC,OAAO;QACZ,6DAA6D;QAC7D,MAAM,oBAAoB,GAAyB,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAE5E,OAAO;YACL;;;;;eAKG;YACH,OAAO,CAAC,IAAI;gBACV,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;oBACnC,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;oBACzC,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;wBAC/B,IAAI,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;4BAC1D,oEAAoE;4BACpE,OAAO,CAAC,MAAM,CAAC;gCACb,IAAI;gCACJ,OAAO,EAAE,GAAG,SAAS,uCACnB,oBAAoB,CAAC,SAAS,CAAC,IAAI,2BACrC,EAAE;6BACH,CAAC,CAAC;wBACL,CAAC;oBACH,CAAC,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["import type { Rule } from 'eslint';\n\n/**\n * Type definition for deprecated class names.\n * Maps deprecated TailwindCSS class names to suggestion messages.\n */\ntype DeprecatedClassnames = {\n [key: string]: string;\n};\n\n/**\n * The main rule module for detecting deprecated TailwindCSS class names.\n * This ESLint rule checks for the usage of deprecated TailwindCSS class names\n * and suggests updated alternatives based on a configurable list.\n */\nexport const noDeprecatedClassnames: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n docs: {\n description: 'No deprecated classnames allowed',\n recommended: false,\n url: 'https://github.com/MetaMask/metamask-design-system/blob/main/packages/eslint-plugin-design-tokens/docs/rules/no-deprecated-classnames.md',\n },\n // Define the schema to accept an object of deprecated classnames\n schema: [\n {\n type: 'object',\n additionalProperties: {\n type: 'string',\n },\n },\n ],\n },\n /**\n * The `create` method that gets executed by ESLint when linting files.\n * It checks for deprecated classnames and reports them.\n *\n * @param context - The ESLint rule context providing interfaces to report node information.\n * @returns An object with methods targeting specific nodes in the AST.\n */\n create(context) {\n // Access the first option as the deprecatedClassnames object\n const deprecatedClassnames: DeprecatedClassnames = context.options[0] || {};\n\n return {\n /**\n * Listener for Literal nodes in the AST. It splits class names in string literals\n * and checks each against the list of deprecated class names.\n *\n * @param node - The AST node being visited.\n */\n Literal(node) {\n if (typeof node.value === 'string') {\n const classNames = node.value.split(' ');\n classNames.forEach((className) => {\n if (Object.keys(deprecatedClassnames).includes(className)) {\n // Report the deprecated class name usage with a suggestion message.\n context.report({\n node,\n message: `${className} is a deprecated TailwindCSS class. ${\n deprecatedClassnames[className] ?? 'No alternative available.'\n }`,\n });\n }\n });\n }\n },\n };\n },\n};\n"]}
@@ -1,6 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.preferThemeColorClassnames = void 0;
3
+ exports.preferThemeColorClassnames = exports.defaultDiscouragedColors = void 0;
4
+ /**
5
+ * The literal color classnames that MetaMask's Tailwind and twrnc setups
6
+ * expose, and that theme color classnames should be preferred over.
7
+ *
8
+ * Brand color families (`grey`, `blue`, `lime`, ...) are deliberately not
9
+ * included: no MetaMask Tailwind or twrnc configuration exposes them as
10
+ * classnames. The Tailwind v4 theme resets the color namespace with
11
+ * `--color-*: initial`, the twrnc preset and consumers' Tailwind configs
12
+ * replace `theme.colors` with semantic theme colors plus the two literal
13
+ * colors below, and the deprecated Tailwind v3 preset only ever extends the
14
+ * palette with semantic theme colors. Literal classes such as `bg-blue-500`
15
+ * therefore never resolve, and unknown-classname linting (e.g.
16
+ * `tailwindcss/no-custom-classname`) is the more accurate signal for them.
17
+ * `black` and `white` are the only literal colors that resolve in every
18
+ * setup, which makes them what this rule discourages by default.
19
+ *
20
+ * Widen the list through the `discouragedColors` option for projects that
21
+ * keep a larger literal palette available. The test suite derives the
22
+ * standalone literal colors from the brand palette in
23
+ * `packages/design-tokens/src/css/brand-colors.css` and asserts this list
24
+ * matches, so it must be updated whenever the palette changes.
25
+ */
26
+ exports.defaultDiscouragedColors = ['black', 'white'];
4
27
  /**
5
28
  * Rule to encourage the use of theme color class names instead of literal color class names.
6
29
  */
@@ -10,7 +33,7 @@ exports.preferThemeColorClassnames = {
10
33
  docs: {
11
34
  description: 'Encourage the use of theme color class names instead of literal color class names.',
12
35
  recommended: true,
13
- url: 'https://github.com/MetaMask/eslint-plugin-design-tokens/blob/main/docs/rules/prefer-theme-color-classnames.md',
36
+ url: 'https://github.com/MetaMask/metamask-design-system/blob/main/packages/eslint-plugin-design-tokens/docs/rules/prefer-theme-color-classnames.md',
14
37
  },
15
38
  // Adding a schema to accept options
16
39
  schema: [
@@ -23,21 +46,7 @@ exports.preferThemeColorClassnames = {
23
46
  type: 'string',
24
47
  minLength: 1, // This ensures that the string is not empty but does not prevent whitespace-only strings.
25
48
  },
26
- default: [
27
- 'blue',
28
- 'red',
29
- 'gray',
30
- 'slateGray',
31
- 'green',
32
- 'orange',
33
- 'black',
34
- 'white',
35
- 'indigo',
36
- 'yellow',
37
- 'purple',
38
- 'pink',
39
- 'teal',
40
- ],
49
+ default: [...exports.defaultDiscouragedColors],
41
50
  },
42
51
  },
43
52
  additionalProperties: false,
@@ -49,21 +58,9 @@ exports.preferThemeColorClassnames = {
49
58
  },
50
59
  create(context) {
51
60
  const options = context.options[0] || {};
52
- // Default to a list of discouraged color names if none are provided in the options.
61
+ // Default to the MetaMask brand palette if none are provided in the options.
53
62
  const discouragedColors = options.discouragedColors || [
54
- 'blue',
55
- 'red',
56
- 'gray',
57
- 'slateGray',
58
- 'green',
59
- 'orange',
60
- 'black',
61
- 'white',
62
- 'indigo',
63
- 'yellow',
64
- 'purple',
65
- 'pink',
66
- 'teal',
63
+ ...exports.defaultDiscouragedColors,
67
64
  ];
68
65
  // Validate discouragedColors to ensure no empty or whitespace-only strings
69
66
  const validColors = discouragedColors.filter((color) => color.trim().length > 0);
@@ -109,3 +106,4 @@ exports.preferThemeColorClassnames = {
109
106
  };
110
107
  },
111
108
  };
109
+ //# sourceMappingURL=prefer-theme-color-classnames.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prefer-theme-color-classnames.cjs","sourceRoot":"","sources":["../../src/rules/prefer-theme-color-classnames.ts"],"names":[],"mappings":";;;AAOA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACU,QAAA,wBAAwB,GAAG,CAAC,OAAO,EAAE,OAAO,CAAU,CAAC;AAEpE;;GAEG;AACU,QAAA,0BAA0B,GAAoB;IACzD,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,IAAI,EAAE;YACJ,WAAW,EACT,oFAAoF;YACtF,WAAW,EAAE,IAAI;YACjB,GAAG,EAAE,+IAA+I;SACrJ;QACD,oCAAoC;QACpC,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,iBAAiB,EAAE;wBACjB,IAAI,EAAE,OAAO;wBACb,KAAK,EAAE;4BACL,IAAI,EAAE,QAAQ;4BACd,SAAS,EAAE,CAAC,EAAE,0FAA0F;yBACzG;wBACD,OAAO,EAAE,CAAC,GAAG,gCAAwB,CAAC;qBACvC;iBACF;gBACD,oBAAoB,EAAE,KAAK;aAC5B;SACF;QACD,QAAQ,EAAE;YACR,qBAAqB,EAAE,oHAAoH;SAC5I;KACF;IACD,MAAM,CAAC,OAAO;QACZ,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAEzC,6EAA6E;QAC7E,MAAM,iBAAiB,GAAa,OAAO,CAAC,iBAAiB,IAAI;YAC/D,GAAG,gCAAwB;SAC5B,CAAC;QAEF,2EAA2E;QAC3E,MAAM,WAAW,GAAG,iBAAiB,CAAC,MAAM,CAC1C,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CACnC,CAAC;QAEF,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7B,OAAO,EAAE,CAAC,CAAC,6CAA6C;QAC1D,CAAC;QAED,yFAAyF;QACzF,MAAM,UAAU,GAAG,IAAI,MAAM,CAC3B,eAAe,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,EACtD,IAAI,CACL,CAAC;QAEF;;;;;;WAMG;QACH,SAAS,2BAA2B,CAClC,KAAa,EACb,IAAiC;YAEjC,uEAAuE;YACvE,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;gBAClB,OAAO;YACT,CAAC;YACD,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YACxC,IAAI,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACjB,OAAO,CAAC,MAAM,CAAC;oBACb,IAAI;oBACJ,SAAS,EAAE,uBAAuB;oBAClC,IAAI,EAAE;wBACJ,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;qBACtB;iBACF,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,OAAO;YACL,OAAO,CAAC,IAAI;gBACV,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;oBACnC,2BAA2B,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;gBAChD,CAAC;YACH,CAAC;YACD,eAAe,CAAC,IAAI;gBAClB,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;oBAC5B,2BAA2B,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;gBACtD,CAAC,CAAC,CAAC;YACL,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["import type { Rule } from 'eslint';\n\ntype TemplateElement = Extract<\n Rule.Node,\n { type: 'TemplateLiteral' }\n>['quasis'][number];\n\n/**\n * The literal color classnames that MetaMask's Tailwind and twrnc setups\n * expose, and that theme color classnames should be preferred over.\n *\n * Brand color families (`grey`, `blue`, `lime`, ...) are deliberately not\n * included: no MetaMask Tailwind or twrnc configuration exposes them as\n * classnames. The Tailwind v4 theme resets the color namespace with\n * `--color-*: initial`, the twrnc preset and consumers' Tailwind configs\n * replace `theme.colors` with semantic theme colors plus the two literal\n * colors below, and the deprecated Tailwind v3 preset only ever extends the\n * palette with semantic theme colors. Literal classes such as `bg-blue-500`\n * therefore never resolve, and unknown-classname linting (e.g.\n * `tailwindcss/no-custom-classname`) is the more accurate signal for them.\n * `black` and `white` are the only literal colors that resolve in every\n * setup, which makes them what this rule discourages by default.\n *\n * Widen the list through the `discouragedColors` option for projects that\n * keep a larger literal palette available. The test suite derives the\n * standalone literal colors from the brand palette in\n * `packages/design-tokens/src/css/brand-colors.css` and asserts this list\n * matches, so it must be updated whenever the palette changes.\n */\nexport const defaultDiscouragedColors = ['black', 'white'] as const;\n\n/**\n * Rule to encourage the use of theme color class names instead of literal color class names.\n */\nexport const preferThemeColorClassnames: Rule.RuleModule = {\n meta: {\n type: 'suggestion',\n docs: {\n description:\n 'Encourage the use of theme color class names instead of literal color class names.',\n recommended: true,\n url: 'https://github.com/MetaMask/metamask-design-system/blob/main/packages/eslint-plugin-design-tokens/docs/rules/prefer-theme-color-classnames.md',\n },\n // Adding a schema to accept options\n schema: [\n {\n type: 'object',\n properties: {\n discouragedColors: {\n type: 'array',\n items: {\n type: 'string',\n minLength: 1, // This ensures that the string is not empty but does not prevent whitespace-only strings.\n },\n default: [...defaultDiscouragedColors],\n },\n },\n additionalProperties: false,\n },\n ],\n messages: {\n discouragedColorUsage: `'{{className}}' usage of literal color class names is discouraged. Consider using theme color class names instead.`,\n },\n },\n create(context) {\n const options = context.options[0] || {};\n\n // Default to the MetaMask brand palette if none are provided in the options.\n const discouragedColors: string[] = options.discouragedColors || [\n ...defaultDiscouragedColors,\n ];\n\n // Validate discouragedColors to ensure no empty or whitespace-only strings\n const validColors = discouragedColors.filter(\n (color) => color.trim().length > 0,\n );\n\n if (validColors.length === 0) {\n return {}; // Exit early if no valid colors are provided\n }\n\n // Create a regex that matches class names containing any of the discouraged color names.\n const colorRegex = new RegExp(\n `\\\\b(\\\\w+-)?(${discouragedColors.join('|')})-?\\\\d*\\\\b`,\n 'iu',\n );\n\n /**\n * Checks if a given string value contains discouraged literal color names in CSS class names and reports them.\n * This function is designed to handle both literals and template literals, capturing classes that violate the rules.\n *\n * @param value - The string value to check against the defined regex for discouraged color names. This could be the raw text from a Literal node or a segment of a TemplateLiteral node in the AST (Abstract Syntax Tree).\n * @param node - The AST node associated with the value; used for reporting the ESLint error. This node object is part of ESLint's traversal of JavaScript code and provides context like location and type, which are used in reporting and potentially fixing violations.\n */\n function checkLiteralOrTemplateValue(\n value: string,\n node: Rule.Node | TemplateElement,\n ) {\n // Return early if the string to be checked is empty or only whitespace\n if (!value.trim()) {\n return;\n }\n const matches = value.match(colorRegex);\n if (matches?.[0]) {\n context.report({\n node,\n messageId: 'discouragedColorUsage',\n data: {\n className: matches[0],\n },\n });\n }\n }\n\n return {\n Literal(node) {\n if (typeof node.value === 'string') {\n checkLiteralOrTemplateValue(node.value, node);\n }\n },\n TemplateLiteral(node) {\n node.quasis.forEach((quasi) => {\n checkLiteralOrTemplateValue(quasi.value.raw, quasi);\n });\n },\n };\n },\n};\n"]}
@@ -0,0 +1,29 @@
1
+ import type { Rule } from "eslint";
2
+ /**
3
+ * The literal color classnames that MetaMask's Tailwind and twrnc setups
4
+ * expose, and that theme color classnames should be preferred over.
5
+ *
6
+ * Brand color families (`grey`, `blue`, `lime`, ...) are deliberately not
7
+ * included: no MetaMask Tailwind or twrnc configuration exposes them as
8
+ * classnames. The Tailwind v4 theme resets the color namespace with
9
+ * `--color-*: initial`, the twrnc preset and consumers' Tailwind configs
10
+ * replace `theme.colors` with semantic theme colors plus the two literal
11
+ * colors below, and the deprecated Tailwind v3 preset only ever extends the
12
+ * palette with semantic theme colors. Literal classes such as `bg-blue-500`
13
+ * therefore never resolve, and unknown-classname linting (e.g.
14
+ * `tailwindcss/no-custom-classname`) is the more accurate signal for them.
15
+ * `black` and `white` are the only literal colors that resolve in every
16
+ * setup, which makes them what this rule discourages by default.
17
+ *
18
+ * Widen the list through the `discouragedColors` option for projects that
19
+ * keep a larger literal palette available. The test suite derives the
20
+ * standalone literal colors from the brand palette in
21
+ * `packages/design-tokens/src/css/brand-colors.css` and asserts this list
22
+ * matches, so it must be updated whenever the palette changes.
23
+ */
24
+ export declare const defaultDiscouragedColors: readonly ["black", "white"];
25
+ /**
26
+ * Rule to encourage the use of theme color class names instead of literal color class names.
27
+ */
28
+ export declare const preferThemeColorClassnames: Rule.RuleModule;
29
+ //# sourceMappingURL=prefer-theme-color-classnames.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prefer-theme-color-classnames.d.cts","sourceRoot":"","sources":["../../src/rules/prefer-theme-color-classnames.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,eAAe;AAOnC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,wBAAwB,6BAA8B,CAAC;AAEpE;;GAEG;AACH,eAAO,MAAM,0BAA0B,EAAE,IAAI,CAAC,UA6F7C,CAAC"}
@@ -0,0 +1,29 @@
1
+ import type { Rule } from "eslint";
2
+ /**
3
+ * The literal color classnames that MetaMask's Tailwind and twrnc setups
4
+ * expose, and that theme color classnames should be preferred over.
5
+ *
6
+ * Brand color families (`grey`, `blue`, `lime`, ...) are deliberately not
7
+ * included: no MetaMask Tailwind or twrnc configuration exposes them as
8
+ * classnames. The Tailwind v4 theme resets the color namespace with
9
+ * `--color-*: initial`, the twrnc preset and consumers' Tailwind configs
10
+ * replace `theme.colors` with semantic theme colors plus the two literal
11
+ * colors below, and the deprecated Tailwind v3 preset only ever extends the
12
+ * palette with semantic theme colors. Literal classes such as `bg-blue-500`
13
+ * therefore never resolve, and unknown-classname linting (e.g.
14
+ * `tailwindcss/no-custom-classname`) is the more accurate signal for them.
15
+ * `black` and `white` are the only literal colors that resolve in every
16
+ * setup, which makes them what this rule discourages by default.
17
+ *
18
+ * Widen the list through the `discouragedColors` option for projects that
19
+ * keep a larger literal palette available. The test suite derives the
20
+ * standalone literal colors from the brand palette in
21
+ * `packages/design-tokens/src/css/brand-colors.css` and asserts this list
22
+ * matches, so it must be updated whenever the palette changes.
23
+ */
24
+ export declare const defaultDiscouragedColors: readonly ["black", "white"];
25
+ /**
26
+ * Rule to encourage the use of theme color class names instead of literal color class names.
27
+ */
28
+ export declare const preferThemeColorClassnames: Rule.RuleModule;
29
+ //# sourceMappingURL=prefer-theme-color-classnames.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prefer-theme-color-classnames.d.mts","sourceRoot":"","sources":["../../src/rules/prefer-theme-color-classnames.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,eAAe;AAOnC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,wBAAwB,6BAA8B,CAAC;AAEpE;;GAEG;AACH,eAAO,MAAM,0BAA0B,EAAE,IAAI,CAAC,UA6F7C,CAAC"}