Skip to content
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/few-beers-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-primer-react": patch
---

no-system-props: skip html elements
1 change: 1 addition & 0 deletions src/rules/__tests__/no-system-props.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ruleTester.run('no-system-props', rule, {
`import {Button} from '@primer/react'; <Button variant="large" />`,
`import {Button} from '@primer/react'; <Button size="large" />`,
`import {ActionMenu} from '@primer/react'; <ActionMenu.Overlay width="large" />`,
{code: `<img width="200px" />`, options: [{skipImportCheck: true}]},
],
invalid: [
{
Expand Down
10 changes: 9 additions & 1 deletion src/rules/no-system-props.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const {isPrimerComponent} = require('../utils/is-primer-component')
const {isHTMLElement} = require('../utils/is-html-element')
const {getJSXOpeningElementName} = require('../utils/get-jsx-opening-element-name')
const {pick} = require('@styled-system/props')
const {some, last} = require('lodash')
Expand Down Expand Up @@ -81,7 +82,14 @@ module.exports = {

return {
JSXOpeningElement(jsxNode) {
if (!skipImportCheck && !isPrimerComponent(jsxNode.name, context.getScope(jsxNode))) return
if (skipImportCheck) {
// if we skip checking if component is imported from primer,
// we need to atleast skip html elements
if (isHTMLElement(jsxNode)) return
} else {
// skip if component is not imported from primer/react
if (!isPrimerComponent(jsxNode.name, context.getScope(jsxNode))) return
}

const componentName = getJSXOpeningElementName(jsxNode)

Expand Down
11 changes: 11 additions & 0 deletions src/utils/is-html-element.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function isHTMLElement(jsxNode) {
if (jsxNode.name.type === 'JSXIdentifier') {
// this is a very silly proxy, but it works
// React components are capitalised, html elements are not
const firstLetter = jsxNode.name.name
if (firstLetter === firstLetter.toLowerCase()) return true
}

return false
}
exports.isHTMLElement = isHTMLElement