|
| 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 commit comments