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 |
| }, {}) | ||
|
|
||
| // Create an array of bad prop attribute nodes | ||
| let badProps = Object.values(pick(propsByNameObject)) |
There was a problem hiding this comment.
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)
| 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.
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 | |
| } |
| fixable: 'code', | ||
| schema: [], | ||
| messages: { | ||
| noSystemProps: 'Styled-system props are deprecated ({{componentName}} called with props: {{ propNames }})' |
There was a problem hiding this comment.
| noSystemProps: 'Styled-system props are deprecated ({{componentName}} called with props: {{ propNames }})' | |
| noSystemProps: 'Styled-system props are deprecated ({{ componentName }} called with props: {{ propNames }})' |
| ...(stylesToAdd.size > 0 | ||
| ? [ | ||
| existingSxProp | ||
| ? // Update an existing sx prop: |
There was a problem hiding this comment.
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?
| @@ -0,0 +1,17 @@ | |||
| /** | |||
There was a problem hiding this comment.
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?
| @@ -0,0 +1,38 @@ | |||
| # Disallow use of style system props (no-system-colors) | |||
There was a problem hiding this comment.
| # Disallow use of style system props (no-system-colors) | |
| # Disallow use of styled-system props (no-system-colors) |
|
|
||
| 🔧 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.
| 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.
Can we also mention that the sx prop is now the preferred method of applying custom styles?
| ['Dialog', new Set(['width', 'height'])], | ||
| ['Label', new Set(['variant'])], |
There was a problem hiding this comment.
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'])], |
| ```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.
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} /> |
|
|
||
| ## Rule details | ||
|
|
||
| This rule disallows use of any styled system prop on a Primer component. |
There was a problem hiding this comment.
| 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.