Skip to content

Updates no-system-props rule to always exclude the 'variant' prop #20

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

Merged
merged 1 commit into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/orange-tools-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'eslint-plugin-primer-react': minor
---

Updates no-system-props rule to always exclude the 'variant' prop no matter which component.
3 changes: 2 additions & 1 deletion src/rules/__tests__/no-system-props.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ ruleTester.run('no-system-props', rule, {
`import {Button} from '@primer/components'; <Button someOtherProp="foo" />`,
`import {Box} from '@primer/components'; <Box width={200} />`,
`import {ProgressBar} from '@primer/components'; <ProgressBar bg="howdy" />`,
`import {Button} from '@primer/components'; <Button {...someExpression()} />`
`import {Button} from '@primer/components'; <Button {...someExpression()} />`,
`import {Button} from '@primer/components'; <Button variant="large" />`
],
invalid: [
{
Expand Down
12 changes: 6 additions & 6 deletions src/rules/no-system-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ const excludedComponentProps = new Map([
['AnchoredOverlay', new Set(['width', 'height'])],
['Avatar', new Set(['size'])],
['Dialog', new Set(['width', 'height'])],
['Flash', new Set(['variant'])],
['Label', new Set(['variant'])],
['ProgressBar', new Set(['bg'])],
['Spinner', new Set(['size'])],
['StyledOcticon', new Set(['size'])]
])

const alwaysExcludedProps = new Set(['variant'])

module.exports = {
meta: {
type: 'suggestion',
Expand Down Expand Up @@ -65,12 +65,12 @@ module.exports = {
// Create an array of system prop attribute nodes
let systemProps = Object.values(pick(propsByNameObject))

let excludedProps = excludedComponentProps.has(jsxNode.name.name)
? new Set([...alwaysExcludedProps, ...excludedComponentProps.get(jsxNode.name.name)])
: alwaysExcludedProps

// Filter out our exceptional props
systemProps = systemProps.filter(prop => {
const excludedProps = excludedComponentProps.get(jsxNode.name.name)
if (!excludedProps) {
return true
}
return !excludedProps.has(prop.name.name)
})

Expand Down