eslint-plugin-primer-react 8.4.0 → 8.5.0-rc.1eb9de5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-primer-react",
3
- "version": "8.4.0",
3
+ "version": "8.5.0-rc.1eb9de5",
4
4
  "description": "ESLint rules for Primer React",
5
5
  "main": "src/index.js",
6
6
  "engines": {
@@ -46,7 +46,7 @@
46
46
  "@github/markdownlint-github": "^0.6.3",
47
47
  "@github/prettier-config": "0.0.6",
48
48
  "@types/jest": "^30.0.0",
49
- "@typescript-eslint/rule-tester": "8.44.1",
49
+ "@typescript-eslint/rule-tester": "8.46.2",
50
50
  "eslint": "^9.0.0",
51
51
  "eslint-plugin-eslint-comments": "^3.2.0",
52
52
  "eslint-plugin-filenames": "^1.3.2",
@@ -23,6 +23,7 @@ module.exports = {
23
23
  'primer-react/a11y-use-accessible-tooltip': 'error',
24
24
  'primer-react/no-unnecessary-components': 'error',
25
25
  'primer-react/prefer-action-list-item-onselect': 'error',
26
+ 'primer-react/no-use-responsive-value': 'error',
26
27
  },
27
28
  settings: {
28
29
  github: {
package/src/index.js CHANGED
@@ -21,6 +21,7 @@ module.exports = {
21
21
  'enforce-css-module-default-import': require('./rules/enforce-css-module-default-import'),
22
22
  'use-styled-react-import': require('./rules/use-styled-react-import'),
23
23
  'spread-props-first': require('./rules/spread-props-first'),
24
+ 'no-use-responsive-value': require('./rules/no-use-responsive-value'),
24
25
  },
25
26
  configs: {
26
27
  recommended: require('./configs/recommended'),
@@ -0,0 +1,133 @@
1
+ 'use strict'
2
+
3
+ const {RuleTester} = require('eslint')
4
+ const rule = require('../no-use-responsive-value')
5
+
6
+ const ruleTester = new RuleTester({
7
+ languageOptions: {
8
+ ecmaVersion: 'latest',
9
+ sourceType: 'module',
10
+ parserOptions: {
11
+ ecmaFeatures: {
12
+ jsx: true,
13
+ },
14
+ },
15
+ },
16
+ })
17
+
18
+ ruleTester.run('no-use-responsive-value', rule, {
19
+ valid: [
20
+ // Valid - not importing useResponsiveValue
21
+ `import { Button } from '@primer/react'`,
22
+
23
+ // Valid - importing from other modules
24
+ `import { useResponsiveValue } from 'other-module'`,
25
+
26
+ // Valid - using other hooks from @primer/react
27
+ `import { useTheme } from '@primer/react'`,
28
+
29
+ // Valid - function with same name but not imported from @primer/react
30
+ `function useResponsiveValue() { return 'custom' }`,
31
+
32
+ // Valid - importing from unrelated local paths
33
+ `import { something } from '../utils/helpers'`,
34
+
35
+ // Valid - importing other hooks from local paths
36
+ `import { useCustomHook } from '../hooks/useCustomHook'`,
37
+ ],
38
+ invalid: [
39
+ // Invalid - importing useResponsiveValue from @primer/react
40
+ {
41
+ code: `import { useResponsiveValue } from '@primer/react'`,
42
+ errors: [
43
+ {
44
+ messageId: 'noUseResponsiveValue',
45
+ },
46
+ ],
47
+ },
48
+
49
+ // Invalid - importing with other imports
50
+ {
51
+ code: `import { Button, useResponsiveValue, Box } from '@primer/react'`,
52
+ errors: [
53
+ {
54
+ messageId: 'noUseResponsiveValue',
55
+ },
56
+ ],
57
+ },
58
+
59
+ // Invalid - importing as named import with alias
60
+ {
61
+ code: `import { useResponsiveValue as useRV } from '@primer/react'
62
+ function Component() {
63
+ const value = useRV(['sm', 'md'])
64
+ return <div>{value}</div>
65
+ }`,
66
+ errors: [
67
+ {
68
+ messageId: 'noUseResponsiveValue',
69
+ },
70
+ ],
71
+ },
72
+
73
+ // Invalid - importing from experimental entrypoint
74
+ {
75
+ code: `import { useResponsiveValue } from '@primer/react/experimental'`,
76
+ errors: [
77
+ {
78
+ messageId: 'noUseResponsiveValue',
79
+ },
80
+ ],
81
+ },
82
+
83
+ // Invalid - importing from deprecated entrypoint
84
+ {
85
+ code: `import { useResponsiveValue } from '@primer/react/deprecated'`,
86
+ errors: [
87
+ {
88
+ messageId: 'noUseResponsiveValue',
89
+ },
90
+ ],
91
+ },
92
+
93
+ // Invalid - importing from local hooks path
94
+ {
95
+ code: `import { useResponsiveValue } from '../hooks/useResponsiveValue'`,
96
+ errors: [
97
+ {
98
+ messageId: 'noUseResponsiveValue',
99
+ },
100
+ ],
101
+ },
102
+
103
+ // Invalid - importing default from local useResponsiveValue file
104
+ {
105
+ code: `import useResponsiveValue from '../hooks/useResponsiveValue'`,
106
+ errors: [
107
+ {
108
+ messageId: 'noUseResponsiveValue',
109
+ },
110
+ ],
111
+ },
112
+
113
+ // Invalid - importing from nested path containing useResponsiveValue
114
+ {
115
+ code: `import { useResponsiveValue } from '../../src/hooks/useResponsiveValue'`,
116
+ errors: [
117
+ {
118
+ messageId: 'noUseResponsiveValue',
119
+ },
120
+ ],
121
+ },
122
+
123
+ // Invalid - importing from lib path containing useResponsiveValue
124
+ {
125
+ code: `import { useResponsiveValue } from './useResponsiveValue'`,
126
+ errors: [
127
+ {
128
+ messageId: 'noUseResponsiveValue',
129
+ },
130
+ ],
131
+ },
132
+ ],
133
+ })
@@ -0,0 +1,53 @@
1
+ 'use strict'
2
+
3
+ const url = require('../url')
4
+
5
+ /**
6
+ * @type {import('eslint').Rule.RuleModule}
7
+ */
8
+ module.exports = {
9
+ meta: {
10
+ type: 'problem',
11
+ docs: {
12
+ description: 'Disallow using useResponsiveValue hook',
13
+ recommended: true,
14
+ url: url(module),
15
+ },
16
+ schema: [],
17
+ messages: {
18
+ noUseResponsiveValue: 'useResponsiveValue is not allowed. Use alternative responsive patterns instead.',
19
+ },
20
+ },
21
+ create(context) {
22
+ return {
23
+ // Check for import declarations
24
+ ImportDeclaration(node) {
25
+ // Check for @primer/react imports
26
+ const isPrimerImport = /@primer\/react/.test(node.source.value)
27
+ // Check for local imports that might be useResponsiveValue hook
28
+ const isLocalUseResponsiveValueImport =
29
+ node.source.value.includes('useResponsiveValue') || node.source.value.includes('/hooks/useResponsiveValue')
30
+
31
+ if (!isPrimerImport && !isLocalUseResponsiveValueImport) {
32
+ return
33
+ }
34
+
35
+ for (const specifier of node.specifiers) {
36
+ if (specifier.type === 'ImportSpecifier' && specifier.imported.name === 'useResponsiveValue') {
37
+ context.report({
38
+ node: specifier,
39
+ messageId: 'noUseResponsiveValue',
40
+ })
41
+ }
42
+ // Also check for default imports from useResponsiveValue files
43
+ if (specifier.type === 'ImportDefaultSpecifier' && isLocalUseResponsiveValueImport) {
44
+ context.report({
45
+ node: specifier,
46
+ messageId: 'noUseResponsiveValue',
47
+ })
48
+ }
49
+ }
50
+ },
51
+ }
52
+ },
53
+ }