@@ -47,6 +47,7 @@ type PropertySchema = {
47
47
prefix ?: string ;
48
48
forbiddenPrefixes ?: string [ ] ;
49
49
forbiddenSuffixes ?: string [ ] ;
50
+ ignorePattern ?: string ;
50
51
} ;
51
52
52
53
type Options = AllowedStyle | PropertySchema ;
@@ -124,6 +125,17 @@ const rule: GraphQLESLintRule<[NamingConventionRuleConfig]> = {
124
125
}
125
126
` ,
126
127
} ,
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
+ } ,
127
139
] ,
128
140
configOptions : {
129
141
schema : [
@@ -191,6 +203,10 @@ const rule: GraphQLESLintRule<[NamingConventionRuleConfig]> = {
191
203
minItems : 1 ,
192
204
items : { type : 'string' } ,
193
205
} ,
206
+ ignorePattern : {
207
+ type : 'string' ,
208
+ description : 'Option to skip validation of some words, e.g. acronyms' ,
209
+ } ,
194
210
} ,
195
211
} ,
196
212
} ,
@@ -249,15 +265,16 @@ const rule: GraphQLESLintRule<[NamingConventionRuleConfig]> = {
249
265
if ( ! node ) {
250
266
return ;
251
267
}
252
- const { prefix, suffix, forbiddenPrefixes, forbiddenSuffixes, style } = normalisePropertyOption ( selector ) ;
268
+ const { prefix, suffix, forbiddenPrefixes, forbiddenSuffixes, style, ignorePattern } =
269
+ normalisePropertyOption ( selector ) ;
253
270
const nodeType = KindToDisplayName [ n . kind ] || n . kind ;
254
271
const nodeName = node . value ;
255
272
const error = getError ( ) ;
256
273
if ( error ) {
257
274
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 ;
261
278
context . report ( {
262
279
loc : getLocation ( node . loc , node . value ) ,
263
280
message : `${ nodeType } "${ nodeName } " should ${ errorMessage } ` ,
@@ -275,6 +292,9 @@ const rule: GraphQLESLintRule<[NamingConventionRuleConfig]> = {
275
292
renameToName : string ;
276
293
} | void {
277
294
const name = nodeName . replace ( / ( ^ _ + ) | ( _ + $ ) / g, '' ) ;
295
+ if ( ignorePattern && new RegExp ( ignorePattern , 'u' ) . test ( name ) ) {
296
+ return ;
297
+ }
278
298
if ( prefix && ! name . startsWith ( prefix ) ) {
279
299
return {
280
300
errorMessage : `have "${ prefix } " prefix` ,
@@ -301,8 +321,12 @@ const rule: GraphQLESLintRule<[NamingConventionRuleConfig]> = {
301
321
renameToName : name . replace ( new RegExp ( `${ forbiddenSuffix } $` ) , '' ) ,
302
322
} ;
303
323
}
324
+ // Style is optional
325
+ if ( ! style ) {
326
+ return ;
327
+ }
304
328
const caseRegex = StyleToRegex [ style ] ;
305
- if ( caseRegex && ! caseRegex . test ( name ) ) {
329
+ if ( ! caseRegex . test ( name ) ) {
306
330
return {
307
331
errorMessage : `be in ${ style } format` ,
308
332
renameToName : convertCase ( style , name ) ,
0 commit comments