eslint-plugin-primer-react 8.5.1-rc.7865cb9 → 8.5.1-rc.79a6690

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
+ - [#474](https://github.com/primer/eslint-plugin-primer-react/pull/474) [`1e0f943`](https://github.com/primer/eslint-plugin-primer-react/commit/1e0f943a264aaac2581b95916bd0cb8a66a41a17) Thanks [@liuliu-dev](https://github.com/liuliu-dev)! - Fix `no-unnecessary-components` rule to support `@primer/styled-react` imports.
8
+
7
9
  - [#461](https://github.com/primer/eslint-plugin-primer-react/pull/461) [`75ae0a5`](https://github.com/primer/eslint-plugin-primer-react/commit/75ae0a5cb1d4587b5481c8a459033206aae8e5c3) Thanks [@joshfarrant](https://github.com/joshfarrant)! - Export `enforce-button-for-link-with-no-href` rule, which flags `Link` components which don't have a `href`.
8
10
 
9
11
  ## 8.5.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-primer-react",
3
- "version": "8.5.1-rc.7865cb9",
3
+ "version": "8.5.1-rc.79a6690",
4
4
  "description": "ESLint rules for Primer React",
5
5
  "main": "src/index.js",
6
6
  "engines": {
@@ -55,7 +55,7 @@
55
55
  "eslint-plugin-import": "^2.32.0",
56
56
  "eslint-plugin-no-only-tests": "^3.3.0",
57
57
  "eslint-plugin-prettier": "^5.5.4",
58
- "globals": "^16.3.0",
58
+ "globals": "^17.0.0",
59
59
  "jest": "^30.0.5",
60
60
  "markdownlint-cli2": "^0.20.0",
61
61
  "markdownlint-cli2-formatter-pretty": "^0.0.9"
@@ -7,6 +7,7 @@ const rule = require('../no-unnecessary-components')
7
7
  const {components} = require('../no-unnecessary-components')
8
8
 
9
9
  const prcImport = 'import React from "react"; import {Box, Text} from "@primer/react";'
10
+ const styledReactImport = 'import React from "react"; import {Box, Text} from "@primer/styled-react";'
10
11
  const brandImport = 'import React from "react"; import {Box, Text} from "@primer/react-brand";'
11
12
 
12
13
  /** @param {string} content */
@@ -66,6 +67,26 @@ ruleTester.run('unnecessary-components', rule, {
66
67
  code: `${prcImport}${stringRecordDeclaration}${jsx(`<${component} {...props}>Hello World</${component}>`)}`,
67
68
  filename,
68
69
  },
70
+ {
71
+ name: `${component} from @primer/styled-react with sx prop`,
72
+ code: `${styledReactImport}${jsx(`<${component} sx={{color: "red"}}>Hello World</${component}>`)}`,
73
+ filename,
74
+ },
75
+ {
76
+ name: `${component} from @primer/styled-react with any styled-system prop`,
77
+ code: `${styledReactImport}${jsx(`<${component} flex="row">Hello World</${component}>`)}`,
78
+ filename,
79
+ },
80
+ {
81
+ name: `${component} from @primer/styled-react with spread sx prop`,
82
+ code: `${styledReactImport}${sxObjectDeclaration}${jsx(`<${component} {...props}>Hello World</${component}>`)}`,
83
+ filename,
84
+ },
85
+ {
86
+ name: `${component} from @primer/styled-react with string index spread props`,
87
+ code: `${styledReactImport}${stringRecordDeclaration}${jsx(`<${component} {...props}>Hello World</${component}>`)}`,
88
+ filename,
89
+ },
69
90
  ]),
70
91
  {
71
92
  name: `Text with weight prop`,
@@ -151,5 +172,69 @@ ruleTester.run('unnecessary-components', rule, {
151
172
  errors: [{messageId}],
152
173
  options: [{skipImportCheck: true}],
153
174
  },
175
+ {
176
+ name: `${component} from @primer/styled-react without any styled-system props`,
177
+ code: `${styledReactImport}${jsx(`<${component}>Hello World</${component}>`)}`,
178
+ output: `${styledReactImport}${jsx(`<${replacement}>Hello World</${replacement}>`)}`,
179
+ errors: [{messageId}],
180
+ filename,
181
+ },
182
+ {
183
+ name: `Self-closing ${component} from @primer/styled-react without any styled-system props`,
184
+ code: `${styledReactImport}${jsx(`<${component} />`)}`,
185
+ output: `${styledReactImport}${jsx(`<${replacement} />`)}`,
186
+ errors: [{messageId}],
187
+ filename,
188
+ },
189
+ {
190
+ name: `${component} from @primer/styled-react with spread props without sx`,
191
+ code: `${styledReactImport}${testIdObjectDeclaration}${jsx(`<${component} {...props}>Hello World</${component}>`)}`,
192
+ output: `${styledReactImport}${testIdObjectDeclaration}${jsx(`<${replacement} {...props}>Hello World</${replacement}>`)}`,
193
+ errors: [{messageId}],
194
+ filename,
195
+ },
196
+ {
197
+ name: `${component} from @primer/styled-react with string element 'as' prop`,
198
+ code: `${styledReactImport}${jsx(`<${component} as="code">Hello world</${component}>`)}`,
199
+ // There is extra whitespace here we don't worry about since formatters would get rid of it
200
+ output: `${styledReactImport}${jsx(`<code >Hello world</code>`)}`,
201
+ errors: [{messageId}],
202
+ filename,
203
+ },
204
+ {
205
+ name: `${component} from @primer/styled-react with single-character 'as' prop`,
206
+ code: `${styledReactImport}${jsx(`<${component} as="p">Hello world</${component}>`)}`,
207
+ output: `${styledReactImport}${jsx(`<p >Hello world</p>`)}`,
208
+ errors: [{messageId}],
209
+ filename,
210
+ },
211
+ {
212
+ name: `${component} from @primer/styled-react with string element 'as' prop surrounded by unnecessary braces`,
213
+ code: `${styledReactImport}${jsx(`<${component} as={"code"}>Hello world</${component}>`)}`,
214
+ output: `${styledReactImport}${jsx(`<code >Hello world</code>`)}`,
215
+ errors: [{messageId}],
216
+ filename,
217
+ },
218
+ {
219
+ name: `${component} from @primer/styled-react with component reference 'as' prop`,
220
+ code: `${styledReactImport}${componentDeclaration}${jsx(`<${component} as={OtherComponent}>Hello world</${component}>`)}`,
221
+ output: `${styledReactImport}${componentDeclaration}${jsx(`<OtherComponent >Hello world</OtherComponent>`)}`,
222
+ errors: [{messageId}],
223
+ filename,
224
+ },
225
+ {
226
+ name: `${component} from @primer/styled-react with spread 'as' prop`,
227
+ code: `${styledReactImport}${asObjectDeclaration}${jsx(`<${component} {...props}>Hello world</${component}>`)}`,
228
+ output: null,
229
+ errors: [{messageId}],
230
+ filename,
231
+ },
232
+ {
233
+ name: `${component} from @primer/styled-react with unusable lowercase reference 'as' prop`,
234
+ code: `${styledReactImport}${asConstDeclaration}${jsx(`<${component} as={as}>Hello world</${component}>`)}`,
235
+ output: null,
236
+ errors: [{messageId}],
237
+ filename,
238
+ },
154
239
  ]),
155
240
  })
@@ -1,8 +1,8 @@
1
1
  const {isImportedFrom} = require('./is-imported-from')
2
2
 
3
3
  /**
4
- * Check if `name` is a JSX component that is imported from `@primer/react` or
5
- * a subpath `@primer/react/*`.
4
+ * Check if `name` is a JSX component that is imported from `@primer/react`,
5
+ * `@primer/styled-react`, or a subpath of either.
6
6
  * @returns {boolean}
7
7
  */
8
8
  function isPrimerComponent(name, scope) {
@@ -18,6 +18,6 @@ function isPrimerComponent(name, scope) {
18
18
  default:
19
19
  return false
20
20
  }
21
- return isImportedFrom(/^@primer\/react(?:$|\/)/, identifier, scope)
21
+ return isImportedFrom(/^@primer\/(?:styled-)?react(?:$|\/)/, identifier, scope)
22
22
  }
23
23
  exports.isPrimerComponent = isPrimerComponent