eslint-plugin-primer-react 4.1.2-rc.26303d5 → 4.1.2-rc.cfb8ae8

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/CHANGELOG.md CHANGED
@@ -4,6 +4,8 @@
4
4
 
5
5
  ### Patch Changes
6
6
 
7
+ - [#148](https://github.com/primer/eslint-plugin-primer-react/pull/148) [`523e169`](https://github.com/primer/eslint-plugin-primer-react/commit/523e169a3c6c801750d451e875c83f52e383c772) Thanks [@siddharthkp](https://github.com/siddharthkp)! - no-system-props: skip html elements
8
+
7
9
  - [#149](https://github.com/primer/eslint-plugin-primer-react/pull/149) [`ca14bb6`](https://github.com/primer/eslint-plugin-primer-react/commit/ca14bb695ad296903bfe7598b4eb81291796245a) Thanks [@siddharthkp](https://github.com/siddharthkp)! - no-system-props: allow maxWidth prop for Truncate
8
10
 
9
11
  ## 4.1.1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-primer-react",
3
- "version": "4.1.2-rc.26303d5",
3
+ "version": "4.1.2-rc.cfb8ae8",
4
4
  "description": "ESLint rules for Primer React",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -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')
@@ -81,7 +82,14 @@ module.exports = {
81
82
 
82
83
  return {
83
84
  JSXOpeningElement(jsxNode) {
84
- if (!skipImportCheck && !isPrimerComponent(jsxNode.name, context.getScope(jsxNode))) return
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
+ }
85
93
 
86
94
  const componentName = getJSXOpeningElementName(jsxNode)
87
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