eslint-plugin-primer-react 2.0.0-rc.022b246 → 2.0.0-rc.19538ce
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.
|
@@ -37,3 +37,10 @@ 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
|
+
|
package/package.json
CHANGED
|
@@ -15,7 +15,11 @@ 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 '
|
|
18
|
+
`import {PageLayout} from './PageLayout'; <PageLayout.Header>Header</PageLayout.Header>`,
|
|
19
|
+
{
|
|
20
|
+
code: `import {Foo} from './Foo'; <Foo><div><Foo.Bar></Foo.Bar></div></Foo>`,
|
|
21
|
+
options: [{skipImportCheck: true}]
|
|
22
|
+
}
|
|
19
23
|
],
|
|
20
24
|
invalid: [
|
|
21
25
|
{
|
|
@@ -62,6 +66,16 @@ ruleTester.run('direct-slot-children', rule, {
|
|
|
62
66
|
data: {childName: 'TreeView.LeadingVisual', parentName: 'TreeView.Item'}
|
|
63
67
|
}
|
|
64
68
|
]
|
|
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
|
+
]
|
|
65
79
|
}
|
|
66
80
|
]
|
|
67
81
|
})
|
|
@@ -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,6 +144,28 @@ 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
|
+
]
|
|
147
169
|
}
|
|
148
170
|
]
|
|
149
171
|
})
|
|
@@ -20,7 +20,15 @@ const slotChildToParentMap = Object.entries(slotParentToChildMap).reduce((acc, [
|
|
|
20
20
|
module.exports = {
|
|
21
21
|
meta: {
|
|
22
22
|
type: 'problem',
|
|
23
|
-
schema: [
|
|
23
|
+
schema: [
|
|
24
|
+
{
|
|
25
|
+
properties: {
|
|
26
|
+
skipImportCheck: {
|
|
27
|
+
type: 'boolean'
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
],
|
|
24
32
|
messages: {
|
|
25
33
|
directSlotChildren: '{{childName}} must be a direct child of {{parentName}}.'
|
|
26
34
|
}
|
|
@@ -30,9 +38,16 @@ module.exports = {
|
|
|
30
38
|
JSXOpeningElement(jsxNode) {
|
|
31
39
|
const name = getJSXOpeningElementName(jsxNode)
|
|
32
40
|
|
|
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
|
+
|
|
33
45
|
// If component is a Primer component and a slot child,
|
|
34
46
|
// check if it's a direct child of the slot parent
|
|
35
|
-
if (
|
|
47
|
+
if (
|
|
48
|
+
(skipImportCheck || isPrimerComponent(jsxNode.name, context.getScope(jsxNode))) &&
|
|
49
|
+
slotChildToParentMap[name]
|
|
50
|
+
) {
|
|
36
51
|
const JSXElement = jsxNode.parent
|
|
37
52
|
const parent = JSXElement.parent
|
|
38
53
|
|
|
@@ -52,7 +52,7 @@ module.exports = {
|
|
|
52
52
|
},
|
|
53
53
|
create(context) {
|
|
54
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/
|
|
55
|
+
// used in any components (not just ones that are imported from `@primer/react`).
|
|
56
56
|
const skipImportCheck = context.options[0] ? context.options[0].skipImportCheck : false
|
|
57
57
|
|
|
58
58
|
const includeUtilityComponents = context.options[0] ? context.options[0].includeUtilityComponents : false
|