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

Update isPrimerComponent helper to only match @primer/react or @primer/react/* #218

Merged
merged 4 commits into from
Sep 6, 2024
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/twenty-rocks-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'eslint-plugin-primer-react': patch
---

Fix incorrect rule violations on components imported from @primer/react-brand
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/rules/__tests__/no-unnecessary-components.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const rule = require('../no-unnecessary-components')
const {components} = require('../no-unnecessary-components')

const prcImport = 'import React from "react"; import {Box, Text} from "@primer/react";'
const brandImport = 'import React from "react"; import {Box, Text} from "@primer/brand";'
const brandImport = 'import React from "react"; import {Box, Text} from "@primer/react-brand";'

/** @param {string} content */
const jsx = content => `export const Component = () => <>${content}</>`
Expand Down
9 changes: 6 additions & 3 deletions src/utils/is-primer-component.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const {isImportedFrom} = require('./is-imported-from')

/** @returns {boolean} */
/**
* Check if `name` is a JSX component that is imported from `@primer/react` or
* a subpath `@primer/react/*`.
* @returns {boolean}
*/
function isPrimerComponent(name, scope) {
let identifier

Expand All @@ -14,7 +18,6 @@ function isPrimerComponent(name, scope) {
default:
return false
}

return isImportedFrom(/^@primer\/react/, identifier, scope)
return isImportedFrom(/^@primer\/react(?:$|\/)/, identifier, scope)
}
exports.isPrimerComponent = isPrimerComponent