eslint-plugin-primer-react 2.0.0-rc.19538ce → 2.0.0-rc.9730bcf
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 +0 -4
- package/docs/rules/direct-slot-children.md +0 -7
- package/docs/rules/no-system-props.md +1 -5
- package/package.json +1 -1
- package/src/rules/__tests__/direct-slot-children.test.js +1 -15
- package/src/rules/__tests__/no-system-props.test.js +1 -23
- package/src/rules/direct-slot-children.js +2 -17
- package/src/rules/no-system-props.js +4 -20
package/CHANGELOG.md
CHANGED
|
@@ -6,10 +6,6 @@
|
|
|
6
6
|
|
|
7
7
|
- [#39](https://github.com/primer/eslint-plugin-primer-react/pull/39) [`96a675d`](https://github.com/primer/eslint-plugin-primer-react/commit/96a675d8865450d3be556135947a29181a56551c) Thanks [@colebemis](https://github.com/colebemis)! - Add `direct-slot-children` rule
|
|
8
8
|
|
|
9
|
-
### Minor Changes
|
|
10
|
-
|
|
11
|
-
- [#21](https://github.com/primer/eslint-plugin-primer-react/pull/21) [`5f68eb7`](https://github.com/primer/eslint-plugin-primer-react/commit/5f68eb7e222e2a41c527b5036b1308ff293e7a0d) Thanks [@SferaDev](https://github.com/SferaDev)! - `no-system-props`: Add `skipImportCheck` option
|
|
12
|
-
|
|
13
9
|
## 1.0.1
|
|
14
10
|
|
|
15
11
|
### Patch Changes
|
|
@@ -37,10 +37,3 @@ const App = () => (
|
|
|
37
37
|
</PageLayout>
|
|
38
38
|
)
|
|
39
39
|
```
|
|
40
|
-
|
|
41
|
-
## Options
|
|
42
|
-
|
|
43
|
-
- `skipImportCheck` (default: `false`)
|
|
44
|
-
|
|
45
|
-
By default, the `direct-slot-children` rule will only check for direct slot children in components that are imported from `@primer/react`. You can disable this behavior by setting `skipImportCheck` to `true`. This is used for internal linting in the [primer/react](https://github.com/prime/react) repository.
|
|
46
|
-
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Disallow use of styled-system props (no-system-
|
|
1
|
+
# Disallow use of styled-system props (no-system-colors)
|
|
2
2
|
|
|
3
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
4
|
|
|
@@ -41,10 +41,6 @@ import {Avatar} from 'some-other-library'
|
|
|
41
41
|
|
|
42
42
|
## Options
|
|
43
43
|
|
|
44
|
-
- `skipImportCheck` (default: `false`)
|
|
45
|
-
|
|
46
|
-
By default, the `no-system-props` rule will only check for styled system props used in functions and components that are imported from `@primer/react`. You can disable this behavior by setting `skipImportCheck` to `true`. This is useful for linting custom components that pass styled system props down to Primer React components.
|
|
47
|
-
|
|
48
44
|
- `includeUtilityComponents` (default: `false`)
|
|
49
45
|
|
|
50
46
|
By default, `Box` and `Text` are excluded because styled system props are not deprecated in our utility components. If you prefer to avoid styled system props there as well for consistency, you can set `includeUtilityComponents` to `true`.
|
package/package.json
CHANGED
|
@@ -15,11 +15,7 @@ ruleTester.run('direct-slot-children', rule, {
|
|
|
15
15
|
valid: [
|
|
16
16
|
`import {PageLayout} from '@primer/react'; <PageLayout><PageLayout.Header>Header</PageLayout.Header><PageLayout.Footer>Footer</PageLayout.Footer></PageLayout>`,
|
|
17
17
|
`import {PageLayout} from '@primer/react'; <PageLayout><div><PageLayout.Pane>Header</PageLayout.Pane></div></PageLayout>`,
|
|
18
|
-
`import {PageLayout} from '
|
|
19
|
-
{
|
|
20
|
-
code: `import {Foo} from './Foo'; <Foo><div><Foo.Bar></Foo.Bar></div></Foo>`,
|
|
21
|
-
options: [{skipImportCheck: true}]
|
|
22
|
-
}
|
|
18
|
+
`import {PageLayout} from 'some-library'; <PageLayout.Header>Header</PageLayout.Header>`
|
|
23
19
|
],
|
|
24
20
|
invalid: [
|
|
25
21
|
{
|
|
@@ -66,16 +62,6 @@ ruleTester.run('direct-slot-children', rule, {
|
|
|
66
62
|
data: {childName: 'TreeView.LeadingVisual', parentName: 'TreeView.Item'}
|
|
67
63
|
}
|
|
68
64
|
]
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
code: `import {PageLayout} from './PageLayout'; <PageLayout><div><PageLayout.Header>Header</PageLayout.Header></div></PageLayout>`,
|
|
72
|
-
options: [{skipImportCheck: true}],
|
|
73
|
-
errors: [
|
|
74
|
-
{
|
|
75
|
-
messageId: 'directSlotChildren',
|
|
76
|
-
data: {childName: 'PageLayout.Header', parentName: 'PageLayout'}
|
|
77
|
-
}
|
|
78
|
-
]
|
|
79
65
|
}
|
|
80
66
|
]
|
|
81
67
|
})
|
|
@@ -20,7 +20,7 @@ ruleTester.run('no-system-props', rule, {
|
|
|
20
20
|
`import {ProgressBar} from '@primer/react'; <ProgressBar bg="howdy" />`,
|
|
21
21
|
`import {Button} from '@primer/react'; <Button {...someExpression()} />`,
|
|
22
22
|
`import {Button} from '@primer/react'; <Button variant="large" />`,
|
|
23
|
-
`import {Button} from '@primer/react'; <Button size="large"
|
|
23
|
+
`import {Button} from '@primer/react'; <Button size="large" />`,
|
|
24
24
|
],
|
|
25
25
|
invalid: [
|
|
26
26
|
{
|
|
@@ -144,28 +144,6 @@ ruleTester.run('no-system-props', rule, {
|
|
|
144
144
|
data: {propNames: 'width', componentName: 'Text'}
|
|
145
145
|
}
|
|
146
146
|
]
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
code: `import {Button} from '../Button'; <Button width={200} />`,
|
|
150
|
-
options: [{skipImportCheck: true}],
|
|
151
|
-
output: `import {Button} from '../Button'; <Button sx={{width: 200}} />`,
|
|
152
|
-
errors: [
|
|
153
|
-
{
|
|
154
|
-
messageId: 'noSystemProps',
|
|
155
|
-
data: {propNames: 'width', componentName: 'Button'}
|
|
156
|
-
}
|
|
157
|
-
]
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
code: `import {Foo} from '../Foo'; <Foo width={200} />`,
|
|
161
|
-
options: [{skipImportCheck: true}],
|
|
162
|
-
output: `import {Foo} from '../Foo'; <Foo sx={{width: 200}} />`,
|
|
163
|
-
errors: [
|
|
164
|
-
{
|
|
165
|
-
messageId: 'noSystemProps',
|
|
166
|
-
data: {propNames: 'width', componentName: 'Foo'}
|
|
167
|
-
}
|
|
168
|
-
]
|
|
169
147
|
}
|
|
170
148
|
]
|
|
171
149
|
})
|
|
@@ -20,15 +20,7 @@ const slotChildToParentMap = Object.entries(slotParentToChildMap).reduce((acc, [
|
|
|
20
20
|
module.exports = {
|
|
21
21
|
meta: {
|
|
22
22
|
type: 'problem',
|
|
23
|
-
schema: [
|
|
24
|
-
{
|
|
25
|
-
properties: {
|
|
26
|
-
skipImportCheck: {
|
|
27
|
-
type: 'boolean'
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
],
|
|
23
|
+
schema: [],
|
|
32
24
|
messages: {
|
|
33
25
|
directSlotChildren: '{{childName}} must be a direct child of {{parentName}}.'
|
|
34
26
|
}
|
|
@@ -38,16 +30,9 @@ module.exports = {
|
|
|
38
30
|
JSXOpeningElement(jsxNode) {
|
|
39
31
|
const name = getJSXOpeningElementName(jsxNode)
|
|
40
32
|
|
|
41
|
-
// If `skipImportCheck` is true, this rule will check for direct slot children
|
|
42
|
-
// in any components (not just ones that are imported from `@primer/react`).
|
|
43
|
-
const skipImportCheck = context.options[0] ? context.options[0].skipImportCheck : false
|
|
44
|
-
|
|
45
33
|
// If component is a Primer component and a slot child,
|
|
46
34
|
// check if it's a direct child of the slot parent
|
|
47
|
-
if (
|
|
48
|
-
(skipImportCheck || isPrimerComponent(jsxNode.name, context.getScope(jsxNode))) &&
|
|
49
|
-
slotChildToParentMap[name]
|
|
50
|
-
) {
|
|
35
|
+
if (isPrimerComponent(jsxNode.name, context.getScope(jsxNode)) && slotChildToParentMap[name]) {
|
|
51
36
|
const JSXElement = jsxNode.parent
|
|
52
37
|
const parent = JSXElement.parent
|
|
53
38
|
|
|
@@ -13,16 +13,7 @@ const utilityComponents = new Set(['Box', 'Text'])
|
|
|
13
13
|
// Components for which we allow a set of prop names
|
|
14
14
|
const excludedComponentProps = new Map([
|
|
15
15
|
['AnchoredOverlay', new Set(['width', 'height'])],
|
|
16
|
-
['Avatar', new Set(['size'])],
|
|
17
|
-
['AvatarToken', new Set(['size'])],
|
|
18
|
-
['CircleOcticon', new Set(['size'])],
|
|
19
16
|
['Dialog', new Set(['width', 'height'])],
|
|
20
|
-
['IssueLabelToken', new Set(['size'])],
|
|
21
|
-
['ProgressBar', new Set(['bg'])],
|
|
22
|
-
['Spinner', new Set(['size'])],
|
|
23
|
-
['StyledOcticon', new Set(['size'])],
|
|
24
|
-
['PointerBox', new Set(['bg'])],
|
|
25
|
-
['Token', new Set(['size'])],
|
|
26
17
|
['PageLayout', new Set(['padding'])],
|
|
27
18
|
['ProgressBar', new Set(['bg'])],
|
|
28
19
|
['PointerBox', new Set(['bg'])]
|
|
@@ -37,9 +28,6 @@ module.exports = {
|
|
|
37
28
|
schema: [
|
|
38
29
|
{
|
|
39
30
|
properties: {
|
|
40
|
-
skipImportCheck: {
|
|
41
|
-
type: 'boolean'
|
|
42
|
-
},
|
|
43
31
|
includeUtilityComponents: {
|
|
44
32
|
type: 'boolean'
|
|
45
33
|
}
|
|
@@ -51,10 +39,6 @@ module.exports = {
|
|
|
51
39
|
}
|
|
52
40
|
},
|
|
53
41
|
create(context) {
|
|
54
|
-
// If `skipImportCheck` is true, this rule will check for deprecated styled system props
|
|
55
|
-
// used in any components (not just ones that are imported from `@primer/react`).
|
|
56
|
-
const skipImportCheck = context.options[0] ? context.options[0].skipImportCheck : false
|
|
57
|
-
|
|
58
42
|
const includeUtilityComponents = context.options[0] ? context.options[0].includeUtilityComponents : false
|
|
59
43
|
|
|
60
44
|
const excludedComponents = new Set([
|
|
@@ -64,7 +48,7 @@ module.exports = {
|
|
|
64
48
|
|
|
65
49
|
return {
|
|
66
50
|
JSXOpeningElement(jsxNode) {
|
|
67
|
-
if (!
|
|
51
|
+
if (!isPrimerComponent(jsxNode.name, context.getScope(jsxNode))) return
|
|
68
52
|
if (excludedComponents.has(jsxNode.name.name)) return
|
|
69
53
|
|
|
70
54
|
// Create an object mapping from prop name to the AST node for that attribute
|
|
@@ -80,7 +64,7 @@ module.exports = {
|
|
|
80
64
|
// Create an array of system prop attribute nodes
|
|
81
65
|
let systemProps = Object.values(pick(propsByNameObject))
|
|
82
66
|
|
|
83
|
-
|
|
67
|
+
let excludedProps = excludedComponentProps.has(jsxNode.name.name)
|
|
84
68
|
? new Set([...alwaysExcludedProps, ...excludedComponentProps.get(jsxNode.name.name)])
|
|
85
69
|
: alwaysExcludedProps
|
|
86
70
|
|
|
@@ -158,12 +142,12 @@ const excludeSxEntriesFromStyleMap = (stylesMap, sxProp) => {
|
|
|
158
142
|
if (
|
|
159
143
|
!sxProp.value ||
|
|
160
144
|
sxProp.value.type !== 'JSXExpressionContainer' ||
|
|
161
|
-
sxProp.value.expression.type
|
|
145
|
+
sxProp.value.expression.type != 'ObjectExpression'
|
|
162
146
|
) {
|
|
163
147
|
return stylesMap
|
|
164
148
|
}
|
|
165
149
|
return new Map(
|
|
166
|
-
[...stylesMap].filter(([key]) => {
|
|
150
|
+
[...stylesMap].filter(([key, _value]) => {
|
|
167
151
|
return !some(sxProp.value.expression.properties, p => p.type === 'Property' && p.key.name === key)
|
|
168
152
|
})
|
|
169
153
|
)
|