@metamask/eslint-plugin-design-tokens 0.1.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 ADDED
@@ -0,0 +1,17 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.0]
11
+
12
+ ### Changed
13
+
14
+ - Initial release
15
+
16
+ [Unreleased]: https://github.com/MetaMask/eslint-plugin-design-tokens/compare/v0.1.0...HEAD
17
+ [0.1.0]: https://github.com/MetaMask/eslint-plugin-design-tokens/releases/tag/v0.1.0
package/README.md ADDED
@@ -0,0 +1,118 @@
1
+ # ESlint Plugin Design Tokens 🪙✨
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! 💁
10
+
11
+ ## Installation
12
+
13
+ You'll first need to install [ESLint](https://eslint.org):
14
+
15
+ ```shell
16
+ $ npm install --save-dev eslint
17
+ # or
18
+ $ yarn add --dev eslint
19
+ ```
20
+
21
+ Next, install `@metamask/eslint-plugin-design-tokens`:
22
+
23
+ ```shell
24
+ $ npm install --save-dev @metamask/eslint-plugin-design-tokens
25
+ # or
26
+ $ yarn add --dev @metamask/eslint-plugin-design-tokens
27
+ ```
28
+
29
+ **Note:** If you installed ESLint globally (using the `-g` flag) then you must also install `@metamask/eslint-plugin-design-tokens` globally.
30
+
31
+ ## Usage
32
+
33
+ Add `@metamask/design-tokens` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:
34
+
35
+ ```json
36
+ {
37
+ "plugins": ["@metamask/design-tokens"]
38
+ }
39
+ ```
40
+
41
+ Then configure the rules you want to use within `rules` property of your `.eslintrc`:
42
+
43
+ ```json
44
+ {
45
+ "rules": {
46
+ "@metamask/design-tokens/no-deprecated-classnames": [
47
+ "warn",
48
+ {
49
+ "bg-white": "Use 'bg-default' to align with the design system's color tokens.",
50
+ "bg-surface-default": "Use 'bg-default' to align with the design system's color tokens.",
51
+ "text-red-500": "Use 'text-error-default' to align with the design system's color tokens.",
52
+ "text-critical": "Use 'text-error-default' to align with the design system's color tokens."
53
+ }
54
+ ]
55
+ }
56
+ }
57
+ ```
58
+
59
+ ## Supported Rules
60
+
61
+ > Remember that all rules from this plugin are prefixed by `"@metamask/design-tokens/"`
62
+
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
+
67
+ ## Contributing
68
+
69
+ ### Setup
70
+
71
+ - Install the current LTS version of [Node.js](https://nodejs.org)
72
+ - 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.
73
+ - Install [Yarn v3](https://yarnpkg.com/getting-started/install)
74
+ - Run `yarn install` to install dependencies and run any required post-install scripts
75
+
76
+ ### Testing and Linting
77
+
78
+ Run `yarn test` to run the tests once. To run tests on file changes, run `yarn test:watch`.
79
+
80
+ Run `yarn lint` to run the linter, or run `yarn lint:fix` to run the linter and fix any automatically fixable issues.
81
+
82
+ ### Release & Publishing
83
+
84
+ 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.
85
+
86
+ 1. Choose a release version.
87
+
88
+ - 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.
89
+
90
+ 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).
91
+
92
+ - 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.
93
+
94
+ 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.
95
+
96
+ - 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).
97
+ - This should trigger the [`action-create-release-pr`](https://github.com/MetaMask/action-create-release-pr) workflow to create the release PR.
98
+
99
+ 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.
100
+
101
+ - 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.).
102
+ - Try to explain each change in terms that users of the package would understand (e.g. avoid referencing internal variables/concepts).
103
+ - Consolidate related changes into one change entry if it makes it easier to explain.
104
+ - Run `yarn auto-changelog validate --rc` to check that the changelog is correctly formatted.
105
+
106
+ 5. Review and QA the release.
107
+
108
+ - 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.
109
+
110
+ 6. Squash & Merge the release.
111
+
112
+ - 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.
113
+
114
+ 7. Publish the release on npm.
115
+
116
+ - 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.
117
+ - Approve the `publish-npm` job (or ask somebody on the npm publishers team to approve it for you).
118
+ - Once the `publish-npm` job has finished, check npm to verify that it has been published.
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rules = void 0;
4
+ const rules_1 = require("./rules");
5
+ exports.rules = {
6
+ 'no-deprecated-classnames': rules_1.noDeprecatedClassnames,
7
+ };
package/dist/index.mjs ADDED
@@ -0,0 +1,60 @@
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?tab=readme-ov-file#eslint-plugin-design-tokens-"
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/index.ts
55
+ var rules = {
56
+ "no-deprecated-classnames": noDeprecatedClassnames
57
+ };
58
+ export {
59
+ rules
60
+ };
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.noDeprecatedClassnames = void 0;
4
+ var no_deprecated_classnames_1 = require("./no-deprecated-classnames");
5
+ Object.defineProperty(exports, "noDeprecatedClassnames", { enumerable: true, get: function () { return no_deprecated_classnames_1.noDeprecatedClassnames; } });
@@ -0,0 +1,55 @@
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?tab=readme-ov-file#eslint-plugin-design-tokens-"
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
+ export {
54
+ noDeprecatedClassnames
55
+ };
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.noDeprecatedClassnames = void 0;
4
+ /**
5
+ * The main rule module for detecting deprecated TailwindCSS class names.
6
+ * This ESLint rule checks for the usage of deprecated TailwindCSS class names
7
+ * and suggests updated alternatives based on a configurable list.
8
+ */
9
+ exports.noDeprecatedClassnames = {
10
+ meta: {
11
+ type: 'suggestion',
12
+ docs: {
13
+ description: 'No deprecated classnames allowed',
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?tab=readme-ov-file#eslint-plugin-design-tokens-',
17
+ },
18
+ // Define the schema to accept an object of deprecated classnames
19
+ schema: [
20
+ {
21
+ type: 'object',
22
+ additionalProperties: {
23
+ type: 'string',
24
+ },
25
+ },
26
+ ],
27
+ },
28
+ /**
29
+ * The `create` method that gets executed by ESLint when linting files.
30
+ * It checks for deprecated classnames and reports them.
31
+ *
32
+ * @param context - The ESLint rule context providing interfaces to report node information.
33
+ * @returns An object with methods targeting specific nodes in the AST.
34
+ */
35
+ create(context) {
36
+ // Access the first option as the deprecatedClassnames object
37
+ const deprecatedClassnames = context.options[0] || {};
38
+ return {
39
+ /**
40
+ * Listener for Literal nodes in the AST. It splits class names in string literals
41
+ * and checks each against the list of deprecated class names.
42
+ *
43
+ * @param node - The AST node being visited.
44
+ */
45
+ Literal(node) {
46
+ if (typeof node.value === 'string') {
47
+ const classNames = node.value.split(' ');
48
+ classNames.forEach((className) => {
49
+ if (Object.keys(deprecatedClassnames).includes(className)) {
50
+ // Report the deprecated class name usage with a suggestion message.
51
+ context.report({
52
+ node,
53
+ message: `${className} is a deprecated TailwindCSS class. ${deprecatedClassnames[className] ?? 'No alternative available.'}`,
54
+ });
55
+ }
56
+ });
57
+ }
58
+ },
59
+ };
60
+ },
61
+ };
@@ -0,0 +1,55 @@
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?tab=readme-ov-file#eslint-plugin-design-tokens-"
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
+ export {
54
+ noDeprecatedClassnames
55
+ };
package/package.json ADDED
@@ -0,0 +1,87 @@
1
+ {
2
+ "name": "@metamask/eslint-plugin-design-tokens",
3
+ "version": "0.1.0",
4
+ "description": "An ESLint plugin designed to enforce best practices and consistency for using MetaMask design tokens across various projects",
5
+ "homepage": "https://github.com/MetaMask/eslint-plugin-design-tokens#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/MetaMask/eslint-plugin-design-tokens/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/MetaMask/eslint-plugin-design-tokens.git"
12
+ },
13
+ "sideEffects": false,
14
+ "exports": {
15
+ ".": {
16
+ "import": "./dist/index.mjs",
17
+ "require": "./dist/index.js",
18
+ "types": "./dist/types/index.d.ts"
19
+ },
20
+ "./package.json": "./package.json"
21
+ },
22
+ "main": "./dist/index.js",
23
+ "module": "./dist/index.mjs",
24
+ "types": "./dist/types/index.d.ts",
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "scripts": {
29
+ "build": "tsup --clean && yarn build:types",
30
+ "build:types": "tsc --project tsconfig.build.json",
31
+ "lint": "yarn lint:eslint && yarn lint:constraints && yarn lint:misc --check && yarn lint:dependencies --check && yarn lint:changelog",
32
+ "lint:changelog": "auto-changelog validate --prettier",
33
+ "lint:constraints": "yarn constraints",
34
+ "lint:dependencies": "depcheck && yarn dedupe",
35
+ "lint:eslint": "eslint . --cache --ext js,ts",
36
+ "lint:fix": "yarn lint:eslint --fix && yarn lint:constraints --fix && yarn lint:misc --write && yarn lint:dependencies && yarn lint:changelog",
37
+ "lint:misc": "prettier '**/*.json' '**/*.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore --no-error-on-unmatched-pattern",
38
+ "prepack": "./scripts/prepack.sh",
39
+ "test": "jest && jest-it-up",
40
+ "test:watch": "jest --watch"
41
+ },
42
+ "devDependencies": {
43
+ "@lavamoat/allow-scripts": "^3.0.0",
44
+ "@lavamoat/preinstall-always-fail": "^2.0.0",
45
+ "@metamask/auto-changelog": "^3.4.3",
46
+ "@metamask/eslint-config": "^12.2.0",
47
+ "@metamask/eslint-config-jest": "^12.1.0",
48
+ "@metamask/eslint-config-nodejs": "^12.1.0",
49
+ "@metamask/eslint-config-typescript": "^12.1.0",
50
+ "@types/eslint": "^8.56.5",
51
+ "@types/jest": "^28.1.6",
52
+ "@types/node": "^16",
53
+ "@typescript-eslint/eslint-plugin": "^5.43.0",
54
+ "@typescript-eslint/parser": "^5.43.0",
55
+ "depcheck": "^1.4.3",
56
+ "eslint": "^8.57.0",
57
+ "eslint-config-prettier": "^8.8.0",
58
+ "eslint-plugin-import": "~2.26.0",
59
+ "eslint-plugin-jest": "^27.2.2",
60
+ "eslint-plugin-jsdoc": "^39.9.1",
61
+ "eslint-plugin-n": "^15.7.0",
62
+ "eslint-plugin-prettier": "^4.2.1",
63
+ "eslint-plugin-promise": "^6.1.1",
64
+ "jest": "^28.1.3",
65
+ "jest-it-up": "^2.0.2",
66
+ "prettier": "^2.7.1",
67
+ "prettier-plugin-packagejson": "^2.3.0",
68
+ "ts-jest": "^28.0.7",
69
+ "ts-node": "^10.7.0",
70
+ "tsup": "^7.2.0",
71
+ "typescript": "~4.8.4"
72
+ },
73
+ "packageManager": "yarn@3.2.1",
74
+ "engines": {
75
+ "node": "^18.18 || >=20"
76
+ },
77
+ "publishConfig": {
78
+ "access": "public",
79
+ "registry": "https://registry.npmjs.org/"
80
+ },
81
+ "lavamoat": {
82
+ "allowScripts": {
83
+ "@lavamoat/preinstall-always-fail": false,
84
+ "tsup>esbuild": true
85
+ }
86
+ }
87
+ }