eslint-plugin-primer-react 2.0.0-rc.022b246 → 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
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
|
|
@@ -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
|
@@ -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/components`).
|
|
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
|
)
|