Skip to content
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

Merged
merged 12 commits into from
Oct 1, 2021
Merged

Adds a no-system-props rule #12

merged 12 commits into from
Oct 1, 2021

Conversation

jfuchs
Copy link
Contributor

@jfuchs jfuchs commented Sep 28, 2021

No description provided.

@changeset-bot
Copy link

changeset-bot bot commented Sep 28, 2021

🦋 Changeset detected

Latest commit: 0555c31

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-plugin-primer-react Minor

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

@jfuchs jfuchs marked this pull request as ready for review October 1, 2021 19:58
@jfuchs jfuchs requested a review from colebemis October 1, 2021 19:58
Copy link
Contributor

@colebemis colebemis left a 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.

}, {})

// Create an array of bad prop attribute nodes
let badProps = Object.values(pick(propsByNameObject))
Copy link
Contributor

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)

Comment on lines 39 to 43
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
}
Copy link
Contributor

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:

Suggested change
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 }})'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:
Copy link
Contributor

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?

@@ -0,0 +1,17 @@
/**
Copy link
Contributor

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?

@@ -0,0 +1,38 @@
# Disallow use of style system props (no-system-colors)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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).

Copy link
Contributor

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?

Comment on lines 16 to 17
['Dialog', new Set(['width', 'height'])],
['Label', new Set(['variant'])],
Copy link
Contributor

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:

Suggested change
['Dialog', new Set(['width', 'height'])],
['Label', new Set(['variant'])],
['Dialog', new Set(['width', 'height'])],
['Flash', new Set(['variant'])],
['Label', new Set(['variant'])],

Comment on lines 25 to 38
```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} />,
```
Copy link
Contributor

@colebemis colebemis Oct 1, 2021

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 than width={}. Using mr={} 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.
Suggested change
```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.
Copy link
Contributor

@colebemis colebemis Oct 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

@jfuchs jfuchs merged commit e32a1f9 into main Oct 1, 2021
@primer-css primer-css mentioned this pull request Oct 1, 2021
@jfuchs jfuchs deleted the jfuchs/no-styled-system-props branch October 1, 2021 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants