eslint-plugin-primer-react 4.0.3 → 4.0.4
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/.changeset/README.md +3 -3
- package/.eslintrc.js +39 -0
- package/.github/dependabot.yml +11 -5
- package/.github/workflows/add-to-inbox.yml +33 -0
- package/.github/workflows/ci.yml +34 -18
- package/.github/workflows/release.yml +2 -2
- package/.github/workflows/release_canary.yml +8 -5
- package/.github/workflows/release_candidate.yml +4 -4
- package/.markdownlint-cli2.cjs +26 -0
- package/.nvmrc +1 -0
- package/.prettierignore +3 -0
- package/CHANGELOG.md +7 -1
- package/README.md +4 -2
- package/docs/rules/a11y-explicit-heading.md +17 -7
- package/docs/rules/a11y-tooltip-interactive-trigger.md +6 -2
- package/docs/rules/direct-slot-children.md +49 -46
- package/docs/rules/new-color-css-vars-have-fallback.md +25 -0
- package/docs/rules/new-css-color-vars.md +19 -14
- package/docs/rules/no-deprecated-colors.md +91 -82
- package/docs/rules/no-system-props.md +12 -5
- package/package.json +22 -14
- package/src/configs/components.js +19 -19
- package/src/configs/recommended.js +9 -8
- package/src/index.js +4 -3
- package/src/rules/__tests__/a11y-explicit-heading.test.js +22 -25
- package/src/rules/__tests__/a11y-tooltip-interactive-trigger.test.js +43 -43
- package/src/rules/__tests__/direct-slot-children.test.js +36 -36
- package/src/rules/__tests__/new-color-css-vars.test.js +612 -44
- package/src/rules/__tests__/new-css-vars-have-fallback.test.js +31 -0
- package/src/rules/__tests__/no-deprecated-colors.test.js +66 -66
- package/src/rules/__tests__/no-system-props.test.js +51 -51
- package/src/rules/a11y-explicit-heading.js +16 -13
- package/src/rules/a11y-tooltip-interactive-trigger.js +21 -22
- package/src/rules/direct-slot-children.js +11 -11
- package/src/rules/new-color-css-vars-have-fallback.js +87 -0
- package/src/rules/new-color-css-vars.js +97 -83
- package/src/rules/no-deprecated-colors.js +15 -15
- package/src/rules/no-system-props.js +21 -21
- package/src/url.js +1 -1
- package/src/utils/__tests__/flatten-components.test.js +13 -13
- package/src/utils/css-variable-map.json +538 -184
- package/src/utils/flatten-components.js +11 -11
- package/src/utils/is-imported-from.js +1 -1
- package/src/utils/new-color-css-vars-map.json +326 -0
- /package/.github/{workflows/CODEOWNERS → CODEOWNERS} +0 -0
package/.changeset/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# Changesets
|
|
2
2
|
|
|
3
|
-
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works with
|
|
4
|
+
multi-package repos, or single-package repos to help you version and publish your code. You can find the full
|
|
5
|
+
documentation for it [in our repository](https://github.com/changesets/changesets)
|
|
6
6
|
|
|
7
7
|
We have a quick list of common questions to get you started engaging with this project in
|
|
8
8
|
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
|
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @type {import('eslint').Linter.Config}
|
|
5
|
+
*/
|
|
6
|
+
module.exports = {
|
|
7
|
+
extends: ['eslint:recommended', 'plugin:github/recommended'],
|
|
8
|
+
parserOptions: {
|
|
9
|
+
ecmaVersion: 'latest',
|
|
10
|
+
},
|
|
11
|
+
env: {
|
|
12
|
+
commonjs: true,
|
|
13
|
+
node: true,
|
|
14
|
+
},
|
|
15
|
+
rules: {
|
|
16
|
+
'import/no-commonjs': 'off',
|
|
17
|
+
'no-shadow': 'off',
|
|
18
|
+
'no-unused-vars': [
|
|
19
|
+
'error',
|
|
20
|
+
{
|
|
21
|
+
varsIgnorePattern: '^_',
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
overrides: [
|
|
26
|
+
{
|
|
27
|
+
files: ['**/*.test.js'],
|
|
28
|
+
env: {
|
|
29
|
+
jest: true,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
files: ['.eslintrc.js'],
|
|
34
|
+
rules: {
|
|
35
|
+
'filenames/match-regex': 'off',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
}
|
package/.github/dependabot.yml
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
version: 2
|
|
2
2
|
updates:
|
|
3
|
+
- package-ecosystem: 'github-actions'
|
|
4
|
+
directory: '/'
|
|
5
|
+
schedule:
|
|
6
|
+
interval: 'weekly'
|
|
7
|
+
labels:
|
|
8
|
+
- 'dependencies'
|
|
9
|
+
- 'skip changeset'
|
|
3
10
|
- package-ecosystem: npm
|
|
4
|
-
directory:
|
|
11
|
+
directory: '/'
|
|
5
12
|
schedule:
|
|
6
13
|
interval: weekly
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
-
|
|
10
|
-
- dependency-name: "eslint-plugin-jsx-a11y"
|
|
14
|
+
labels:
|
|
15
|
+
- 'dependencies'
|
|
16
|
+
- 'skip changeset'
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
name: Add to Inbox 📥
|
|
2
|
+
on:
|
|
3
|
+
issues:
|
|
4
|
+
types: [opened, reopened]
|
|
5
|
+
|
|
6
|
+
jobs:
|
|
7
|
+
add-to-inbox:
|
|
8
|
+
if: ${{ github.repository == 'primer/eslint-plugin-primer-react' }}
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
env:
|
|
11
|
+
ISSUE_URL: ${{ github.event.issue.html_url }}
|
|
12
|
+
PROJECT_ID: 4503
|
|
13
|
+
steps:
|
|
14
|
+
- id: get-primer-access-token
|
|
15
|
+
uses: actions/create-github-app-token@v1
|
|
16
|
+
with:
|
|
17
|
+
app-id: ${{ vars.PRIMER_ISSUE_TRIAGE_APP_ID }}
|
|
18
|
+
private-key: ${{ secrets.PRIMER_ISSUE_TRIAGE_APP_PRIVATE_KEY }}
|
|
19
|
+
- name: Add react label to issue
|
|
20
|
+
run: |
|
|
21
|
+
gh issue edit $ISSUE_URL --add-label react
|
|
22
|
+
env:
|
|
23
|
+
GH_TOKEN: ${{ steps.get-primer-access-token.outputs.token }}
|
|
24
|
+
- id: get-github-access-token
|
|
25
|
+
uses: actions/create-github-app-token@v1
|
|
26
|
+
with:
|
|
27
|
+
app-id: ${{ vars.PRIMER_ISSUE_TRIAGE_APP_ID_FOR_GITHUB }}
|
|
28
|
+
private-key: ${{ secrets.PRIMER_ISSUE_TRIAGE_APP_PRIVATE_KEY_FOR_GITHUB }}
|
|
29
|
+
owner: github
|
|
30
|
+
- name: Add issue to project
|
|
31
|
+
run: gh project item-add $PROJECT_ID --url $ISSUE_URL --owner github
|
|
32
|
+
env:
|
|
33
|
+
GH_TOKEN: ${{ steps.get-github-access-token.outputs.token }}
|
package/.github/workflows/ci.yml
CHANGED
|
@@ -1,28 +1,44 @@
|
|
|
1
1
|
name: CI
|
|
2
|
-
|
|
3
2
|
on:
|
|
4
3
|
push:
|
|
5
|
-
branches: [
|
|
4
|
+
branches: [main]
|
|
6
5
|
pull_request:
|
|
7
|
-
branches: [
|
|
6
|
+
branches: [main]
|
|
8
7
|
|
|
9
8
|
jobs:
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
format:
|
|
12
10
|
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
- name: Use Node.js
|
|
14
|
+
uses: actions/setup-node@v4
|
|
15
|
+
with:
|
|
16
|
+
node-version: 18
|
|
17
|
+
cache: 'npm'
|
|
18
|
+
- run: npm ci
|
|
19
|
+
- run: npm run format:check
|
|
13
20
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
21
|
+
test:
|
|
22
|
+
runs-on: ubuntu-latest
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v4
|
|
25
|
+
- name: Use Node.js
|
|
26
|
+
uses: actions/setup-node@v4
|
|
27
|
+
with:
|
|
28
|
+
node-version: 18
|
|
29
|
+
cache: 'npm'
|
|
30
|
+
- run: npm ci
|
|
31
|
+
- run: npm test
|
|
18
32
|
|
|
33
|
+
lint:
|
|
34
|
+
runs-on: ubuntu-latest
|
|
19
35
|
steps:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
36
|
+
- uses: actions/checkout@v4
|
|
37
|
+
- name: Use Node.js
|
|
38
|
+
uses: actions/setup-node@v4
|
|
39
|
+
with:
|
|
40
|
+
node-version: 18
|
|
41
|
+
cache: 'npm'
|
|
42
|
+
- run: npm ci
|
|
43
|
+
- run: npm run lint
|
|
44
|
+
- run: npm run lint:md
|
|
@@ -8,14 +8,14 @@ jobs:
|
|
|
8
8
|
runs-on: ubuntu-latest
|
|
9
9
|
steps:
|
|
10
10
|
- name: Checkout repository
|
|
11
|
-
uses: actions/checkout@
|
|
11
|
+
uses: actions/checkout@v4
|
|
12
12
|
with:
|
|
13
13
|
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
|
|
14
14
|
fetch-depth: 0
|
|
15
15
|
persist-credentials: false
|
|
16
16
|
|
|
17
17
|
- name: Set up Node.js
|
|
18
|
-
uses: actions/setup-node@
|
|
18
|
+
uses: actions/setup-node@v4
|
|
19
19
|
with:
|
|
20
20
|
node-version: 14
|
|
21
21
|
|
|
@@ -5,20 +5,23 @@ on:
|
|
|
5
5
|
- 'main'
|
|
6
6
|
- 'changeset-release/main'
|
|
7
7
|
|
|
8
|
+
concurrency:
|
|
9
|
+
group: npm-canary
|
|
10
|
+
cancel-in-progress: false
|
|
11
|
+
|
|
8
12
|
jobs:
|
|
9
13
|
release:
|
|
10
14
|
if: ${{ github.repository == 'primer/eslint-plugin-primer-react' }}
|
|
11
|
-
|
|
12
15
|
runs-on: ubuntu-latest
|
|
13
16
|
steps:
|
|
14
17
|
- name: Checkout repository
|
|
15
|
-
uses: actions/checkout@
|
|
18
|
+
uses: actions/checkout@v4
|
|
16
19
|
with:
|
|
17
20
|
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
|
|
18
21
|
fetch-depth: 0
|
|
19
22
|
|
|
20
23
|
- name: Set up Node.js
|
|
21
|
-
uses: actions/setup-node@
|
|
24
|
+
uses: actions/setup-node@v4
|
|
22
25
|
with:
|
|
23
26
|
node-version: 14.x
|
|
24
27
|
|
|
@@ -46,11 +49,11 @@ jobs:
|
|
|
46
49
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
47
50
|
|
|
48
51
|
- name: Output canary version number
|
|
49
|
-
uses: actions/github-script@
|
|
52
|
+
uses: actions/github-script@v6.4.1
|
|
50
53
|
with:
|
|
51
54
|
script: |
|
|
52
55
|
const package = require(`${process.env.GITHUB_WORKSPACE}/package.json`)
|
|
53
|
-
github.repos.createCommitStatus({
|
|
56
|
+
github.rest.repos.createCommitStatus({
|
|
54
57
|
owner: context.repo.owner,
|
|
55
58
|
repo: context.repo.repo,
|
|
56
59
|
sha: context.sha,
|
|
@@ -11,13 +11,13 @@ jobs:
|
|
|
11
11
|
runs-on: ubuntu-latest
|
|
12
12
|
steps:
|
|
13
13
|
- name: Checkout repository
|
|
14
|
-
uses: actions/checkout@
|
|
14
|
+
uses: actions/checkout@v4
|
|
15
15
|
with:
|
|
16
16
|
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
|
|
17
17
|
fetch-depth: 0
|
|
18
18
|
|
|
19
19
|
- name: Set up Node.js
|
|
20
|
-
uses: actions/setup-node@
|
|
20
|
+
uses: actions/setup-node@v4
|
|
21
21
|
with:
|
|
22
22
|
node-version: 14.x
|
|
23
23
|
|
|
@@ -44,11 +44,11 @@ jobs:
|
|
|
44
44
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
45
45
|
|
|
46
46
|
- name: Output release candidate version number
|
|
47
|
-
uses: actions/github-script@
|
|
47
|
+
uses: actions/github-script@v6.4.1
|
|
48
48
|
with:
|
|
49
49
|
script: |
|
|
50
50
|
const package = require(`${process.env.GITHUB_WORKSPACE}/package.json`)
|
|
51
|
-
github.repos.createCommitStatus({
|
|
51
|
+
github.rest.repos.createCommitStatus({
|
|
52
52
|
owner: context.repo.owner,
|
|
53
53
|
repo: context.repo.repo,
|
|
54
54
|
sha: context.sha,
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const githubMarkdownOpinions = require('@github/markdownlint-github')
|
|
4
|
+
|
|
5
|
+
const options = githubMarkdownOpinions.init({
|
|
6
|
+
// Rules we don't care to enforce (usually stylistic)
|
|
7
|
+
'line-length': false,
|
|
8
|
+
'blanks-around-headings': false,
|
|
9
|
+
'blanks-around-lists': false,
|
|
10
|
+
'no-trailing-spaces': false,
|
|
11
|
+
'no-multiple-blanks': false,
|
|
12
|
+
'no-trailing-punctuation': false,
|
|
13
|
+
'single-trailing-newline': false,
|
|
14
|
+
'ul-indent': false,
|
|
15
|
+
'ul-style': false,
|
|
16
|
+
'no-hard-tabs': false,
|
|
17
|
+
'first-line-heading': false,
|
|
18
|
+
'no-space-in-emphasis': false,
|
|
19
|
+
'blanks-around-fences': false
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
module.exports = {
|
|
23
|
+
config: options,
|
|
24
|
+
customRules: ['@github/markdownlint-github'],
|
|
25
|
+
outputFormatters: [['markdownlint-cli2-formatter-pretty', {appendLink: true}]]
|
|
26
|
+
}
|
package/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
v18
|
package/.prettierignore
ADDED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# eslint-plugin-primer-react
|
|
2
2
|
|
|
3
|
+
## 4.0.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#122](https://github.com/primer/eslint-plugin-primer-react/pull/122) [`3bc226a`](https://github.com/primer/eslint-plugin-primer-react/commit/3bc226ad0786f9a7a21ce92a63cbba17b8a5b763) Thanks [@lukasoppermann](https://github.com/lukasoppermann)! - New rule: new-color-css-vars-have-fallback: checks that if a new color var is used, it has a fallback value
|
|
8
|
+
|
|
3
9
|
## 4.0.3
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -151,7 +157,7 @@
|
|
|
151
157
|
function ExampleComponent() {
|
|
152
158
|
const styles = {
|
|
153
159
|
// Enabling `checkAllStrings` will find deprecated colors used like this:
|
|
154
|
-
color: 'text.primary'
|
|
160
|
+
color: 'text.primary',
|
|
155
161
|
}
|
|
156
162
|
return <Box sx={styles}>Hello</Box>
|
|
157
163
|
}
|
package/README.md
CHANGED
|
@@ -6,7 +6,8 @@ ESLint rules for Primer React
|
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
9
|
-
1. Assuming you already have [ESLint](https://www.npmjs.com/package/eslint) and
|
|
9
|
+
1. Assuming you already have [ESLint](https://www.npmjs.com/package/eslint) and
|
|
10
|
+
[Primer React](https://github.com/primer/react) installed, run:
|
|
10
11
|
|
|
11
12
|
```shell
|
|
12
13
|
npm install --save-dev eslint-plugin-primer-react
|
|
@@ -16,7 +17,8 @@ ESLint rules for Primer React
|
|
|
16
17
|
yarn add --dev eslint-plugin-primer-react
|
|
17
18
|
```
|
|
18
19
|
|
|
19
|
-
2. In your [ESLint configuration file](https://eslint.org/docs/user-guide/configuring/configuration-files), extend the
|
|
20
|
+
2. In your [ESLint configuration file](https://eslint.org/docs/user-guide/configuring/configuration-files), extend the
|
|
21
|
+
recommended Primer React ESLint config:
|
|
20
22
|
|
|
21
23
|
```js
|
|
22
24
|
{
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
## Require explicit heading level on `<Heading>` component
|
|
2
2
|
|
|
3
|
-
The `Heading` component does not require you to use `as` to specify the heading level, as it will default to an `h2` if
|
|
3
|
+
The `Heading` component does not require you to use `as` to specify the heading level, as it will default to an `h2` if
|
|
4
|
+
one isn't specified. This may lead to inaccessible usage if the default is out of order in the existing heading
|
|
5
|
+
hierarchy.
|
|
4
6
|
|
|
5
7
|
## Rule Details
|
|
6
8
|
|
|
7
|
-
This rule enforces using `as` on the `<Heading>` component to specify a heading level (`h1`-`h6`). In addition, it
|
|
9
|
+
This rule enforces using `as` on the `<Heading>` component to specify a heading level (`h1`-`h6`). In addition, it
|
|
10
|
+
enforces `as` usage to only be used for headings.
|
|
8
11
|
|
|
9
12
|
👎 Examples of **incorrect** code for this rule
|
|
10
13
|
|
|
11
14
|
```jsx
|
|
12
15
|
import {Heading} from '@primer/react'
|
|
13
16
|
|
|
14
|
-
|
|
17
|
+
function ExampleComponent() {
|
|
18
|
+
return <Heading>Heading without explicit heading level</Heading>
|
|
19
|
+
}
|
|
15
20
|
```
|
|
16
21
|
|
|
17
22
|
`as` must only be for headings (`h1`-`h6`)
|
|
@@ -19,19 +24,24 @@ import {Heading} from '@primer/react'
|
|
|
19
24
|
```jsx
|
|
20
25
|
import {Heading} from '@primer/react'
|
|
21
26
|
|
|
22
|
-
|
|
27
|
+
function ExampleComponent() {
|
|
28
|
+
return <Heading as="span">Heading component used as "span"</Heading>
|
|
29
|
+
}
|
|
23
30
|
```
|
|
24
31
|
|
|
25
32
|
👍 Examples of **correct** code for this rule:
|
|
26
33
|
|
|
27
34
|
```jsx
|
|
28
|
-
import {Heading} from '@primer/react'
|
|
35
|
+
import {Heading} from '@primer/react'
|
|
29
36
|
|
|
30
|
-
|
|
37
|
+
function ExampleComponent() {
|
|
38
|
+
return <Heading as="h2">Heading level 2</Heading>
|
|
39
|
+
}
|
|
31
40
|
```
|
|
32
41
|
|
|
33
42
|
## Options
|
|
34
43
|
|
|
35
44
|
- `skipImportCheck` (default: `false`)
|
|
36
45
|
|
|
37
|
-
By default, the `a11y-explicit-heading` rule will only check for `<Heading>` components imported directly from
|
|
46
|
+
By default, the `a11y-explicit-heading` rule will only check for `<Heading>` components imported directly from
|
|
47
|
+
`@primer/react`. You can disable this behavior by setting `skipImportCheck` to `true`.
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
## Rule Details
|
|
2
2
|
|
|
3
|
-
This rule enforces to use interactive elements as tooltip triggers. Interactive elements can be Primer `Button`,
|
|
3
|
+
This rule enforces to use interactive elements as tooltip triggers. Interactive elements can be Primer `Button`,
|
|
4
|
+
`IconButton` and `Link` components or native elements like `button`, `a` with an `href` attribute, `select`, `textarea`,
|
|
5
|
+
`summary` and `input` (that is not a `hidden` type).
|
|
4
6
|
|
|
5
7
|
👎 Examples of **incorrect** code for this rule:
|
|
6
8
|
|
|
@@ -38,4 +40,6 @@ const App = () => (
|
|
|
38
40
|
|
|
39
41
|
- `skipImportCheck` (default: `false`)
|
|
40
42
|
|
|
41
|
-
By default, the `a11y-tooltip-interactive-trigger` rule will only check for interactive elements in components that
|
|
43
|
+
By default, the `a11y-tooltip-interactive-trigger` rule will only check for interactive elements in components that
|
|
44
|
+
are imported from `@primer/react`. You can disable this behavior by setting `skipImportCheck` to `true`. This is used
|
|
45
|
+
for internal linting in the [primer/react](https://github.com/prime/react) repository.
|
|
@@ -1,46 +1,49 @@
|
|
|
1
|
-
# Enforce direct parent-child relationship of slot components (direct-slot-children)
|
|
2
|
-
|
|
3
|
-
Some Primer React components use a slots pattern under the hood to render subcomponents in specific places. For example,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
1
|
+
# Enforce direct parent-child relationship of slot components (direct-slot-children)
|
|
2
|
+
|
|
3
|
+
Some Primer React components use a slots pattern under the hood to render subcomponents in specific places. For example,
|
|
4
|
+
the `PageLayout` component renders `PageLayout.Header` in the header area, and `PageLayout.Footer` in the footer area.
|
|
5
|
+
These subcomponents must be direct children of the parent component, and cannot be nested inside other components.
|
|
6
|
+
|
|
7
|
+
## Rule details
|
|
8
|
+
|
|
9
|
+
This rule enforces that slot components are direct children of their parent component.
|
|
10
|
+
|
|
11
|
+
👎 Examples of **incorrect** code for this rule:
|
|
12
|
+
|
|
13
|
+
```jsx
|
|
14
|
+
/* eslint primer-react/direct-slot-children: "error" */
|
|
15
|
+
import {PageLayout} from '@primer/react'
|
|
16
|
+
|
|
17
|
+
const MyHeader = () => <PageLayout.Header>Header</PageLayout.Header>
|
|
18
|
+
|
|
19
|
+
const App = () => (
|
|
20
|
+
<PageLayout>
|
|
21
|
+
<MyHeader />
|
|
22
|
+
</PageLayout>
|
|
23
|
+
)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
👍 Examples of **correct** code for this rule:
|
|
27
|
+
|
|
28
|
+
```jsx
|
|
29
|
+
/* eslint primer-react/direct-slot-children: "error" */
|
|
30
|
+
import {PageLayout} from '@primer/react'
|
|
31
|
+
|
|
32
|
+
const MyHeader = () => <div>Header</div>
|
|
33
|
+
|
|
34
|
+
const App = () => (
|
|
35
|
+
<PageLayout>
|
|
36
|
+
<PageLayout.Header>
|
|
37
|
+
<MyHeader />
|
|
38
|
+
</PageLayout.Header>
|
|
39
|
+
</PageLayout>
|
|
40
|
+
)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Options
|
|
44
|
+
|
|
45
|
+
- `skipImportCheck` (default: `false`)
|
|
46
|
+
|
|
47
|
+
By default, the `direct-slot-children` rule will only check for direct slot children in components that are imported
|
|
48
|
+
from `@primer/react`. You can disable this behavior by setting `skipImportCheck` to `true`. This is used for internal
|
|
49
|
+
linting in the [primer/react](https://github.com/prime/react) repository.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
## Ensure new Primitive v8 color CSS vars have a fallback
|
|
2
|
+
|
|
3
|
+
This rule is temporary as we begin testing v8 color tokens behind a feature flag. If a color token is used without a fallback, the color will only render if the feature flag is enabled. This rule is an extra safety net to ensure we don't accidentally ship code that relies on the feature flag.
|
|
4
|
+
|
|
5
|
+
## Rule Details
|
|
6
|
+
|
|
7
|
+
This rule refers to a JSON file that lists all the new color tokens
|
|
8
|
+
|
|
9
|
+
```json
|
|
10
|
+
["--fgColor-default", "--fgColor-muted", "--fgColor-onEmphasis"]
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
If it finds that one of these tokens is used without a fallback, it will throw an error.
|
|
14
|
+
|
|
15
|
+
👎 Examples of **incorrect** code for this rule
|
|
16
|
+
|
|
17
|
+
```jsx
|
|
18
|
+
<Button sx={{color: 'var(--fgColor-muted)'}}>Test</Button>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
👍 Examples of **correct** code for this rule:
|
|
22
|
+
|
|
23
|
+
```jsx
|
|
24
|
+
<Button sx={{color: 'var(--fgColor-muted, var(--color-fg-muted))'}}>Test</Button>
|
|
25
|
+
```
|
|
@@ -1,26 +1,31 @@
|
|
|
1
1
|
## Upgrade legacy color CSS variables to Primitives v8 in sx prop
|
|
2
2
|
|
|
3
|
-
CSS variables are allowed within the `sx` prop in Primer React components. However, the legacy color CSS variables are
|
|
3
|
+
CSS variables are allowed within the `sx` prop in Primer React components. However, the legacy color CSS variables are
|
|
4
|
+
deprecated in favor of the new CSS variables introduced in Primitives v8. This rule will warn you if you are using the
|
|
5
|
+
deprecated color CSS variables in the `sx` prop, and autofix it including a fallback to the old value.
|
|
4
6
|
|
|
5
7
|
## Rule Details
|
|
6
8
|
|
|
7
9
|
This rule looks inside the `sx` prop for the following properties:
|
|
8
10
|
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
```json
|
|
12
|
+
[
|
|
13
|
+
"bg",
|
|
14
|
+
"backgroundColor",
|
|
15
|
+
"color",
|
|
16
|
+
"borderColor",
|
|
17
|
+
"borderTopColor",
|
|
18
|
+
"borderRightColor",
|
|
19
|
+
"borderBottomColor",
|
|
20
|
+
"borderLeftColor",
|
|
21
|
+
"border",
|
|
22
|
+
"boxShadow",
|
|
23
|
+
"caretColor"
|
|
24
|
+
]
|
|
21
25
|
```
|
|
22
26
|
|
|
23
|
-
The rule references a static JSON file called `css-variable-map.json` that matches the old color CSS variables to a new
|
|
27
|
+
The rule references a static JSON file called `css-variable-map.json` that matches the old color CSS variables to a new
|
|
28
|
+
one based on the property. We only check `sx` because `stylelint` is used to lint other forms of CSS-in-JS.
|
|
24
29
|
|
|
25
30
|
👎 Examples of **incorrect** code for this rule
|
|
26
31
|
|