@@ -237,6 +237,48 @@ ruleTester.run<RuleOptions>('naming-convention', rule, {
237237 } ,
238238 ] ,
239239 } ,
240+ {
241+ name : 'requiredPattern with case style in prefix' ,
242+ options : [
243+ {
244+ FragmentDefinition : {
245+ style : 'PascalCase' ,
246+ requiredPattern : / ^ (?< camelCase > .+ ?) _ / ,
247+ } ,
248+ } ,
249+ ] ,
250+ code : /* GraphQL */ `
251+ fragment myUser_UserProfileFields on User {
252+ id
253+ }
254+ ` ,
255+ parserOptions : {
256+ graphQLConfig : {
257+ schema : 'type User' ,
258+ } ,
259+ } ,
260+ } ,
261+ {
262+ name : 'requiredPattern with case style in suffix' ,
263+ options : [
264+ {
265+ FragmentDefinition : {
266+ style : 'PascalCase' ,
267+ requiredPattern : / _ (?< snake_case > .+ ?) $ / ,
268+ } ,
269+ } ,
270+ ] ,
271+ code : /* GraphQL */ `
272+ fragment UserProfileFields_my_user on User {
273+ id
274+ }
275+ ` ,
276+ parserOptions : {
277+ graphQLConfig : {
278+ schema : 'type User' ,
279+ } ,
280+ } ,
281+ } ,
240282 ] ,
241283 invalid : [
242284 {
@@ -446,15 +488,42 @@ ruleTester.run<RuleOptions>('naming-convention', rule, {
446488 ` ,
447489 options : ( rule . meta . docs ! . configOptions as any ) . operations ,
448490 errors : [
449- { message : 'Query "TestQuery" should not have "Query" suffix' } ,
450- { message : 'Query "QueryTest" should not have "Query" prefix' } ,
451- { message : 'Query "GetQuery" should not have "Get" prefix' } ,
452- { message : 'Mutation "TestMutation" should not have "Mutation" suffix' } ,
453- { message : 'Mutation "MutationTest" should not have "Mutation" prefix' } ,
454- { message : 'Subscription "TestSubscription" should not have "Subscription" suffix' } ,
455- { message : 'Subscription "SubscriptionTest" should not have "Subscription" prefix' } ,
456- { message : 'Fragment "TestFragment" should not have "Fragment" suffix' } ,
457- { message : 'Fragment "FragmentTest" should not have "Fragment" prefix' } ,
491+ {
492+ message :
493+ 'Query "TestQuery" should not contain the forbidden pattern "/(query|mutation|subscription)$/i"' ,
494+ } ,
495+ {
496+ message :
497+ 'Query "QueryTest" should not contain the forbidden pattern "/^(query|mutation|subscription|get)/i"' ,
498+ } ,
499+ {
500+ message :
501+ 'Query "GetQuery" should not contain the forbidden pattern "/^(query|mutation|subscription|get)/i"' ,
502+ } ,
503+ {
504+ message :
505+ 'Mutation "TestMutation" should not contain the forbidden pattern "/(query|mutation|subscription)$/i"' ,
506+ } ,
507+ {
508+ message :
509+ 'Mutation "MutationTest" should not contain the forbidden pattern "/^(query|mutation|subscription|get)/i"' ,
510+ } ,
511+ {
512+ message :
513+ 'Subscription "TestSubscription" should not contain the forbidden pattern "/(query|mutation|subscription)$/i"' ,
514+ } ,
515+ {
516+ message :
517+ 'Subscription "SubscriptionTest" should not contain the forbidden pattern "/^(query|mutation|subscription|get)/i"' ,
518+ } ,
519+ {
520+ message :
521+ 'Fragment "TestFragment" should not contain the forbidden pattern "/(^fragment)|(fragment$)/i"' ,
522+ } ,
523+ {
524+ message :
525+ 'Fragment "FragmentTest" should not contain the forbidden pattern "/(^fragment)|(fragment$)/i"' ,
526+ } ,
458527 ] ,
459528 } ,
460529 {
@@ -536,17 +605,39 @@ ruleTester.run<RuleOptions>('naming-convention', rule, {
536605 errors : 2 ,
537606 } ,
538607 {
539- name : 'requiredPatterns ' ,
608+ name : 'requiredPattern ' ,
540609 code : 'type Test { enabled: Boolean! }' ,
541610 options : [
542611 {
543612 'FieldDefinition[gqlType.gqlType.name.value=Boolean]' : {
544613 style : 'camelCase' ,
545- requiredPatterns : [ / ^ ( i s | h a s ) / ] ,
614+ requiredPattern : / ^ ( i s | h a s ) / ,
546615 } ,
547616 } ,
548617 ] ,
549618 errors : 1 ,
550619 } ,
620+ {
621+ name : 'requiredPattern with case style in suffix' ,
622+ options : [
623+ {
624+ FragmentDefinition : {
625+ style : 'PascalCase' ,
626+ requiredPattern : / _ (?< camelCase > .+ ?) $ / ,
627+ } ,
628+ } ,
629+ ] ,
630+ code : /* GraphQL */ `
631+ fragment UserProfileFields on User {
632+ id
633+ }
634+ ` ,
635+ parserOptions : {
636+ graphQLConfig : {
637+ schema : 'type User' ,
638+ } ,
639+ } ,
640+ errors : 1 ,
641+ } ,
551642 ] ,
552643} ) ;
0 commit comments