@@ -47,6 +47,7 @@ type PropertySchema = {
4747 prefix ?: string ;
4848 forbiddenPrefixes ?: string [ ] ;
4949 forbiddenSuffixes ?: string [ ] ;
50+ ignorePattern ?: string ;
5051} ;
5152
5253type Options = AllowedStyle | PropertySchema ;
@@ -124,6 +125,17 @@ const rule: GraphQLESLintRule<[NamingConventionRuleConfig]> = {
124125 }
125126 ` ,
126127 } ,
128+ {
129+ title : 'Correct' ,
130+ usage : [ { FieldDefinition : { style : 'camelCase' , ignorePattern : '^(EAN13|UPC|UK)' } } ] ,
131+ code : /* GraphQL */ `
132+ type Product {
133+ EAN13: String
134+ UPC: String
135+ UKFlag: String
136+ }
137+ ` ,
138+ } ,
127139 ] ,
128140 configOptions : {
129141 schema : [
@@ -191,6 +203,10 @@ const rule: GraphQLESLintRule<[NamingConventionRuleConfig]> = {
191203 minItems : 1 ,
192204 items : { type : 'string' } ,
193205 } ,
206+ ignorePattern : {
207+ type : 'string' ,
208+ description : 'Option to skip validation of some words, e.g. acronyms' ,
209+ } ,
194210 } ,
195211 } ,
196212 } ,
@@ -249,15 +265,16 @@ const rule: GraphQLESLintRule<[NamingConventionRuleConfig]> = {
249265 if ( ! node ) {
250266 return ;
251267 }
252- const { prefix, suffix, forbiddenPrefixes, forbiddenSuffixes, style } = normalisePropertyOption ( selector ) ;
268+ const { prefix, suffix, forbiddenPrefixes, forbiddenSuffixes, style, ignorePattern } =
269+ normalisePropertyOption ( selector ) ;
253270 const nodeType = KindToDisplayName [ n . kind ] || n . kind ;
254271 const nodeName = node . value ;
255272 const error = getError ( ) ;
256273 if ( error ) {
257274 const { errorMessage, renameToName } = error ;
258- const [ leadingUnderscore ] = nodeName . match ( / ^ _ * / ) ;
259- const [ trailingUnderscore ] = nodeName . match ( / _ * $ / ) ;
260- const suggestedName = leadingUnderscore + renameToName + trailingUnderscore ;
275+ const [ leadingUnderscores ] = nodeName . match ( / ^ _ * / ) ;
276+ const [ trailingUnderscores ] = nodeName . match ( / _ * $ / ) ;
277+ const suggestedName = leadingUnderscores + renameToName + trailingUnderscores ;
261278 context . report ( {
262279 loc : getLocation ( node . loc , node . value ) ,
263280 message : `${ nodeType } "${ nodeName } " should ${ errorMessage } ` ,
@@ -275,6 +292,9 @@ const rule: GraphQLESLintRule<[NamingConventionRuleConfig]> = {
275292 renameToName : string ;
276293 } | void {
277294 const name = nodeName . replace ( / ( ^ _ + ) | ( _ + $ ) / g, '' ) ;
295+ if ( ignorePattern && new RegExp ( ignorePattern , 'u' ) . test ( name ) ) {
296+ return ;
297+ }
278298 if ( prefix && ! name . startsWith ( prefix ) ) {
279299 return {
280300 errorMessage : `have "${ prefix } " prefix` ,
@@ -301,8 +321,12 @@ const rule: GraphQLESLintRule<[NamingConventionRuleConfig]> = {
301321 renameToName : name . replace ( new RegExp ( `${ forbiddenSuffix } $` ) , '' ) ,
302322 } ;
303323 }
324+ // Style is optional
325+ if ( ! style ) {
326+ return ;
327+ }
304328 const caseRegex = StyleToRegex [ style ] ;
305- if ( caseRegex && ! caseRegex . test ( name ) ) {
329+ if ( ! caseRegex . test ( name ) ) {
306330 return {
307331 errorMessage : `be in ${ style } format` ,
308332 renameToName : convertCase ( style , name ) ,
0 commit comments