@metamask/eslint-plugin-design-tokens 0.1.0 → 1.0.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/CHANGELOG.md +8 -1
- package/dist/index.js +1 -0
- package/dist/index.mjs +46 -2
- package/dist/rules/color-no-hex.js +51 -0
- package/dist/rules/color-no-hex.mjs +45 -0
- package/dist/rules/index.js +3 -1
- package/dist/rules/index.mjs +45 -1
- package/dist/rules/no-deprecated-classnames.js +1 -1
- package/dist/rules/no-deprecated-classnames.mjs +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,11 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.0.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Adding `color-no-hex` rule ([#11](https://github.com/MetaMask/eslint-plugin-design-tokens/pull/11))
|
|
15
|
+
|
|
10
16
|
## [0.1.0]
|
|
11
17
|
|
|
12
18
|
### Changed
|
|
13
19
|
|
|
14
20
|
- Initial release
|
|
15
21
|
|
|
16
|
-
[Unreleased]: https://github.com/MetaMask/eslint-plugin-design-tokens/compare/
|
|
22
|
+
[Unreleased]: https://github.com/MetaMask/eslint-plugin-design-tokens/compare/v1.0.0...HEAD
|
|
23
|
+
[1.0.0]: https://github.com/MetaMask/eslint-plugin-design-tokens/compare/v0.1.0...v1.0.0
|
|
17
24
|
[0.1.0]: https://github.com/MetaMask/eslint-plugin-design-tokens/releases/tag/v0.1.0
|
package/dist/index.js
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -6,7 +6,7 @@ var noDeprecatedClassnames = {
|
|
|
6
6
|
description: "No deprecated classnames allowed",
|
|
7
7
|
recommended: false,
|
|
8
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
|
|
9
|
+
url: "https://github.com/MetaMask/eslint-plugin-design-tokens/blob/main/docs/rules/no-deprecated-classnames.md"
|
|
10
10
|
},
|
|
11
11
|
// Define the schema to accept an object of deprecated classnames
|
|
12
12
|
schema: [
|
|
@@ -51,9 +51,53 @@ var noDeprecatedClassnames = {
|
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
+
// src/rules/color-no-hex.ts
|
|
55
|
+
var hexColorRegex = /(#\p{Hex_Digit}{3,6})\b/u;
|
|
56
|
+
var colorNoHex = {
|
|
57
|
+
meta: {
|
|
58
|
+
type: "problem",
|
|
59
|
+
docs: {
|
|
60
|
+
description: "Prevent the use of hex color values.",
|
|
61
|
+
recommended: true,
|
|
62
|
+
url: "https://github.com/MetaMask/eslint-plugin-design-tokens/blob/main/docs/rules/color-no-hex.md"
|
|
63
|
+
},
|
|
64
|
+
schema: []
|
|
65
|
+
// This rule does not take any options
|
|
66
|
+
},
|
|
67
|
+
create(context) {
|
|
68
|
+
return {
|
|
69
|
+
Literal(node) {
|
|
70
|
+
if (typeof node.value === "string") {
|
|
71
|
+
const matches = node.value.match(hexColorRegex);
|
|
72
|
+
if (matches) {
|
|
73
|
+
const hexValue = matches[1];
|
|
74
|
+
context.report({
|
|
75
|
+
node,
|
|
76
|
+
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.`
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
TemplateLiteral(node) {
|
|
82
|
+
node.quasis.forEach((part) => {
|
|
83
|
+
const matches = part.value.raw.match(hexColorRegex);
|
|
84
|
+
if (matches) {
|
|
85
|
+
const hexValue = matches[1];
|
|
86
|
+
context.report({
|
|
87
|
+
node: part,
|
|
88
|
+
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.`
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
54
97
|
// src/index.ts
|
|
55
98
|
var rules = {
|
|
56
|
-
"no-deprecated-classnames": noDeprecatedClassnames
|
|
99
|
+
"no-deprecated-classnames": noDeprecatedClassnames,
|
|
100
|
+
"color-no-hex": colorNoHex
|
|
57
101
|
};
|
|
58
102
|
export {
|
|
59
103
|
rules
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.colorNoHex = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Regular expression to match hex color values.
|
|
6
|
+
* Added capturing group to extract the hex value.
|
|
7
|
+
* Using 'u' flag for Unicode support.
|
|
8
|
+
*/
|
|
9
|
+
const hexColorRegex = /(#\p{Hex_Digit}{3,6})\b/u;
|
|
10
|
+
/**
|
|
11
|
+
* Rule to prevent the use of hex color values.
|
|
12
|
+
*/
|
|
13
|
+
exports.colorNoHex = {
|
|
14
|
+
meta: {
|
|
15
|
+
type: 'problem',
|
|
16
|
+
docs: {
|
|
17
|
+
description: 'Prevent the use of hex color values.',
|
|
18
|
+
recommended: true,
|
|
19
|
+
url: 'https://github.com/MetaMask/eslint-plugin-design-tokens/blob/main/docs/rules/color-no-hex.md',
|
|
20
|
+
},
|
|
21
|
+
schema: [], // This rule does not take any options
|
|
22
|
+
},
|
|
23
|
+
create(context) {
|
|
24
|
+
return {
|
|
25
|
+
Literal(node) {
|
|
26
|
+
if (typeof node.value === 'string') {
|
|
27
|
+
const matches = node.value.match(hexColorRegex);
|
|
28
|
+
if (matches) {
|
|
29
|
+
const hexValue = matches[1]; // Type assertion to string
|
|
30
|
+
context.report({
|
|
31
|
+
node,
|
|
32
|
+
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.`,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
TemplateLiteral(node) {
|
|
38
|
+
node.quasis.forEach((part) => {
|
|
39
|
+
const matches = part.value.raw.match(hexColorRegex);
|
|
40
|
+
if (matches) {
|
|
41
|
+
const hexValue = matches[1]; // Type assertion to string
|
|
42
|
+
context.report({
|
|
43
|
+
node: part,
|
|
44
|
+
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.`,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// src/rules/color-no-hex.ts
|
|
2
|
+
var hexColorRegex = /(#\p{Hex_Digit}{3,6})\b/u;
|
|
3
|
+
var colorNoHex = {
|
|
4
|
+
meta: {
|
|
5
|
+
type: "problem",
|
|
6
|
+
docs: {
|
|
7
|
+
description: "Prevent the use of hex color values.",
|
|
8
|
+
recommended: true,
|
|
9
|
+
url: "https://github.com/MetaMask/eslint-plugin-design-tokens/blob/main/docs/rules/color-no-hex.md"
|
|
10
|
+
},
|
|
11
|
+
schema: []
|
|
12
|
+
// This rule does not take any options
|
|
13
|
+
},
|
|
14
|
+
create(context) {
|
|
15
|
+
return {
|
|
16
|
+
Literal(node) {
|
|
17
|
+
if (typeof node.value === "string") {
|
|
18
|
+
const matches = node.value.match(hexColorRegex);
|
|
19
|
+
if (matches) {
|
|
20
|
+
const hexValue = matches[1];
|
|
21
|
+
context.report({
|
|
22
|
+
node,
|
|
23
|
+
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.`
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
TemplateLiteral(node) {
|
|
29
|
+
node.quasis.forEach((part) => {
|
|
30
|
+
const matches = part.value.raw.match(hexColorRegex);
|
|
31
|
+
if (matches) {
|
|
32
|
+
const hexValue = matches[1];
|
|
33
|
+
context.report({
|
|
34
|
+
node: part,
|
|
35
|
+
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.`
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
export {
|
|
44
|
+
colorNoHex
|
|
45
|
+
};
|
package/dist/rules/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.noDeprecatedClassnames = void 0;
|
|
3
|
+
exports.colorNoHex = exports.noDeprecatedClassnames = void 0;
|
|
4
4
|
var no_deprecated_classnames_1 = require("./no-deprecated-classnames");
|
|
5
5
|
Object.defineProperty(exports, "noDeprecatedClassnames", { enumerable: true, get: function () { return no_deprecated_classnames_1.noDeprecatedClassnames; } });
|
|
6
|
+
var color_no_hex_1 = require("./color-no-hex");
|
|
7
|
+
Object.defineProperty(exports, "colorNoHex", { enumerable: true, get: function () { return color_no_hex_1.colorNoHex; } });
|
package/dist/rules/index.mjs
CHANGED
|
@@ -6,7 +6,7 @@ var noDeprecatedClassnames = {
|
|
|
6
6
|
description: "No deprecated classnames allowed",
|
|
7
7
|
recommended: false,
|
|
8
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
|
|
9
|
+
url: "https://github.com/MetaMask/eslint-plugin-design-tokens/blob/main/docs/rules/no-deprecated-classnames.md"
|
|
10
10
|
},
|
|
11
11
|
// Define the schema to accept an object of deprecated classnames
|
|
12
12
|
schema: [
|
|
@@ -50,6 +50,50 @@ var noDeprecatedClassnames = {
|
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
|
+
|
|
54
|
+
// src/rules/color-no-hex.ts
|
|
55
|
+
var hexColorRegex = /(#\p{Hex_Digit}{3,6})\b/u;
|
|
56
|
+
var colorNoHex = {
|
|
57
|
+
meta: {
|
|
58
|
+
type: "problem",
|
|
59
|
+
docs: {
|
|
60
|
+
description: "Prevent the use of hex color values.",
|
|
61
|
+
recommended: true,
|
|
62
|
+
url: "https://github.com/MetaMask/eslint-plugin-design-tokens/blob/main/docs/rules/color-no-hex.md"
|
|
63
|
+
},
|
|
64
|
+
schema: []
|
|
65
|
+
// This rule does not take any options
|
|
66
|
+
},
|
|
67
|
+
create(context) {
|
|
68
|
+
return {
|
|
69
|
+
Literal(node) {
|
|
70
|
+
if (typeof node.value === "string") {
|
|
71
|
+
const matches = node.value.match(hexColorRegex);
|
|
72
|
+
if (matches) {
|
|
73
|
+
const hexValue = matches[1];
|
|
74
|
+
context.report({
|
|
75
|
+
node,
|
|
76
|
+
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.`
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
TemplateLiteral(node) {
|
|
82
|
+
node.quasis.forEach((part) => {
|
|
83
|
+
const matches = part.value.raw.match(hexColorRegex);
|
|
84
|
+
if (matches) {
|
|
85
|
+
const hexValue = matches[1];
|
|
86
|
+
context.report({
|
|
87
|
+
node: part,
|
|
88
|
+
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.`
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
};
|
|
53
96
|
export {
|
|
97
|
+
colorNoHex,
|
|
54
98
|
noDeprecatedClassnames
|
|
55
99
|
};
|
|
@@ -13,7 +13,7 @@ exports.noDeprecatedClassnames = {
|
|
|
13
13
|
description: 'No deprecated classnames allowed',
|
|
14
14
|
recommended: false,
|
|
15
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
|
|
16
|
+
url: 'https://github.com/MetaMask/eslint-plugin-design-tokens/blob/main/docs/rules/no-deprecated-classnames.md',
|
|
17
17
|
},
|
|
18
18
|
// Define the schema to accept an object of deprecated classnames
|
|
19
19
|
schema: [
|
|
@@ -6,7 +6,7 @@ var noDeprecatedClassnames = {
|
|
|
6
6
|
description: "No deprecated classnames allowed",
|
|
7
7
|
recommended: false,
|
|
8
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
|
|
9
|
+
url: "https://github.com/MetaMask/eslint-plugin-design-tokens/blob/main/docs/rules/no-deprecated-classnames.md"
|
|
10
10
|
},
|
|
11
11
|
// Define the schema to accept an object of deprecated classnames
|
|
12
12
|
schema: [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/eslint-plugin-design-tokens",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "An ESLint plugin designed to enforce best practices and consistency for using MetaMask design tokens across various projects",
|
|
5
5
|
"homepage": "https://github.com/MetaMask/eslint-plugin-design-tokens#readme",
|
|
6
6
|
"bugs": {
|