eslint-plugin-primer-react 4.1.2-rc.26303d5 → 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/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-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "eslint-plugin-primer-react",
3
- "version": "4.1.0",
3
+ "version": "4.1.1",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "eslint-plugin-primer-react",
9
- "version": "4.1.0",
9
+ "version": "4.1.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@styled-system/props": "^5.1.5",
@@ -1900,9 +1900,9 @@
1900
1900
  }
1901
1901
  },
1902
1902
  "node_modules/@primer/primitives": {
1903
- "version": "7.15.8",
1904
- "resolved": "https://registry.npmjs.org/@primer/primitives/-/primitives-7.15.8.tgz",
1905
- "integrity": "sha512-AVJeqvRdNWl6EWP8HaHMHi/nPOepZ/cAPb2ECVYhs2L/X+qmXRePeWv6sAMSFBySPA+1srLAbRBRP8/9nrunWw==",
1903
+ "version": "7.15.9",
1904
+ "resolved": "https://registry.npmjs.org/@primer/primitives/-/primitives-7.15.9.tgz",
1905
+ "integrity": "sha512-1dDNxokYV8sP2QDHMaAaEnRTxhYNBznf4QDTe4Gx9VzOXLexRvqrhvRitDbefbyfvO0yPr5TKI2nGCoz5T5zrQ==",
1906
1906
  "dev": true
1907
1907
  },
1908
1908
  "node_modules/@sinclair/typebox": {
@@ -10021,9 +10021,9 @@
10021
10021
  "dev": true
10022
10022
  },
10023
10023
  "@primer/primitives": {
10024
- "version": "7.15.8",
10025
- "resolved": "https://registry.npmjs.org/@primer/primitives/-/primitives-7.15.8.tgz",
10026
- "integrity": "sha512-AVJeqvRdNWl6EWP8HaHMHi/nPOepZ/cAPb2ECVYhs2L/X+qmXRePeWv6sAMSFBySPA+1srLAbRBRP8/9nrunWw==",
10024
+ "version": "7.15.9",
10025
+ "resolved": "https://registry.npmjs.org/@primer/primitives/-/primitives-7.15.9.tgz",
10026
+ "integrity": "sha512-1dDNxokYV8sP2QDHMaAaEnRTxhYNBznf4QDTe4Gx9VzOXLexRvqrhvRitDbefbyfvO0yPr5TKI2nGCoz5T5zrQ==",
10027
10027
  "dev": true
10028
10028
  },
10029
10029
  "@sinclair/typebox": {
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.62fedad",
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