eslint-plugin-primer-react 5.5.0-rc.40574df → 6.0.0-rc.2964cbe

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 CHANGED
@@ -1,11 +1,21 @@
1
1
  # eslint-plugin-primer-react
2
2
 
3
- ## 5.5.0
3
+ ## 6.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#207](https://github.com/primer/eslint-plugin-primer-react/pull/207) [`baff792`](https://github.com/primer/eslint-plugin-primer-react/commit/baff792c0aa01a29374e44e8aa770dbe2cb889a1) Thanks [@iansan5653](https://github.com/iansan5653)! - [Breaking] Adds `no-unnecessary-components` lint rule and enables it by default. This may raise new (typically autofixable) lint errors in existing codebases.
8
+
9
+ - [#211](https://github.com/primer/eslint-plugin-primer-react/pull/211) [`3f92cd4`](https://github.com/primer/eslint-plugin-primer-react/commit/3f92cd4b689e437bb9efe6a9fe873501ddf76bf2) Thanks [@camchenry](https://github.com/camchenry)! - [Breaking] Adds `prefer-action-list-item-onselect` lint rule and enables it by default. This may raise new auto-fixable lint errors or type-checking errors in existing codebases.
4
10
 
5
11
  ### Minor Changes
6
12
 
7
13
  - [#204](https://github.com/primer/eslint-plugin-primer-react/pull/204) [`e2cab87`](https://github.com/primer/eslint-plugin-primer-react/commit/e2cab872c265f4211750436fad32fe5fd8927c5c) Thanks [@joshblack](https://github.com/joshblack)! - Add use-deprecated-from-deprecated rule
8
14
 
15
+ ### Patch Changes
16
+
17
+ - [#212](https://github.com/primer/eslint-plugin-primer-react/pull/212) [`78d4600`](https://github.com/primer/eslint-plugin-primer-react/commit/78d460024ae4c10b6a754b615c6d594e4dfb646e) Thanks [@langermank](https://github.com/langermank)! - no-system-props: Add `padding` and `gap` as exceptions for `Stack`
18
+
9
19
  ## 5.4.0
10
20
 
11
21
  ### Minor Changes
@@ -0,0 +1,69 @@
1
+ # Disallow unnecessary use of `Box` and `Text` components (no-unnecessary-components)
2
+
3
+ 🔧 The `--fix` option on the [ESLint CLI](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can
4
+ automatically fix some of the problems reported by this rule.
5
+
6
+ ## Rule details
7
+
8
+ The [`Box`](https://primer.style/components/box) and [`Text`](https://primer.style/components/text)
9
+ Primer React components are utilities that exist solely to provide access to `sx` or styled-system
10
+ props.
11
+
12
+ If these props are not being used, plain HTML element provide better performance, simpler code,
13
+ and improved linting support.
14
+
15
+ This rule is auto-fixable in nearly all cases. Autofixing respects the presence of an `as` prop.
16
+
17
+ 👎 Examples of **incorrect** code for this rule:
18
+
19
+ ```jsx
20
+ /* eslint primer-react/no-unnecessary-components: "error" */
21
+ import {Box, Text} from '@primer/react'
22
+
23
+ <Box>Content</Box>
24
+ <Box style={{padding: '16px'}} className="danger-box">Content</Box>
25
+ <Box as="section">Content</Box>
26
+
27
+ <Text>Content</Text>
28
+ <Text style={{fontSize: '24px'}} className="large-text">Content</Text>
29
+ <Text as="p">Content</Text>
30
+ ```
31
+
32
+ 👍 Examples of **correct** code for this rule:
33
+
34
+ ```jsx
35
+ /* eslint primer-react/no-system-props: "error" */
36
+ import {Box, Text} from '@primer/react'
37
+
38
+ // Prefer plain HTML elements (autofixable)
39
+ <div>Content</div>
40
+ <div style={{padding: '16px'}} className="danger-box">Content</div>
41
+ <section>Content</section>
42
+
43
+ <span>Content</span>
44
+ <span style={{fontSize: '24px'}} className="large-text">Content</span>
45
+ <p>Content</p>
46
+
47
+ // sx props are allowed
48
+ <Box sx={{p: 2}}>Content</Box>
49
+ <Text sx={{mt: 2}} as="p">Content</Text>
50
+
51
+ // styled-system props are allowed
52
+ <Box p={2}>Content</Box>
53
+ <Text mt={2} as="p">Content</Text>
54
+ ```
55
+
56
+ ```jsx
57
+ /* eslint primer-react/no-system-props: ["error", {skipImportCheck: false}] */
58
+ import {Box, Text} from '@primer/brand'
59
+
60
+ // Other components with the same name are allowed
61
+ <Box>Content</Box>
62
+ <Text>Content</Text>
63
+ ```
64
+
65
+ ## Options
66
+
67
+ - `skipImportCheck` (default: `false`)
68
+
69
+ By default, the rule will only check for incorrect uses of `Box` and `Text` components that are are imported from `@primer/react`. You can disable this behavior (checking all components with these names regardless of import source) by setting `skipImportCheck` to `true`.
@@ -0,0 +1,37 @@
1
+ # Prefer using `onSelect` instead of `onClick` for `ActionList.Item` components (`prefer-action-list-item-onselect`)
2
+
3
+ 🔧 The `--fix` option on the [ESLint CLI](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule.
4
+
5
+ ## Rule details
6
+
7
+ When using the `onClick` attribute on `ActionList.Item` components, this callback only fires when a user clicks on the element with a mouse. If the user navigates to the element with a keyboard and presses the `Enter` key, the callback will not fire. This produces an inaccessible experience for keyboard users.
8
+
9
+ Using `onSelect` will lead to a more accessible experience for keyboard users compared to using `onClick`.
10
+
11
+ This rule is generally auto-fixable, though you may encounter type checking errors that result from not properly handling keyboard events which are not part of the `onSelect` callback signature.
12
+
13
+ 👎 Examples of **incorrect** code for this rule:
14
+
15
+ ```jsx
16
+ <ActionList.Item onClick={handleClick} />
17
+ <ActionList.Item
18
+ aria-label="Edit item 1"
19
+ onClick={(event) => {
20
+ event.preventDefault()
21
+ handleClick()
22
+ }}
23
+ />
24
+ ```
25
+
26
+ 👍 Examples of **correct** code for this rule:
27
+
28
+ ```jsx
29
+ <ActionList.Item onSelect={handleClick} />
30
+ <ActionList.Item
31
+ aria-label="Edit item 1"
32
+ onSelect={(event) => {
33
+ event.preventDefault()
34
+ handleClick()
35
+ }}
36
+ />
37
+ ```
package/jest.config.js ADDED
@@ -0,0 +1,7 @@
1
+ // @ts-check
2
+
3
+ /** @type {import('jest').Config} **/
4
+ module.exports = {
5
+ testEnvironment: 'node',
6
+ testMatch: ['**/__tests__/*.test.js'],
7
+ }