eslint-plugin-primer-react 4.1.1 → 4.1.2-rc.62fedad
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/CODEOWNERS +1 -1
- package/CHANGELOG.md +8 -0
- package/package-lock.json +14900 -0
- package/package.json +1 -1
- package/src/rules/__tests__/no-system-props.test.js +1 -0
- package/src/rules/no-system-props.js +10 -1
- package/src/utils/is-html-element.js +11 -0
package/package.json
CHANGED
|
@@ -22,6 +22,7 @@ ruleTester.run('no-system-props', rule, {
|
|
|
22
22
|
`import {Button} from '@primer/react'; <Button variant="large" />`,
|
|
23
23
|
`import {Button} from '@primer/react'; <Button size="large" />`,
|
|
24
24
|
`import {ActionMenu} from '@primer/react'; <ActionMenu.Overlay width="large" />`,
|
|
25
|
+
{code: `<img width="200px" />`, options: [{skipImportCheck: true}]},
|
|
25
26
|
],
|
|
26
27
|
invalid: [
|
|
27
28
|
{
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const {isPrimerComponent} = require('../utils/is-primer-component')
|
|
2
|
+
const {isHTMLElement} = require('../utils/is-html-element')
|
|
2
3
|
const {getJSXOpeningElementName} = require('../utils/get-jsx-opening-element-name')
|
|
3
4
|
const {pick} = require('@styled-system/props')
|
|
4
5
|
const {some, last} = require('lodash')
|
|
@@ -42,6 +43,7 @@ const excludedComponentProps = new Map([
|
|
|
42
43
|
['PageLayout.Content', new Set(['padding', 'width'])],
|
|
43
44
|
['ProgressBar', new Set(['bg'])],
|
|
44
45
|
['PointerBox', new Set(['bg'])],
|
|
46
|
+
['Truncate', new Set(['maxWidth'])],
|
|
45
47
|
])
|
|
46
48
|
|
|
47
49
|
const alwaysExcludedProps = new Set(['variant', 'size'])
|
|
@@ -80,7 +82,14 @@ module.exports = {
|
|
|
80
82
|
|
|
81
83
|
return {
|
|
82
84
|
JSXOpeningElement(jsxNode) {
|
|
83
|
-
if (
|
|
85
|
+
if (skipImportCheck) {
|
|
86
|
+
// if we skip checking if component is imported from primer,
|
|
87
|
+
// we need to atleast skip html elements
|
|
88
|
+
if (isHTMLElement(jsxNode)) return
|
|
89
|
+
} else {
|
|
90
|
+
// skip if component is not imported from primer/react
|
|
91
|
+
if (!isPrimerComponent(jsxNode.name, context.getScope(jsxNode))) return
|
|
92
|
+
}
|
|
84
93
|
|
|
85
94
|
const componentName = getJSXOpeningElementName(jsxNode)
|
|
86
95
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
function isHTMLElement(jsxNode) {
|
|
2
|
+
if (jsxNode.name.type === 'JSXIdentifier') {
|
|
3
|
+
// this is a very silly proxy, but it works
|
|
4
|
+
// React components are capitalised, html elements are not
|
|
5
|
+
const firstLetter = jsxNode.name.name
|
|
6
|
+
if (firstLetter === firstLetter.toLowerCase()) return true
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return false
|
|
10
|
+
}
|
|
11
|
+
exports.isHTMLElement = isHTMLElement
|