@hero-design/eslint-plugin 9.2.1 → 9.2.3-test-auto-workflow.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 +12 -0
- package/README.md +125 -15
- package/docs/rules/banning-snowflake-approve-comment.md +42 -0
- package/docs/rules/no-deprecated-component-prop-next.md +32 -0
- package/docs/rules/no-direct-color-palette-access.md +34 -0
- package/docs/rules/react-no-text-outside-typography.md +57 -0
- package/lib/rules/no-deprecated-component-prop-next.js +0 -1
- package/package.json +2 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @hero-design/eslint-plugin
|
|
2
2
|
|
|
3
|
+
## 9.2.3-test-auto-workflow.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#4880](https://github.com/Thinkei/hero-design/pull/4880) [`58e5d24cb3a296fee8b4192594656a08bf983ab5`](https://github.com/Thinkei/hero-design/commit/58e5d24cb3a296fee8b4192594656a08bf983ab5) Thanks [@tqdungit](https://github.com/tqdungit)! - Update `engines.node` to enforce Node.js 20/22 support. Published packages now require `^20.0.0 || ^22.0.0`, dropping support for Node 14/16/18 and older ranges. Internal packages are set to `^22.0.0`.
|
|
8
|
+
|
|
9
|
+
## 9.2.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#4770](https://github.com/Thinkei/hero-design/pull/4770) [`f41e0ff2a0a23e37c0be1203320dc2677f7e6af4`](https://github.com/Thinkei/hero-design/commit/f41e0ff2a0a23e37c0be1203320dc2677f7e6af4) Thanks [@tqdungit](https://github.com/tqdungit)! - Upgrade node 22
|
|
14
|
+
|
|
3
15
|
## 9.2.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,17 +1,31 @@
|
|
|
1
1
|
# @hero-design/eslint-plugin
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Hero Design's ESLint plugin that ensures correct usage and deprecation of Hero Design packages. The plugin is used across many repositories to enforce best practices, prevent deprecated API usage, and maintain consistency across projects using `@hero-design/rn`, `@hero-design/react`, and `@hero-design/colors`.
|
|
6
|
+
|
|
7
|
+
**Key features:**
|
|
8
|
+
- Enforces proper component prop usage and prevents deprecated APIs
|
|
9
|
+
- Prevents direct color palette access in favor of semantic tokens
|
|
10
|
+
- Ensures text content is properly wrapped in Typography components
|
|
11
|
+
- Blocks not recommended imports with helpful migration messages
|
|
12
|
+
- Provides pre-configured rule sets for React Native and React web projects
|
|
13
|
+
|
|
14
|
+
We **strongly recommend** all consumers to use this plugin with our predefined `recommendedRn` or `recommendedReact` configs.
|
|
5
15
|
|
|
6
16
|
## Installation
|
|
7
17
|
|
|
8
|
-
|
|
18
|
+
**Prerequisites:**
|
|
19
|
+
- Node.js >= 14.17.0 (or >= 20.0.0 recommended)
|
|
20
|
+
- ESLint >= 7.0.0
|
|
21
|
+
|
|
22
|
+
Install ESLint (if not already installed):
|
|
9
23
|
|
|
10
24
|
```sh
|
|
11
25
|
yarn add -D eslint
|
|
12
26
|
```
|
|
13
27
|
|
|
14
|
-
|
|
28
|
+
Install `@hero-design/eslint-plugin`:
|
|
15
29
|
|
|
16
30
|
```sh
|
|
17
31
|
yarn add -D @hero-design/eslint-plugin
|
|
@@ -19,7 +33,7 @@ yarn add -D @hero-design/eslint-plugin
|
|
|
19
33
|
|
|
20
34
|
## Usage
|
|
21
35
|
|
|
22
|
-
Add `@hero-design` to the plugins section of your `.eslintrc`
|
|
36
|
+
Add `@hero-design` to the plugins section of your ESLint configuration (`.eslintrc`). You can omit the `eslint-plugin` postfix:
|
|
23
37
|
|
|
24
38
|
```json
|
|
25
39
|
{
|
|
@@ -27,9 +41,11 @@ Add `@hero-design` to the plugins section of your `.eslintrc` configuration file
|
|
|
27
41
|
}
|
|
28
42
|
```
|
|
29
43
|
|
|
30
|
-
|
|
44
|
+
### Recommended Configurations
|
|
45
|
+
|
|
46
|
+
#### For React Native Projects
|
|
31
47
|
|
|
32
|
-
|
|
48
|
+
Use the `recommendedRn` config, which includes rules for deprecated props, theme keys, and not recommended imports:
|
|
33
49
|
|
|
34
50
|
```json
|
|
35
51
|
{
|
|
@@ -37,21 +53,115 @@ Then, you can either:
|
|
|
37
53
|
}
|
|
38
54
|
```
|
|
39
55
|
|
|
40
|
-
|
|
56
|
+
#### For React Web Projects
|
|
57
|
+
|
|
58
|
+
Use the `recommendedReact` config, which includes rules for color palette access and typography:
|
|
59
|
+
|
|
60
|
+
```json
|
|
61
|
+
{
|
|
62
|
+
"extends": ["plugin:@hero-design/recommendedReact"]
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
#### For Internal Teams (Next Version Migration)
|
|
67
|
+
|
|
68
|
+
Use the `internalRn` config to prepare for upcoming breaking changes:
|
|
69
|
+
|
|
70
|
+
```json
|
|
71
|
+
{
|
|
72
|
+
"extends": ["plugin:@hero-design/internalRn"]
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Manual Rule Configuration
|
|
77
|
+
|
|
78
|
+
You can also configure individual rules manually, though this approach should be avoided unless you have specific needs:
|
|
41
79
|
|
|
42
80
|
```json
|
|
43
81
|
{
|
|
44
82
|
"rules": {
|
|
45
|
-
"@hero-design/
|
|
83
|
+
"@hero-design/no-deprecated-component-prop": "error",
|
|
84
|
+
"@hero-design/no-direct-color-palette-access": "warn"
|
|
46
85
|
}
|
|
47
86
|
}
|
|
48
87
|
```
|
|
49
88
|
|
|
89
|
+
## Examples
|
|
90
|
+
|
|
91
|
+
### Basic Setup
|
|
92
|
+
|
|
93
|
+
```json
|
|
94
|
+
// .eslintrc.json
|
|
95
|
+
{
|
|
96
|
+
"extends": [
|
|
97
|
+
"eslint:recommended",
|
|
98
|
+
"plugin:@hero-design/recommendedRn"
|
|
99
|
+
],
|
|
100
|
+
"plugins": ["@hero-design"]
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### React Native Component Usage
|
|
105
|
+
|
|
106
|
+
The plugin will catch deprecated props and suggest alternatives:
|
|
107
|
+
|
|
108
|
+
```jsx
|
|
109
|
+
// ❌ Incorrect - will be flagged
|
|
110
|
+
import { Card } from '@hero-design/rn';
|
|
111
|
+
<Card variant="outlined" />
|
|
112
|
+
|
|
113
|
+
// ✅ Correct
|
|
114
|
+
<Card appearance="outlined" />
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Color Usage
|
|
118
|
+
|
|
119
|
+
```jsx
|
|
120
|
+
// ❌ Incorrect - direct palette access
|
|
121
|
+
const color = theme.colors.palette.redLight30;
|
|
122
|
+
|
|
123
|
+
// ✅ Correct - semantic color tokens
|
|
124
|
+
const color = theme.colors.text.primary;
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Typography Usage (React Web)
|
|
128
|
+
|
|
129
|
+
```jsx
|
|
130
|
+
// ❌ Incorrect - raw HTML text elements
|
|
131
|
+
<div>
|
|
132
|
+
<p>Some text</p>
|
|
133
|
+
</div>
|
|
134
|
+
|
|
135
|
+
// ✅ Correct - Typography component
|
|
136
|
+
<div>
|
|
137
|
+
<Typography tagName="p">Some text</Typography>
|
|
138
|
+
</div>
|
|
139
|
+
```
|
|
140
|
+
|
|
50
141
|
## Supported Rules
|
|
51
142
|
|
|
52
|
-
| Rule
|
|
53
|
-
|
|
54
|
-
|
|
|
55
|
-
|
|
|
56
|
-
|
|
|
57
|
-
|
|
|
143
|
+
| Rule | Description | Config |
|
|
144
|
+
|------|-------------|--------|
|
|
145
|
+
| `@hero-design/banning-snowflake-approve-comment` | Disallow Snowflake Guard approval comments | - |
|
|
146
|
+
| `@hero-design/no-deprecated-component-prop` | Disallow deprecated component props | - |
|
|
147
|
+
| `@hero-design/no-deprecated-component-prop-next` | Disallow props deprecated in next version | `internalRn` |
|
|
148
|
+
| `@hero-design/no-deprecated-component-prop-value` | Disallow deprecated component prop values | - |
|
|
149
|
+
| `@hero-design/no-deprecated-theme-key` | Disallow deprecated theme keys | - |
|
|
150
|
+
| `@hero-design/no-direct-color-palette-access` | Disallow direct color palette access | `recommendedReact` |
|
|
151
|
+
| `@hero-design/not-recommended-import` | Disallow not recommended imports | `recommendedRn` |
|
|
152
|
+
| `@hero-design/react-no-text-outside-typography` | Require text inside Typography component | `recommendedReact` |
|
|
153
|
+
|
|
154
|
+
For detailed documentation on each rule, see the [docs/rules](./docs/rules/) directory.
|
|
155
|
+
|
|
156
|
+
## Contributing
|
|
157
|
+
|
|
158
|
+
To contribute to this plugin:
|
|
159
|
+
|
|
160
|
+
1. **Add a new rule**: Create a new rule file in `lib/rules/` following the existing pattern
|
|
161
|
+
2. **Add tests**: Create corresponding test files in `tests/lib/rules/`
|
|
162
|
+
3. **Add documentation**: Create a markdown file in `docs/rules/` explaining the rule
|
|
163
|
+
4. **Update configs**: Add the rule to appropriate configs in `lib/index.js`
|
|
164
|
+
5. **Run tests**: Execute `yarn test` to ensure all tests pass
|
|
165
|
+
6. **Run linter**: Execute `yarn lint` to check code quality
|
|
166
|
+
|
|
167
|
+
See the existing rules for examples of the expected structure and patterns.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Disallow snowflake-guard comments (banning-snowflake-approve-comment)
|
|
2
|
+
|
|
3
|
+
## Rule Details
|
|
4
|
+
|
|
5
|
+
This rule disallows the use of comments that include `@snowflake-guard/` references. These comments are used for Snowflake Guard approval workflows and should not be committed to the codebase.
|
|
6
|
+
|
|
7
|
+
Examples of **incorrect** code for this rule:
|
|
8
|
+
|
|
9
|
+
```jsx
|
|
10
|
+
// @snowflake-guard/approve
|
|
11
|
+
const Component = () => {
|
|
12
|
+
return <div>Content</div>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/* @snowflake-guard/review */
|
|
16
|
+
function fetchUserData() {
|
|
17
|
+
return api.get('/users');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// @snowflake-guard/custom-pattern
|
|
21
|
+
const config = { apiKey: process.env.API_KEY };
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Examples of **correct** code for this rule:
|
|
25
|
+
|
|
26
|
+
```jsx
|
|
27
|
+
// Regular comment
|
|
28
|
+
const Component = () => {
|
|
29
|
+
return <div>Content</div>;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
function fetchUserData() {
|
|
33
|
+
return api.get('/users');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const config = { apiKey: process.env.API_KEY };
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## When To Use It
|
|
40
|
+
|
|
41
|
+
Use this rule to prevent Snowflake Guard approval comments from being committed to the repository. If you need Snowflake Guard approval, please contact the Andromeda team directly.
|
|
42
|
+
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Disallow deprecated component props for next version (no-deprecated-component-prop-next)
|
|
2
|
+
|
|
3
|
+
## Rule Details
|
|
4
|
+
|
|
5
|
+
This rule is an alias for `no-deprecated-component-prop` and is used to flag component props that will be deprecated in the next major version. It helps teams prepare for upcoming breaking changes by warning about props that should be migrated.
|
|
6
|
+
|
|
7
|
+
Examples of **incorrect** code for this rule:
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
<Tag variant="primary" />
|
|
11
|
+
<FAB.ActionGroup headerTitle="Actions" />
|
|
12
|
+
<Checkbox withBorder />
|
|
13
|
+
<SectionHeading fontSize={16} fontWeight="bold" />
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Examples of **correct** code for this rule:
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
<Tag appearance="primary" />
|
|
20
|
+
<FAB.ActionGroup title="Actions" />
|
|
21
|
+
<Checkbox />
|
|
22
|
+
<SectionHeading />
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Options
|
|
26
|
+
|
|
27
|
+
This rule receives the same options as `no-deprecated-component-prop`. See the [no-deprecated-component-prop documentation](./no-deprecated-component-prop.md) for details.
|
|
28
|
+
|
|
29
|
+
## When To Use It
|
|
30
|
+
|
|
31
|
+
Use this rule when you want to prepare for upcoming breaking changes in the next major version. This rule is typically enabled in the `internalRn` config to help internal teams migrate before the public release.
|
|
32
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Disallow direct color palette access (no-direct-color-palette-access)
|
|
2
|
+
|
|
3
|
+
## Rule Details
|
|
4
|
+
|
|
5
|
+
This rule disallows direct access to color palette values (e.g., `theme.colors.palette.redLight30` or `colors.palette.blueDark50`). Instead, you should use semantic color tokens from the theme.
|
|
6
|
+
|
|
7
|
+
Examples of **incorrect** code for this rule:
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
const StyledComponent = styled.div`
|
|
11
|
+
color: ${({ theme }) => theme.colors.palette.redLight30};
|
|
12
|
+
background-color: ${({ theme }) => theme.colors.palette.blueDark50};
|
|
13
|
+
`;
|
|
14
|
+
|
|
15
|
+
// Or with direct colors import
|
|
16
|
+
const color = colors.palette.greenLight20;
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Examples of **correct** code for this rule:
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
const StyledComponent = styled.div`
|
|
23
|
+
color: ${({ theme }) => theme.colors.text.primary};
|
|
24
|
+
background-color: ${({ theme }) => theme.colors.background.secondary};
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
// Use semantic colors from theme
|
|
28
|
+
const color = theme.colors.brand.primary;
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## When To Use It
|
|
32
|
+
|
|
33
|
+
Use this rule to enforce the use of semantic color tokens instead of direct palette access. This ensures consistent theming and makes it easier to maintain design system colors across different themes and products.
|
|
34
|
+
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Require text inside Typography component (react-no-text-outside-typography)
|
|
2
|
+
|
|
3
|
+
## Rule Details
|
|
4
|
+
|
|
5
|
+
This rule recommends using text content inside Typography components from `@hero-design/react` instead of raw HTML text elements like `<p>`, `<span>`, `<div>`, etc.
|
|
6
|
+
|
|
7
|
+
Examples of **incorrect** code for this rule:
|
|
8
|
+
|
|
9
|
+
```jsx
|
|
10
|
+
<div>
|
|
11
|
+
<p>Some text content</p>
|
|
12
|
+
<span>More text</span>
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
<div>
|
|
16
|
+
<Typography tagName="div">
|
|
17
|
+
<div>Nested text</div>
|
|
18
|
+
</Typography>
|
|
19
|
+
</div>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Examples of **correct** code for this rule:
|
|
23
|
+
|
|
24
|
+
```jsx
|
|
25
|
+
<div>
|
|
26
|
+
<Typography tagName="p">Some text content</Typography>
|
|
27
|
+
<Typography tagName="span">More text</Typography>
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
<Typography tagName="div">
|
|
31
|
+
<ul>
|
|
32
|
+
<li>List item</li>
|
|
33
|
+
</ul>
|
|
34
|
+
</Typography>
|
|
35
|
+
|
|
36
|
+
<Typography tagName="p">
|
|
37
|
+
<Typography tagName="span">Nested text</Typography>
|
|
38
|
+
</Typography>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Allowed Cases
|
|
42
|
+
|
|
43
|
+
The rule allows certain nested structures:
|
|
44
|
+
|
|
45
|
+
- Text inside `<Typography tagName="p">` or `<Typography tagName="span">` can be nested up to 1 level
|
|
46
|
+
- Text inside `<Typography tagName="div">` can be nested up to 2 levels when:
|
|
47
|
+
- Inside an unordered list (`<ul><li>`)
|
|
48
|
+
- Inside a paragraph (`<p>`)
|
|
49
|
+
|
|
50
|
+
### Special Handling
|
|
51
|
+
|
|
52
|
+
The rule also checks for `Intl.formatMessage` calls and ensures they are properly wrapped in Typography components.
|
|
53
|
+
|
|
54
|
+
## When To Use It
|
|
55
|
+
|
|
56
|
+
Use this rule to ensure consistent typography styling across your React application and to maintain design system standards for text rendering.
|
|
57
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hero-design/eslint-plugin",
|
|
3
|
-
"version": "9.2.
|
|
3
|
+
"version": "9.2.3-test-auto-workflow.0",
|
|
4
4
|
"description": "Hero Design's eslint plugin",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
"requireindex": "^1.2.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@eslint/compat": "^1.1.1",
|
|
26
25
|
"@eslint/eslintrc": "^3.1.0",
|
|
27
26
|
"@eslint/js": "^9.8.0",
|
|
28
27
|
"eslint": "^8.56.0",
|
|
@@ -32,7 +31,7 @@
|
|
|
32
31
|
"prettier-config-hd": "8.42.4"
|
|
33
32
|
},
|
|
34
33
|
"engines": {
|
|
35
|
-
"node": "^
|
|
34
|
+
"node": "^20.0.0 || ^22.0.0"
|
|
36
35
|
},
|
|
37
36
|
"peerDependencies": {
|
|
38
37
|
"eslint": ">=7"
|