@@ -11,80 +11,74 @@ const ruleTester = new RuleTester({
1111 languageOptions : {
1212 parserOptions : {
1313 ecmaVersion : 2022 ,
14- sourceType : "module"
14+ sourceType : "module" ,
15+ ecmaFeatures : {
16+ jsx : true
17+ }
1518 }
1619 }
1720} )
1821
1922ruleTester . run ( "consistent-plural-format" , consistentPluralFormat , {
2023 valid : [
21- // All required keys present (default: one, other)
22- "plural(count, { one: ' # item', other: ' # items' })" ,
23- "plural(count, { one: ' One', other: ' Many', zero: ' None' })" ,
24+ // All required props present (default: one, other)
25+ '<Plural value={count} one=" # item" other=" # items" />' ,
26+ '<Plural value={count} one=" One" other=" Many" zero=" None" />' ,
2427
25- // With i18n prefix
26- "i18n.plural(count, { one: '# item', other: '# items' }) " ,
28+ // With expressions
29+ "<Plural value={count} one={oneMsg} other={otherMsg} /> " ,
2730
2831 // Custom required keys
2932 {
30- code : "plural(count, { other: ' items' })" ,
33+ code : '<Plural value={count} other=" items" />' ,
3134 options : [ { requiredKeys : [ "other" ] } ]
3235 } ,
3336 {
34- code : "plural(count, { one: '#', other: '#', zero: ' none' })" ,
37+ code : '<Plural value={count} one="#" other="#" zero=" none" />' ,
3538 options : [ { requiredKeys : [ "one" , "other" , "zero" ] } ]
3639 } ,
3740
38- // Non-plural calls should be ignored
39- "select(value, { male: 'He', female: 'She', other: 'They' })" ,
40- "someOtherFunction({ one: 'x' })" ,
41-
42- // No object argument (edge case)
43- "plural(count)"
41+ // Non-Plural components should be ignored
42+ '<Select value={gender} male="He" female="She" other="They" />' ,
43+ '<div one="x" />' ,
44+ "<Trans>Hello</Trans>"
4445 ] ,
4546 invalid : [
4647 // Missing 'other' (default required)
4748 {
48- code : "plural(count, { one: ' # item' })" ,
49+ code : '<Plural value={count} one=" # item" />' ,
4950 errors : [ { messageId : "missingPluralKey" , data : { key : "other" } } ]
5051 } ,
5152
5253 // Missing 'one' (default required)
5354 {
54- code : "plural(count, { other: ' # items' })" ,
55+ code : '<Plural value={count} other=" # items" />' ,
5556 errors : [ { messageId : "missingPluralKey" , data : { key : "one" } } ]
5657 } ,
5758
5859 // Missing both default required keys
5960 {
60- code : "plural(count, { zero: ' None' })" ,
61+ code : '<Plural value={count} zero=" None" />' ,
6162 errors : [
6263 { messageId : "missingPluralKey" , data : { key : "one" } } ,
6364 { messageId : "missingPluralKey" , data : { key : "other" } }
6465 ]
6566 } ,
6667
67- // With i18n prefix
68- {
69- code : "i18n.plural(count, { one: '# item' })" ,
70- errors : [ { messageId : "missingPluralKey" , data : { key : "other" } } ]
71- } ,
72-
7368 // Custom required keys missing
7469 {
75- code : "plural(count, { one: '#', other: '#' })" ,
70+ code : '<Plural value={count} one="#" other="#" />' ,
7671 options : [ { requiredKeys : [ "one" , "other" , "zero" ] } ] ,
7772 errors : [ { messageId : "missingPluralKey" , data : { key : "zero" } } ]
7873 } ,
7974
80- // Empty object
75+ // Only value prop
8176 {
82- code : "plural(count, {}) " ,
77+ code : "<Plural value={count} /> " ,
8378 errors : [
8479 { messageId : "missingPluralKey" , data : { key : "one" } } ,
8580 { messageId : "missingPluralKey" , data : { key : "other" } }
8681 ]
8782 }
8883 ]
8984} )
90-
0 commit comments