Skip to content

Commit 7baeb96

Browse files
authored
no-system-props: Add option to ignore specific component names (#152)
* add ability to ignore specific names * Create quiet-poets-rescue.md * Update quiet-poets-rescue.md
1 parent 18f7887 commit 7baeb96

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

.changeset/quiet-poets-rescue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-primer-react": patch
3+
---
4+
5+
no-system-props: Add option to ignore specific component names

src/rules/__tests__/no-system-props.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ ruleTester.run('no-system-props', rule, {
2323
`import {Button} from '@primer/react'; <Button size="large" />`,
2424
`import {ActionMenu} from '@primer/react'; <ActionMenu.Overlay width="large" />`,
2525
{code: `<img width="200px" />`, options: [{skipImportCheck: true}]},
26+
{code: `<Placeholder width="200px" />`, options: [{skipImportCheck: true, ignoreNames: ['Placeholder']}]},
27+
{
28+
code: `<Placeholder.Header width="200px" />`,
29+
options: [{skipImportCheck: true, ignoreNames: ['Placeholder.Header']}],
30+
},
2631
],
2732
invalid: [
2833
{

src/rules/no-system-props.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,9 @@ module.exports = {
5656
schema: [
5757
{
5858
properties: {
59-
skipImportCheck: {
60-
type: 'boolean',
61-
},
62-
includeUtilityComponents: {
63-
type: 'boolean',
64-
},
59+
skipImportCheck: {type: 'boolean'},
60+
includeUtilityComponents: {type: 'boolean'},
61+
ignoreNames: {type: 'array'},
6562
},
6663
},
6764
],
@@ -73,8 +70,8 @@ module.exports = {
7370
// If `skipImportCheck` is true, this rule will check for deprecated styled system props
7471
// used in any components (not just ones that are imported from `@primer/react`).
7572
const skipImportCheck = context.options[0] ? context.options[0].skipImportCheck : false
76-
7773
const includeUtilityComponents = context.options[0] ? context.options[0].includeUtilityComponents : false
74+
const ignoreNames = context.options[0] ? context.options[0].ignoreNames || [] : []
7875

7976
const excludedComponents = new Set([
8077
...alwaysExcludedComponents,
@@ -93,6 +90,7 @@ module.exports = {
9390
}
9491

9592
const componentName = getJSXOpeningElementName(jsxNode)
93+
if (ignoreNames.length && ignoreNames.includes(componentName)) return
9694

9795
if (excludedComponents.has(componentName)) return
9896

0 commit comments

Comments
 (0)