@@ -270,6 +270,88 @@ tester.run('shorthand-property-sorting', shorthandFirst, {
270
270
` ,
271
271
} ,
272
272
273
+ //
274
+ // styles from ternary operators should not cause false positives, if the same properties
275
+ // are defined in each style object
276
+ //
277
+
278
+ {
279
+ name : `styles from ternary operators should not cause false positive, if the same properties are defined (css, ${ imp } )` ,
280
+ code : `
281
+ import { css } from '${ imp } ';
282
+ const oldStyles = css({
283
+ font: '...',
284
+ fontWeight: '...',
285
+ });
286
+ const newStyles = css({
287
+ font: '...',
288
+ fontWeight: '...',
289
+ });
290
+ const someCondition = true;
291
+ export const EmphasisText = ({ children }) => <span css={[someCondition ? oldStyles : newStyles]}>{children}</span>;
292
+ ` ,
293
+ } ,
294
+ {
295
+ name : `pseudo-classes from ternary operators should not cause false positive, if the same properties are defined (css, ${ imp } )` ,
296
+ code : `
297
+ import { css } from '${ imp } ';
298
+ const oldStyles = css({
299
+ '&:hover': {
300
+ font: '...',
301
+ fontWeight: '...',
302
+ }
303
+ });
304
+ const newStyles = css({
305
+ '&:hover': {
306
+ font: '...',
307
+ fontWeight: '...',
308
+ },
309
+ });
310
+ const someCondition = true;
311
+ export const EmphasisText = ({ children }) => <span css={[someCondition ? oldStyles : newStyles]}>{children}</span>;
312
+ ` ,
313
+ } ,
314
+ {
315
+ name : `styles from ternary operators should not cause false positive, if the same properties are defined (cssMap, ${ imp } )` ,
316
+ code : `
317
+ import { css } from '${ imp } ';
318
+ const myMap = cssMap({
319
+ warning: {
320
+ font: '...',
321
+ fontWeight: '...',
322
+ },
323
+ normal: {
324
+ font: '...',
325
+ fontWeight: '...',
326
+ }
327
+ });
328
+ const someCondition = true;
329
+ export const EmphasisText = ({ appearance, children }) => <span css={myMap[apperance]}>{children}</span>;
330
+ ` ,
331
+ } ,
332
+ {
333
+ name : `pseudo-classes from ternary operators should not cause false positive, if the same properties are defined (cssMap, ${ imp } )` ,
334
+ code : `
335
+ import { cssMap } from '${ imp } ';
336
+ const myMap = cssMap({
337
+ warning: {
338
+ '&:hover': {
339
+ font: '...',
340
+ fontWeight: '...',
341
+ },
342
+ },
343
+ normal: {
344
+ '&:hover': {
345
+ font: '...',
346
+ fontWeight: '...',
347
+ },
348
+ }
349
+ });
350
+ const someCondition = true;
351
+ export const EmphasisText = ({ appearance, children }) => <span css={myMap[apperance]}>{children}</span>;
352
+ ` ,
353
+ } ,
354
+
273
355
//
274
356
// has a valid sorting for borderInlineStart and borderInlineEnd
275
357
//
@@ -310,6 +392,54 @@ tester.run('shorthand-property-sorting', shorthandFirst, {
310
392
export const EmphasisText = ({ children }) => <span css={styles}>{children}</span>;
311
393
` ,
312
394
} ,
395
+
396
+ // false negative: styles in pseudo-classes are not checked when using style composition
397
+
398
+ {
399
+ // Currently not handled due to the added complexity of handling selectors.
400
+ // Feel free to update the rule to handle this, if it becomes a problem
401
+ name : `false negative: styles in pseudo-classes are not checked when using style composition (css, ${ imp } )` ,
402
+ code : `
403
+ import { css } from '${ imp } ';
404
+ const baseStyles = css({
405
+ '&:hover': {
406
+ paddingLeft: '...',
407
+ }
408
+ });
409
+ const newStyles = css({
410
+ '&:hover': {
411
+ padding: '...',
412
+ }
413
+ });
414
+ export const EmphasisText = ({ children }) => <span css={[baseStyles, newStyles]}>{children}</span>;
415
+ ` ,
416
+ } ,
417
+
418
+ //
419
+ // depth in correct order for shorthand properties in the same bucket for cssMap AND if key not static
420
+ //
421
+
422
+ {
423
+ name : `depth in correct order for shorthand properties in the same bucket for cssMap AND if key not static (${ imp } )` ,
424
+ code : outdent `
425
+ import { cssMap } from '${ imp } ';
426
+ const styles = cssMap({
427
+ warning: {
428
+ borderColor: '...', // 2
429
+ borderTop: '...', // 1
430
+ },
431
+ debug: {
432
+ borderColor: '...', // 2
433
+ borderTop: '...', // 1
434
+ },
435
+ normal: {
436
+ borderColor: '...', // 2
437
+ borderTop: '...', // 1
438
+ },
439
+ });
440
+ export const EmphasisText = ({ children, appearance }) => <span css={styles[appearance]}>{children}</span>;
441
+ ` ,
442
+ } ,
313
443
] ) ,
314
444
315
445
invalid : includedImports . flatMap ( ( imp ) => [
@@ -796,39 +926,42 @@ tester.run('shorthand-property-sorting', shorthandFirst, {
796
926
} ,
797
927
798
928
//
799
- // false positives for cssMap
929
+ // known false positives for css
800
930
//
801
931
802
932
{
803
- name : `false positive: shorthands in different selectors for cssMap if key not static (${ imp } )` ,
804
- code : outdent `
805
- import { cssMap } from '${ imp } ';
806
- const styles = cssMap({
807
- warning: {
808
- borderTop: '...',
809
- },
810
- normal: {
811
- border: '...',
812
- }
933
+ // I don't see a good way for the ESLint rule to handle this, without running the
934
+ // rule multiple times to handle each branch of the ternary operator (which can be
935
+ // exponentially expensive the more ternary operators we have)
936
+ name : 'false positive: styles from ternary operators, if different properties are defined' ,
937
+ code : `
938
+ import { css } from '${ imp } ';
939
+ const oldStyles = css({
940
+ fontWeight: '...',
813
941
});
814
- export const EmphasisText = ({ children, appearance }) => <span css={styles[appearance]}>{children}</span>;
942
+ const newStyles = css({
943
+ font: '...',
944
+ });
945
+ const someCondition = true;
946
+ export const EmphasisText = ({ children }) => <span css={[someCondition ? oldStyles : newStyles]}>{children}</span>;
815
947
` ,
816
948
errors : [ { messageId : 'shorthand-first' } , { messageId : 'shorthand-first' } ] ,
817
949
} ,
950
+
951
+ //
952
+ // known false positives for cssMap
953
+ //
954
+
818
955
{
819
- // this is a false positive, but making an exception for this would involve
820
- // some extra logic... maybe we can revisit this if it becomes a common situation.
821
- name : `false positive, if depth in correct order for shorthand properties in the same bucket for cssMap AND if key not static (${ imp } )` ,
956
+ name : `false positive: shorthands in different selectors for cssMap if key not static (${ imp } )` ,
822
957
code : outdent `
823
958
import { cssMap } from '${ imp } ';
824
959
const styles = cssMap({
825
960
warning: {
826
- borderColor: '...', // 2
827
- borderTop: '...', // 1
961
+ borderTop: '...',
828
962
},
829
963
normal: {
830
- borderColor: '...', // 2
831
- borderTop: '...', // 1
964
+ border: '...',
832
965
}
833
966
});
834
967
export const EmphasisText = ({ children, appearance }) => <span css={styles[appearance]}>{children}</span>;
0 commit comments