-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds a no-system-props rule #12
Conversation
🦋 Changeset detectedLatest commit: 0555c31 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really awesome, @jfuchs! 🔥
Left a few minor comments. Nothing blocking.
src/rules/no-system-props.js
Outdated
}, {}) | ||
|
||
// Create an array of bad prop attribute nodes | ||
let badProps = Object.values(pick(propsByNameObject)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you feel about calling this variable systemProps
instead of badProps
? I think that would align nicely with the name of the rule (no-system-props
)
src/rules/no-system-props.js
Outdated
const propsByNameObject = jsxNode.attributes.reduce((object, cur) => { | ||
// We don't do anything about spreads for now — only named attributes: | ||
if (cur.type === 'JSXAttribute') { | ||
object[cur.name.name] = cur | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling this attribute
instead of cur
might be a litte more clear:
const propsByNameObject = jsxNode.attributes.reduce((object, cur) => { | |
// We don't do anything about spreads for now — only named attributes: | |
if (cur.type === 'JSXAttribute') { | |
object[cur.name.name] = cur | |
} | |
const propsByNameObject = jsxNode.attributes.reduce((object, attribute) => { | |
// We don't do anything about spreads for now — only named attributes: | |
if (attribute.type === 'JSXAttribute') { | |
object[attribute.name.name] = attribute | |
} |
src/rules/no-system-props.js
Outdated
fixable: 'code', | ||
schema: [], | ||
messages: { | ||
noSystemProps: 'Styled-system props are deprecated ({{componentName}} called with props: {{ propNames }})' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
noSystemProps: 'Styled-system props are deprecated ({{componentName}} called with props: {{ propNames }})' | |
noSystemProps: 'Styled-system props are deprecated ({{ componentName }} called with props: {{ propNames }})' |
src/rules/no-system-props.js
Outdated
...(stylesToAdd.size > 0 | ||
? [ | ||
existingSxProp | ||
? // Update an existing sx prop: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is super nitpicky (so feel free to ignore): Is there a reason some of your comments end with a colon and some don't?
src/utils/getVariableDeclaration.js
Outdated
@@ -0,0 +1,17 @@ | |||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless you have strong opinions otherwise, can we name these utility files with kebab case instead of camel case to be consistent with the rest of the filenames in this repo?
docs/rules/no-system-props.md
Outdated
@@ -0,0 +1,38 @@ | |||
# Disallow use of style system props (no-system-colors) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Disallow use of style system props (no-system-colors) | |
# Disallow use of styled-system props (no-system-colors) |
docs/rules/no-system-props.md
Outdated
|
||
🔧 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. | ||
|
||
System props are deprecated in Primer components (excluding utility components). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
System props are deprecated in Primer components (excluding utility components). | |
[Styled-system](https://styled-system.com/table) props are deprecated in Primer React components (excluding utility components). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also mention that the sx
prop is now the preferred method of applying custom styles?
src/rules/no-system-props.js
Outdated
['Dialog', new Set(['width', 'height'])], | ||
['Label', new Set(['variant'])], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flash
also accepts a variant
prop:
['Dialog', new Set(['width', 'height'])], | |
['Label', new Set(['variant'])], | |
['Dialog', new Set(['width', 'height'])], | |
['Flash', new Set(['variant'])], | |
['Label', new Set(['variant'])], |
docs/rules/no-system-props.md
Outdated
```jsx | ||
/* eslint primer-react/no-system-props: "error" */ | ||
import {Box, Button, ProgressBar} from '@primer/components' | ||
import {Avatar} from 'some-other-library' | ||
|
||
<Button sx={{width: 200}} />, | ||
<Button someOtherProp="foo" />, | ||
|
||
<ProgressBar bg="howdy" /> | ||
|
||
<Box width={200} />, | ||
|
||
<Avatar width={200} />, | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of notes here:
- I think a prop like
mr={}
is more recognizable as a styled-system prop thanwidth={}
. Usingmr={}
as our example in this document might make help people understand the idea faster. - Adding comments about why these examples are correct could be helpful.
```jsx | |
/* eslint primer-react/no-system-props: "error" */ | |
import {Box, Button, ProgressBar} from '@primer/components' | |
import {Avatar} from 'some-other-library' | |
<Button sx={{width: 200}} />, | |
<Button someOtherProp="foo" />, | |
<ProgressBar bg="howdy" /> | |
<Box width={200} />, | |
<Avatar width={200} />, | |
``` | |
```jsx | |
/* eslint primer-react/no-system-props: "error" */ | |
import {Box, Button, ProgressBar} from '@primer/components' | |
import {Avatar} from 'some-other-library' | |
// Non-system props are allowed | |
<Button someOtherProp="foo" /> | |
// If you need to override styles, use the `sx` prop instead of system props | |
<Button sx={{mr: 2}} /> | |
// Some component prop names overlap with styled-system prop names. | |
// These props are still allowed | |
<ProgressBar bg="success.emphasis" /> | |
// Utility components like Box and Text still accept system props | |
<Box mr={2} /> | |
// System props passed to non-Primer components are allowed | |
<Avatar mr={2} /> |
docs/rules/no-system-props.md
Outdated
|
||
## Rule details | ||
|
||
This rule disallows use of any styled system prop on a Primer component. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This rule disallows use of any styled system prop on a Primer component. | |
This rule disallows the use of any styled-system prop on Primer React components. |
No description provided.