eslint-plugin-primer-react 0.6.1 → 0.7.1-rc.04b2811
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 +14 -0
- package/README.md +2 -1
- package/docs/rules/no-system-props.md +16 -0
- package/package-lock.json +5631 -0
- package/package.json +1 -1
- package/src/rules/__tests__/no-deprecated-colors.test.js +2 -0
- package/src/rules/__tests__/no-system-props.test.js +24 -1
- package/src/rules/no-deprecated-colors.js +9 -2
- package/src/rules/no-system-props.js +26 -10
package/package.json
CHANGED
|
@@ -31,6 +31,8 @@ ruleTester.run('no-deprecated-colors', rule, {
|
|
|
31
31
|
`import {Box} from "@primer/components"; <Box color="fg.default">Hello</Box>`,
|
|
32
32
|
`import {hello} from "@primer/components"; hello("colors.text.primary")`,
|
|
33
33
|
`import {themeGet} from "@primer/components"; themeGet("space.text.primary")`,
|
|
34
|
+
`import {themeGet} from "@primer/components"; themeGet(props.backgroundColorThemeValue)`,
|
|
35
|
+
`import {themeGet} from "@primer/components"; themeGet(2)`,
|
|
34
36
|
`import {themeGet} from "@other/design-system"; themeGet("colors.text.primary")`,
|
|
35
37
|
`import {get} from "@other/constants"; get("space.text.primary")`,
|
|
36
38
|
`import {Box} from '@primer/components'; <Box sx={styles}>Hello</Box>`,
|
|
@@ -18,7 +18,8 @@ ruleTester.run('no-system-props', rule, {
|
|
|
18
18
|
`import {Button} from '@primer/components'; <Button someOtherProp="foo" />`,
|
|
19
19
|
`import {Box} from '@primer/components'; <Box width={200} />`,
|
|
20
20
|
`import {ProgressBar} from '@primer/components'; <ProgressBar bg="howdy" />`,
|
|
21
|
-
`import {Button} from '@primer/components'; <Button {...someExpression()}
|
|
21
|
+
`import {Button} from '@primer/components'; <Button {...someExpression()} />`,
|
|
22
|
+
`import {Button} from '@primer/components'; <Button variant="large" />`
|
|
22
23
|
],
|
|
23
24
|
invalid: [
|
|
24
25
|
{
|
|
@@ -120,6 +121,28 @@ ruleTester.run('no-system-props', rule, {
|
|
|
120
121
|
data: {propNames: 'width', componentName: 'Label'}
|
|
121
122
|
}
|
|
122
123
|
]
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
code: `import {Box} from '@primer/components'; <Box width={200} />`,
|
|
127
|
+
output: `import {Box} from '@primer/components'; <Box sx={{width: 200}} />`,
|
|
128
|
+
options: [{includeUtilityComponents: true}],
|
|
129
|
+
errors: [
|
|
130
|
+
{
|
|
131
|
+
messageId: 'noSystemProps',
|
|
132
|
+
data: {propNames: 'width', componentName: 'Box'}
|
|
133
|
+
}
|
|
134
|
+
]
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
code: `import {Text} from '@primer/components'; <Text width={200} />`,
|
|
138
|
+
output: `import {Text} from '@primer/components'; <Text sx={{width: 200}} />`,
|
|
139
|
+
options: [{includeUtilityComponents: true}],
|
|
140
|
+
errors: [
|
|
141
|
+
{
|
|
142
|
+
messageId: 'noSystemProps',
|
|
143
|
+
data: {propNames: 'width', componentName: 'Text'}
|
|
144
|
+
}
|
|
145
|
+
]
|
|
123
146
|
}
|
|
124
147
|
]
|
|
125
148
|
})
|
|
@@ -118,11 +118,18 @@ module.exports = {
|
|
|
118
118
|
return
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
const
|
|
121
|
+
const argument = node.arguments[0]
|
|
122
|
+
// Skip if the argument is not a Literal (themeGet(props.backgroundColor))
|
|
123
|
+
// or a string themeGet(2)
|
|
124
|
+
if (argument.type !== 'Literal' || typeof argument.value !== 'string') {
|
|
125
|
+
return
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const [key, ...path] = argument.value.split('.')
|
|
122
129
|
const name = path.join('.')
|
|
123
130
|
|
|
124
131
|
if (['colors', 'shadows'].includes(key) && Object.keys(deprecations).includes(name)) {
|
|
125
|
-
replaceDeprecatedColor(context,
|
|
132
|
+
replaceDeprecatedColor(context, argument, name, str => [key, str].join('.'))
|
|
126
133
|
}
|
|
127
134
|
}
|
|
128
135
|
}
|
|
@@ -3,34 +3,50 @@ const {pick} = require('@styled-system/props')
|
|
|
3
3
|
const {some, last} = require('lodash')
|
|
4
4
|
|
|
5
5
|
// Components for which we allow all styled system props
|
|
6
|
-
const
|
|
7
|
-
'Box',
|
|
8
|
-
'Text',
|
|
6
|
+
const alwaysExcludedComponents = new Set([
|
|
9
7
|
'BaseStyles' // BaseStyles will be deprecated eventually
|
|
10
8
|
])
|
|
11
9
|
|
|
10
|
+
// Excluded by default, but optionally included:
|
|
11
|
+
const utilityComponents = new Set(['Box', 'Text'])
|
|
12
|
+
|
|
12
13
|
// Components for which we allow a set of prop names
|
|
13
14
|
const excludedComponentProps = new Map([
|
|
14
15
|
['AnchoredOverlay', new Set(['width', 'height'])],
|
|
15
16
|
['Avatar', new Set(['size'])],
|
|
16
17
|
['Dialog', new Set(['width', 'height'])],
|
|
17
|
-
['Flash', new Set(['variant'])],
|
|
18
|
-
['Label', new Set(['variant'])],
|
|
19
18
|
['ProgressBar', new Set(['bg'])],
|
|
20
19
|
['Spinner', new Set(['size'])],
|
|
21
20
|
['StyledOcticon', new Set(['size'])]
|
|
22
21
|
])
|
|
23
22
|
|
|
23
|
+
const alwaysExcludedProps = new Set(['variant'])
|
|
24
|
+
|
|
24
25
|
module.exports = {
|
|
25
26
|
meta: {
|
|
26
27
|
type: 'suggestion',
|
|
27
28
|
fixable: 'code',
|
|
28
|
-
schema: [
|
|
29
|
+
schema: [
|
|
30
|
+
{
|
|
31
|
+
properties: {
|
|
32
|
+
includeUtilityComponents: {
|
|
33
|
+
type: 'boolean'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
],
|
|
29
38
|
messages: {
|
|
30
39
|
noSystemProps: 'Styled-system props are deprecated ({{ componentName }} called with props: {{ propNames }})'
|
|
31
40
|
}
|
|
32
41
|
},
|
|
33
42
|
create(context) {
|
|
43
|
+
const includeUtilityComponents = context.options[0] ? context.options[0].includeUtilityComponents : false
|
|
44
|
+
|
|
45
|
+
const excludedComponents = new Set([
|
|
46
|
+
...alwaysExcludedComponents,
|
|
47
|
+
...(includeUtilityComponents ? [] : utilityComponents)
|
|
48
|
+
])
|
|
49
|
+
|
|
34
50
|
return {
|
|
35
51
|
JSXOpeningElement(jsxNode) {
|
|
36
52
|
if (!isPrimerComponent(jsxNode.name, context.getScope(jsxNode))) return
|
|
@@ -49,12 +65,12 @@ module.exports = {
|
|
|
49
65
|
// Create an array of system prop attribute nodes
|
|
50
66
|
let systemProps = Object.values(pick(propsByNameObject))
|
|
51
67
|
|
|
68
|
+
let excludedProps = excludedComponentProps.has(jsxNode.name.name)
|
|
69
|
+
? new Set([...alwaysExcludedProps, ...excludedComponentProps.get(jsxNode.name.name)])
|
|
70
|
+
: alwaysExcludedProps
|
|
71
|
+
|
|
52
72
|
// Filter out our exceptional props
|
|
53
73
|
systemProps = systemProps.filter(prop => {
|
|
54
|
-
const excludedProps = excludedComponentProps.get(jsxNode.name.name)
|
|
55
|
-
if (!excludedProps) {
|
|
56
|
-
return true
|
|
57
|
-
}
|
|
58
74
|
return !excludedProps.has(prop.name.name)
|
|
59
75
|
})
|
|
60
76
|
|