@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
package/CHANGELOG.md CHANGED
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.0.1]
11
+
12
+ ### Fixed
13
+
14
+ - Aligned the rules with the current design tokens ([#1723](https://github.com/MetaMask/metamask-design-system/pull/1723))
15
+ - `prefer-theme-color-classnames` now defaults `discouragedColors` to `black` and `white`, the only literal color classnames the MetaMask Tailwind and twrnc setups expose; literal brand-family and `gray` classes (for example `bg-blue-500`, `text-gray-500`, `bg-grey-050`) are no longer flagged by default because those classnames never resolve under MetaMask setups — restore any of them through the `discouragedColors` option
16
+ - `color-no-hex` now reports 8-digit hex values with an alpha channel (for example `#4459ff1a`), which previously went unflagged
17
+ - Rule docs and links now point at the `metamask-design-system` monorepo
18
+
19
+ ## [2.0.0]
20
+
21
+ ### Changed
22
+
23
+ - **BREAKING:** The minimum supported Node.js version is now 24 (`engines.node` is `>=24`) ([#38](https://github.com/MetaMask/eslint-plugin-design-tokens/pull/38))
24
+ - This package is being migrated to the [`metamask-design-system`](https://github.com/MetaMask/metamask-design-system) monorepo ([#37](https://github.com/MetaMask/eslint-plugin-design-tokens/pull/37))
25
+
10
26
  ## [1.1.1]
11
27
 
12
28
  ### Changed
@@ -33,8 +49,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
33
49
 
34
50
  - Initial release
35
51
 
36
- [Unreleased]: https://github.com/MetaMask/eslint-plugin-design-tokens/compare/v1.1.1...HEAD
37
- [1.1.1]: https://github.com/MetaMask/eslint-plugin-design-tokens/compare/v1.1.0...v1.1.1
38
- [1.1.0]: https://github.com/MetaMask/eslint-plugin-design-tokens/compare/v1.0.0...v1.1.0
39
- [1.0.0]: https://github.com/MetaMask/eslint-plugin-design-tokens/compare/v0.1.0...v1.0.0
40
- [0.1.0]: https://github.com/MetaMask/eslint-plugin-design-tokens/releases/tag/v0.1.0
52
+ [Unreleased]: https://github.com/MetaMask/metamask-design-system/compare/@metamask/eslint-plugin-design-tokens@2.0.1...HEAD
53
+ [2.0.1]: https://github.com/MetaMask/metamask-design-system/compare/@metamask/eslint-plugin-design-tokens@2.0.0...@metamask/eslint-plugin-design-tokens@2.0.1
54
+ [2.0.0]: https://github.com/MetaMask/metamask-design-system/compare/@metamask/eslint-plugin-design-tokens@1.1.1...@metamask/eslint-plugin-design-tokens@2.0.0
55
+ [1.1.1]: https://github.com/MetaMask/metamask-design-system/compare/@metamask/eslint-plugin-design-tokens@1.1.0...@metamask/eslint-plugin-design-tokens@1.1.1
56
+ [1.1.0]: https://github.com/MetaMask/metamask-design-system/compare/@metamask/eslint-plugin-design-tokens@1.0.0...@metamask/eslint-plugin-design-tokens@1.1.0
57
+ [1.0.0]: https://github.com/MetaMask/metamask-design-system/compare/@metamask/eslint-plugin-design-tokens@0.1.0...@metamask/eslint-plugin-design-tokens@1.0.0
58
+ [0.1.0]: https://github.com/MetaMask/metamask-design-system/releases/tag/@metamask/eslint-plugin-design-tokens@0.1.0
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 MetaMask
3
+ Copyright (c) 2024 MetaMask
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,16 +1,10 @@
1
- # ESlint Plugin Design Tokens 🪙✨
1
+ # `@metamask/eslint-plugin-design-tokens`
2
2
 
3
- [![npm version](https://badge.fury.io/js/@metamask%2Feslint-plugin-design-tokens.svg)](https://npmjs.com/package/@metamask/eslint-plugin-design-tokens)
4
-
5
- ## `@metamask/eslint-plugin-design-tokens`
6
-
7
- An ESLint plugin designed to enforce best practices and consistency for using MetaMask [design tokens](https://github.com/MetaMask/design-tokens) across various projects
8
-
9
- Have a question, suggestion, feedback? Contributors can [create an issue](https://github.com/MetaMask/eslint-plugin-design-tokens/issues/new/choose) or internal folks can post on the [#metamask-design-system](https://consensys.slack.com/archives/C0354T27M5M) Slack channel. We're here to help! 💁
3
+ An ESLint plugin designed to enforce best practices and consistency for using MetaMask [design tokens](https://github.com/MetaMask/metamask-design-system/tree/main/packages/design-tokens) across various projects
10
4
 
11
5
  ## Installation
12
6
 
13
- You'll first need to install [ESLint](https://eslint.org):
7
+ You'll first need to install [ESLint](https://eslint.org) 9 or later. This package lists `eslint` as a peer dependency:
14
8
 
15
9
  ```shell
16
10
  $ npm install --save-dev eslint
@@ -21,15 +15,17 @@ $ yarn add --dev eslint
21
15
  Next, install `@metamask/eslint-plugin-design-tokens`:
22
16
 
23
17
  ```shell
24
- $ npm install --save-dev @metamask/eslint-plugin-design-tokens
18
+ $ yarn add @metamask/eslint-plugin-design-tokens
25
19
  # or
26
- $ yarn add --dev @metamask/eslint-plugin-design-tokens
20
+ $ npm install @metamask/eslint-plugin-design-tokens
27
21
  ```
28
22
 
29
23
  **Note:** If you installed ESLint globally (using the `-g` flag) then you must also install `@metamask/eslint-plugin-design-tokens` globally.
30
24
 
31
25
  ## Usage
32
26
 
27
+ ### Legacy config
28
+
33
29
  Add `@metamask/design-tokens` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:
34
30
 
35
31
  ```json
@@ -56,65 +52,47 @@ Then configure the rules you want to use within `rules` property of your `.eslin
56
52
  }
57
53
  ```
58
54
 
55
+ ### Flat config
56
+
57
+ The package publishes a named `rules` export. Register that object under the plugin name in `eslint.config.js`:
58
+
59
+ ```js
60
+ import { rules } from '@metamask/eslint-plugin-design-tokens';
61
+
62
+ export default [
63
+ {
64
+ plugins: {
65
+ '@metamask/design-tokens': { rules },
66
+ },
67
+ rules: {
68
+ '@metamask/design-tokens/no-deprecated-classnames': [
69
+ 'warn',
70
+ {
71
+ 'bg-white':
72
+ "Use 'bg-default' to align with the design system's color tokens.",
73
+ 'bg-surface-default':
74
+ "Use 'bg-default' to align with the design system's color tokens.",
75
+ 'text-red-500':
76
+ "Use 'text-error-default' to align with the design system's color tokens.",
77
+ 'text-critical':
78
+ "Use 'text-error-default' to align with the design system's color tokens.",
79
+ },
80
+ ],
81
+ },
82
+ },
83
+ ];
84
+ ```
85
+
59
86
  ## Supported Rules
60
87
 
61
88
  > Remember that all rules from this plugin are prefixed by `"@metamask/design-tokens/"`
62
89
 
63
- | Name                                                                              | Description |
64
- | :-------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- |
65
- | [no-deprecated-classnames](docs/rules/no-deprecated-classnames.md) | Enforce usage of up-to-date TailwindCSS class names, disallowing deprecated ones. |
66
- | [color-no-hex](docs/rules/color-no-hex.md) | Prevent the use of hex color values. |
67
- | [prefer-theme-color-classnames](docs/rules/prefer-theme-color-classnames.md) | Encourage the use of theme color class names instead of literal color class names. |
90
+ | Name | Description |
91
+ | :--------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- |
92
+ | [no-deprecated-classnames](docs/rules/no-deprecated-classnames.md) | Enforce usage of up-to-date TailwindCSS class names, disallowing deprecated ones. |
93
+ | [color-no-hex](docs/rules/color-no-hex.md) | Prevent the use of hex color values. |
94
+ | [prefer-theme-color-classnames](docs/rules/prefer-theme-color-classnames.md) | Encourage the use of theme color class names instead of literal color class names. |
68
95
 
69
96
  ## Contributing
70
97
 
71
- ### Setup
72
-
73
- - Install the current LTS version of [Node.js](https://nodejs.org)
74
- - If you are using [nvm](https://github.com/creationix/nvm#installation) (recommended) running `nvm install` will install the latest version and running `nvm use` will automatically choose the right node version for you.
75
- - Install [Yarn v3](https://yarnpkg.com/getting-started/install)
76
- - Run `yarn install` to install dependencies and run any required post-install scripts
77
-
78
- ### Testing and Linting
79
-
80
- Run `yarn test` to run the tests once. To run tests on file changes, run `yarn test:watch`.
81
-
82
- Run `yarn lint` to run the linter, or run `yarn lint:fix` to run the linter and fix any automatically fixable issues.
83
-
84
- ### Release & Publishing
85
-
86
- The project follows the same release process as the other libraries in the MetaMask organization. The GitHub Actions [`action-create-release-pr`](https://github.com/MetaMask/action-create-release-pr) and [`action-publish-release`](https://github.com/MetaMask/action-publish-release) are used to automate the release process; see those repositories for more information about how they work.
87
-
88
- 1. Choose a release version.
89
-
90
- - The release version should be chosen according to SemVer. Analyze the changes to see whether they include any breaking changes, new features, or deprecations, then choose the appropriate SemVer version. See [the SemVer specification](https://semver.org/) for more information.
91
-
92
- 2. If this release is backporting changes onto a previous release, then ensure there is a major version branch for that version (e.g. `1.x` for a `v1` backport release).
93
-
94
- - The major version branch should be set to the most recent release with that major version. For example, when backporting a `v1.0.2` release, you'd want to ensure there was a `1.x` branch that was set to the `v1.0.1` tag.
95
-
96
- 3. Trigger the [`workflow_dispatch`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#workflow_dispatch) event [manually](https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow) for the `Create Release Pull Request` action to create the release PR.
97
-
98
- - For a backport release, the base branch should be the major version branch that you ensured existed in step 2. For a normal release, the base branch should be the main branch for that repository (which should be the default value).
99
- - This should trigger the [`action-create-release-pr`](https://github.com/MetaMask/action-create-release-pr) workflow to create the release PR.
100
-
101
- 4. Update the changelog to move each change entry into the appropriate change category ([See here](https://keepachangelog.com/en/1.0.0/#types) for the full list of change categories, and the correct ordering), and edit them to be more easily understood by users of the package.
102
-
103
- - Generally any changes that don't affect consumers of the package (e.g. lockfile changes or development environment changes) are omitted. Exceptions may be made for changes that might be of interest despite not having an effect upon the published package (e.g. major test improvements, security improvements, improved documentation, etc.).
104
- - Try to explain each change in terms that users of the package would understand (e.g. avoid referencing internal variables/concepts).
105
- - Consolidate related changes into one change entry if it makes it easier to explain.
106
- - Run `yarn auto-changelog validate --rc` to check that the changelog is correctly formatted.
107
-
108
- 5. Review and QA the release.
109
-
110
- - If changes are made to the base branch, the release branch will need to be updated with these changes and review/QA will need to restart again. As such, it's probably best to avoid merging other PRs into the base branch while review is underway.
111
-
112
- 6. Squash & Merge the release.
113
-
114
- - This should trigger the [`action-publish-release`](https://github.com/MetaMask/action-publish-release) workflow to tag the final release commit and publish the release on GitHub.
115
-
116
- 7. Publish the release on npm.
117
-
118
- - Wait for the `publish-release` GitHub Action workflow to finish. This should trigger a second job (`publish-npm`), which will wait for a run approval by the [`npm publishers`](https://github.com/orgs/MetaMask/teams/npm-publishers) team.
119
- - Approve the `publish-npm` job (or ask somebody on the npm publishers team to approve it for you).
120
- - Once the `publish-npm` job has finished, check npm to verify that it has been published.
98
+ This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/metamask-design-system#readme).
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.rules = void 0;
4
- const rules_1 = require("./rules");
4
+ const rules_1 = require("./rules/index.cjs");
5
5
  exports.rules = {
6
6
  'no-deprecated-classnames': rules_1.noDeprecatedClassnames,
7
7
  'color-no-hex': rules_1.colorNoHex,
8
8
  'prefer-theme-color-classnames': rules_1.preferThemeColorClassnames,
9
9
  };
10
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,6CAIiB;AAEJ,QAAA,KAAK,GAAG;IACnB,0BAA0B,EAAE,8BAAsB;IAClD,cAAc,EAAE,kBAAU;IAC1B,+BAA+B,EAAE,kCAA0B;CAC5D,CAAC","sourcesContent":["import {\n noDeprecatedClassnames,\n colorNoHex,\n preferThemeColorClassnames,\n} from './rules';\n\nexport const rules = {\n 'no-deprecated-classnames': noDeprecatedClassnames,\n 'color-no-hex': colorNoHex,\n 'prefer-theme-color-classnames': preferThemeColorClassnames,\n};\n"]}
@@ -0,0 +1,6 @@
1
+ export declare const rules: {
2
+ 'no-deprecated-classnames': import("eslint").Rule.RuleModule;
3
+ 'color-no-hex': import("eslint").Rule.RuleModule;
4
+ 'prefer-theme-color-classnames': import("eslint").Rule.RuleModule;
5
+ };
6
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,KAAK;;;;CAIjB,CAAC"}
@@ -0,0 +1,6 @@
1
+ export declare const rules: {
2
+ 'no-deprecated-classnames': import("eslint").Rule.RuleModule;
3
+ 'color-no-hex': import("eslint").Rule.RuleModule;
4
+ 'prefer-theme-color-classnames': import("eslint").Rule.RuleModule;
5
+ };
6
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,KAAK;;;;CAIjB,CAAC"}
package/dist/index.mjs CHANGED
@@ -1,207 +1,7 @@
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
-
199
- // src/index.ts
200
- var rules = {
201
- "no-deprecated-classnames": noDeprecatedClassnames,
202
- "color-no-hex": colorNoHex,
203
- "prefer-theme-color-classnames": preferThemeColorClassnames
204
- };
205
- export {
206
- rules
1
+ import { noDeprecatedClassnames, colorNoHex, preferThemeColorClassnames } from "./rules/index.mjs";
2
+ export const rules = {
3
+ 'no-deprecated-classnames': noDeprecatedClassnames,
4
+ 'color-no-hex': colorNoHex,
5
+ 'prefer-theme-color-classnames': preferThemeColorClassnames,
207
6
  };
7
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,UAAU,EACV,0BAA0B,EAC3B,0BAAgB;AAEjB,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,0BAA0B,EAAE,sBAAsB;IAClD,cAAc,EAAE,UAAU;IAC1B,+BAA+B,EAAE,0BAA0B;CAC5D,CAAC","sourcesContent":["import {\n noDeprecatedClassnames,\n colorNoHex,\n preferThemeColorClassnames,\n} from './rules';\n\nexport const rules = {\n 'no-deprecated-classnames': noDeprecatedClassnames,\n 'color-no-hex': colorNoHex,\n 'prefer-theme-color-classnames': preferThemeColorClassnames,\n};\n"]}
@@ -4,9 +4,12 @@ exports.colorNoHex = void 0;
4
4
  /**
5
5
  * Regular expression to match hex color values.
6
6
  * Added capturing group to extract the hex value.
7
+ * Matches three to eight hex digits so that 8-digit ARGB values with an alpha
8
+ * channel (e.g. `#4459ff1a`, used by the current design tokens) are caught as
9
+ * well as 6-digit values.
7
10
  * Using 'u' flag for Unicode support.
8
11
  */
9
- const hexColorRegex = /(#\p{Hex_Digit}{3,6})\b/u;
12
+ const hexColorRegex = /(#\p{Hex_Digit}{3,8})\b/u;
10
13
  /**
11
14
  * Rule to prevent the use of hex color values.
12
15
  */
@@ -16,7 +19,7 @@ exports.colorNoHex = {
16
19
  docs: {
17
20
  description: 'Prevent the use of hex color values.',
18
21
  recommended: true,
19
- url: 'https://github.com/MetaMask/eslint-plugin-design-tokens/blob/main/docs/rules/color-no-hex.md',
22
+ url: 'https://github.com/MetaMask/metamask-design-system/blob/main/packages/eslint-plugin-design-tokens/docs/rules/color-no-hex.md',
20
23
  },
21
24
  schema: [], // This rule does not take any options
22
25
  },
@@ -49,3 +52,4 @@ exports.colorNoHex = {
49
52
  };
50
53
  },
51
54
  };
55
+ //# sourceMappingURL=color-no-hex.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color-no-hex.cjs","sourceRoot":"","sources":["../../src/rules/color-no-hex.ts"],"names":[],"mappings":";;;AACA;;;;;;;GAOG;AACH,MAAM,aAAa,GAAG,0BAA0B,CAAC;AAEjD;;GAEG;AACU,QAAA,UAAU,GAAoB;IACzC,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EAAE,sCAAsC;YACnD,WAAW,EAAE,IAAI;YACjB,GAAG,EAAE,8HAA8H;SACpI;QACD,MAAM,EAAE,EAAE,EAAE,sCAAsC;KACnD;IACD,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,OAAO,CAAC,IAAI;gBACV,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;oBACnC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;oBAChD,IAAI,OAAO,EAAE,CAAC;wBACZ,MAAM,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAW,CAAC,CAAC,2BAA2B;wBAClE,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI;4BACJ,OAAO,EAAE,IAAI,QAAQ,6JAA6J;yBACnL,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;YACH,CAAC;YACD,eAAe,CAAC,IAAI;gBAClB,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;oBAC3B,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;oBACpD,IAAI,OAAO,EAAE,CAAC;wBACZ,MAAM,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAW,CAAC,CAAC,2BAA2B;wBAClE,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI,EAAE,IAAI;4BACV,OAAO,EAAE,IAAI,QAAQ,6JAA6J;yBACnL,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC,CAAC,CAAC;YACL,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["import type { Rule } from 'eslint';\n/**\n * Regular expression to match hex color values.\n * Added capturing group to extract the hex value.\n * Matches three to eight hex digits so that 8-digit ARGB values with an alpha\n * channel (e.g. `#4459ff1a`, used by the current design tokens) are caught as\n * well as 6-digit values.\n * Using 'u' flag for Unicode support.\n */\nconst hexColorRegex = /(#\\p{Hex_Digit}{3,8})\\b/u;\n\n/**\n * Rule to prevent the use of hex color values.\n */\nexport const colorNoHex: Rule.RuleModule = {\n meta: {\n type: 'problem',\n docs: {\n description: 'Prevent the use of hex color values.',\n recommended: true,\n url: 'https://github.com/MetaMask/metamask-design-system/blob/main/packages/eslint-plugin-design-tokens/docs/rules/color-no-hex.md',\n },\n schema: [], // This rule does not take any options\n },\n create(context) {\n return {\n Literal(node) {\n if (typeof node.value === 'string') {\n const matches = node.value.match(hexColorRegex);\n if (matches) {\n const hexValue = matches[1] as string; // Type assertion to string\n context.report({\n node,\n 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.`,\n });\n }\n }\n },\n TemplateLiteral(node) {\n node.quasis.forEach((part) => {\n const matches = part.value.raw.match(hexColorRegex);\n if (matches) {\n const hexValue = matches[1] as string; // Type assertion to string\n context.report({\n node: part,\n 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.`,\n });\n }\n });\n },\n };\n },\n};\n"]}
@@ -0,0 +1,6 @@
1
+ import type { Rule } from "eslint";
2
+ /**
3
+ * Rule to prevent the use of hex color values.
4
+ */
5
+ export declare const colorNoHex: Rule.RuleModule;
6
+ //# sourceMappingURL=color-no-hex.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color-no-hex.d.cts","sourceRoot":"","sources":["../../src/rules/color-no-hex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,eAAe;AAWnC;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,IAAI,CAAC,UAsC7B,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { Rule } from "eslint";
2
+ /**
3
+ * Rule to prevent the use of hex color values.
4
+ */
5
+ export declare const colorNoHex: Rule.RuleModule;
6
+ //# sourceMappingURL=color-no-hex.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color-no-hex.d.mts","sourceRoot":"","sources":["../../src/rules/color-no-hex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,eAAe;AAWnC;;GAEG;AACH,eAAO,MAAM,UAAU,EAAE,IAAI,CAAC,UAsC7B,CAAC"}
@@ -1,45 +1,52 @@
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"
1
+ /**
2
+ * Regular expression to match hex color values.
3
+ * Added capturing group to extract the hex value.
4
+ * Matches three to eight hex digits so that 8-digit ARGB values with an alpha
5
+ * channel (e.g. `#4459ff1a`, used by the current design tokens) are caught as
6
+ * well as 6-digit values.
7
+ * Using 'u' flag for Unicode support.
8
+ */
9
+ const hexColorRegex = /(#\p{Hex_Digit}{3,8})\b/u;
10
+ /**
11
+ * Rule to prevent the use of hex color values.
12
+ */
13
+ export const 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/metamask-design-system/blob/main/packages/eslint-plugin-design-tokens/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
+ };
10
50
  },
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
51
  };
52
+ //# sourceMappingURL=color-no-hex.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color-no-hex.mjs","sourceRoot":"","sources":["../../src/rules/color-no-hex.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AACH,MAAM,aAAa,GAAG,0BAA0B,CAAC;AAEjD;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAoB;IACzC,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EAAE,sCAAsC;YACnD,WAAW,EAAE,IAAI;YACjB,GAAG,EAAE,8HAA8H;SACpI;QACD,MAAM,EAAE,EAAE,EAAE,sCAAsC;KACnD;IACD,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,OAAO,CAAC,IAAI;gBACV,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;oBACnC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;oBAChD,IAAI,OAAO,EAAE,CAAC;wBACZ,MAAM,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAW,CAAC,CAAC,2BAA2B;wBAClE,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI;4BACJ,OAAO,EAAE,IAAI,QAAQ,6JAA6J;yBACnL,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;YACH,CAAC;YACD,eAAe,CAAC,IAAI;gBAClB,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;oBAC3B,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;oBACpD,IAAI,OAAO,EAAE,CAAC;wBACZ,MAAM,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAW,CAAC,CAAC,2BAA2B;wBAClE,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI,EAAE,IAAI;4BACV,OAAO,EAAE,IAAI,QAAQ,6JAA6J;yBACnL,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC,CAAC,CAAC;YACL,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["import type { Rule } from 'eslint';\n/**\n * Regular expression to match hex color values.\n * Added capturing group to extract the hex value.\n * Matches three to eight hex digits so that 8-digit ARGB values with an alpha\n * channel (e.g. `#4459ff1a`, used by the current design tokens) are caught as\n * well as 6-digit values.\n * Using 'u' flag for Unicode support.\n */\nconst hexColorRegex = /(#\\p{Hex_Digit}{3,8})\\b/u;\n\n/**\n * Rule to prevent the use of hex color values.\n */\nexport const colorNoHex: Rule.RuleModule = {\n meta: {\n type: 'problem',\n docs: {\n description: 'Prevent the use of hex color values.',\n recommended: true,\n url: 'https://github.com/MetaMask/metamask-design-system/blob/main/packages/eslint-plugin-design-tokens/docs/rules/color-no-hex.md',\n },\n schema: [], // This rule does not take any options\n },\n create(context) {\n return {\n Literal(node) {\n if (typeof node.value === 'string') {\n const matches = node.value.match(hexColorRegex);\n if (matches) {\n const hexValue = matches[1] as string; // Type assertion to string\n context.report({\n node,\n 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.`,\n });\n }\n }\n },\n TemplateLiteral(node) {\n node.quasis.forEach((part) => {\n const matches = part.value.raw.match(hexColorRegex);\n if (matches) {\n const hexValue = matches[1] as string; // Type assertion to string\n context.report({\n node: part,\n 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.`,\n });\n }\n });\n },\n };\n },\n};\n"]}
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.colorNoHex = exports.preferThemeColorClassnames = exports.noDeprecatedClassnames = void 0;
4
- var no_deprecated_classnames_1 = require("./no-deprecated-classnames");
4
+ var no_deprecated_classnames_1 = require("./no-deprecated-classnames.cjs");
5
5
  Object.defineProperty(exports, "noDeprecatedClassnames", { enumerable: true, get: function () { return no_deprecated_classnames_1.noDeprecatedClassnames; } });
6
- var prefer_theme_color_classnames_1 = require("./prefer-theme-color-classnames");
6
+ var prefer_theme_color_classnames_1 = require("./prefer-theme-color-classnames.cjs");
7
7
  Object.defineProperty(exports, "preferThemeColorClassnames", { enumerable: true, get: function () { return prefer_theme_color_classnames_1.preferThemeColorClassnames; } });
8
- var color_no_hex_1 = require("./color-no-hex");
8
+ var color_no_hex_1 = require("./color-no-hex.cjs");
9
9
  Object.defineProperty(exports, "colorNoHex", { enumerable: true, get: function () { return color_no_hex_1.colorNoHex; } });
10
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":";;;AAAA,2EAAoE;AAA3D,kIAAA,sBAAsB,OAAA;AAC/B,qFAA6E;AAApE,2IAAA,0BAA0B,OAAA;AACnC,mDAA4C;AAAnC,0GAAA,UAAU,OAAA","sourcesContent":["export { noDeprecatedClassnames } from './no-deprecated-classnames';\nexport { preferThemeColorClassnames } from './prefer-theme-color-classnames';\nexport { colorNoHex } from './color-no-hex';\n"]}
@@ -0,0 +1,4 @@
1
+ export { noDeprecatedClassnames } from "./no-deprecated-classnames.cjs";
2
+ export { preferThemeColorClassnames } from "./prefer-theme-color-classnames.cjs";
3
+ export { colorNoHex } from "./color-no-hex.cjs";
4
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","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"}