|
| 1 | +import { RuleTester } from 'eslint' |
| 2 | +import rule from '../src/rules/no-conditional-css-prop' |
| 3 | +import sharedGlobals from '../src/sharedGlobals' |
| 4 | + |
| 5 | +const ruleTester = new RuleTester({ |
| 6 | + languageOptions: { |
| 7 | + globals: sharedGlobals, |
| 8 | + parserOptions: { |
| 9 | + ecmaFeatures: { |
| 10 | + jsx: true, |
| 11 | + }, |
| 12 | + }, |
| 13 | + }, |
| 14 | +}) |
| 15 | + |
| 16 | +ruleTester.run('no-conditional-css-prop', rule, { |
| 17 | + invalid: [ |
| 18 | + { |
| 19 | + code: '<div css={condition ? { color: "red" } : { color: "blue" }} />', |
| 20 | + errors: [ |
| 21 | + { |
| 22 | + message: |
| 23 | + 'Avoid using conditionals within the css prop, move them to style.', |
| 24 | + }, |
| 25 | + ], |
| 26 | + }, |
| 27 | + { |
| 28 | + code: '<div css={condition && { color: "red" }} />', |
| 29 | + errors: [ |
| 30 | + { |
| 31 | + message: |
| 32 | + 'Avoid using conditionals within the css prop, move them to style.', |
| 33 | + }, |
| 34 | + ], |
| 35 | + }, |
| 36 | + { |
| 37 | + code: '<div css={condition || { color: "blue" }} />', |
| 38 | + errors: [ |
| 39 | + { |
| 40 | + message: |
| 41 | + 'Avoid using conditionals within the css prop, move them to style.', |
| 42 | + }, |
| 43 | + ], |
| 44 | + }, |
| 45 | + { |
| 46 | + code: '<div css={[{color: `red`}, true && {background: `black`}]} />', |
| 47 | + errors: [ |
| 48 | + { |
| 49 | + message: |
| 50 | + 'Avoid using conditionals within the css prop, move them to style.', |
| 51 | + }, |
| 52 | + ], |
| 53 | + }, |
| 54 | + ], |
| 55 | + valid: [ |
| 56 | + { |
| 57 | + code: '<div css={{ color: "red" }} />', |
| 58 | + }, |
| 59 | + { |
| 60 | + code: '<div css={someVariable} />', |
| 61 | + }, |
| 62 | + { |
| 63 | + code: '<div css={`color: ${someVariable}`} />', |
| 64 | + }, |
| 65 | + { |
| 66 | + code: '<div css={[{color: `red`}, {background: `black`}]} />', |
| 67 | + }, |
| 68 | + ], |
| 69 | +}) |
0 commit comments