Skip to content

Commit 99b0703

Browse files
authored
allowLeadingUnderscore and allowTrailingUnderscore should not conflict with ignorePattern in naming-convention rule (#2785)
* aa * aa
1 parent 8e8d7cf commit 99b0703

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

.changeset/spotty-lobsters-enjoy.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@graphql-eslint/eslint-plugin': patch
3+
---
4+
5+
`allowLeadingUnderscore` and `allowTrailingUnderscore` should not conflict with `ignorePattern` in
6+
`naming-convention` rule

packages/plugin/src/rules/naming-convention/index.test.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,21 @@ ruleTester.run<RuleOptions>('naming-convention', rule, {
222222
}
223223
`,
224224
},
225+
{
226+
name: '`allowLeadingUnderscore` and `allowTrailingUnderscore` should not conflict with `ignorePattern`',
227+
code: /* GraphQL */ `
228+
type SomeType {
229+
_someField_: Boolean!
230+
}
231+
`,
232+
options: [
233+
{
234+
'FieldDefinition[parent.name.value=SomeType]': {
235+
ignorePattern: '.*someField.*',
236+
},
237+
},
238+
],
239+
},
225240
],
226241
invalid: [
227242
{
@@ -258,24 +273,12 @@ ruleTester.run<RuleOptions>('naming-convention', rule, {
258273
},
259274
],
260275
errors: [
261-
{
262-
message: 'Input "_idOperatorsFilterFindManyUserInput" should be in PascalCase format',
263-
},
264-
{
265-
message: 'Input "_idOperatorsFilterFindOneUserInput" should be in PascalCase format',
266-
},
267-
{
268-
message: 'Input "_idOperatorsFilterRemoveManyUserInput" should be in PascalCase format',
269-
},
270-
{
271-
message: 'Input "_idOperatorsFilterRemoveOneUserInput" should be in PascalCase format',
272-
},
273-
{
274-
message: 'Input "_idOperatorsFilterUpdateManyUserInput" should be in PascalCase format',
275-
},
276-
{
277-
message: 'Input "_idOperatorsFilterUpdateOneUserInput" should be in PascalCase format',
278-
},
276+
{ message: 'Input "_idOperatorsFilterFindManyUserInput" should be in PascalCase format' },
277+
{ message: 'Input "_idOperatorsFilterFindOneUserInput" should be in PascalCase format' },
278+
{ message: 'Input "_idOperatorsFilterRemoveManyUserInput" should be in PascalCase format' },
279+
{ message: 'Input "_idOperatorsFilterRemoveOneUserInput" should be in PascalCase format' },
280+
{ message: 'Input "_idOperatorsFilterUpdateManyUserInput" should be in PascalCase format' },
281+
{ message: 'Input "_idOperatorsFilterUpdateOneUserInput" should be in PascalCase format' },
279282
{ message: 'Input "_idOperatorsFilterUserInput" should be in PascalCase format' },
280283
{ message: 'Enum value "male" should be in UPPER_CASE format' },
281284
{ message: 'Enum value "female" should be in UPPER_CASE format' },

packages/plugin/src/rules/naming-convention/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ export const rule: GraphQLESLintRule<RuleOptions> = {
342342
create(context) {
343343
const options = context.options[0] || {};
344344
const { allowLeadingUnderscore, allowTrailingUnderscore, types, ...restOptions } = options;
345+
const ignoredNodes = new Set<unknown>();
345346

346347
function normalisePropertyOption(kind: string): PropertySchema {
347348
const style = (restOptions[kind] || types) as Options;
@@ -403,6 +404,9 @@ export const rule: GraphQLESLintRule<RuleOptions> = {
403404
} | void {
404405
const name = nodeName.replace(/(^_+)|(_+$)/g, '');
405406
if (ignorePattern && new RegExp(ignorePattern, 'u').test(name)) {
407+
if ('name' in n) {
408+
ignoredNodes.add(n.name);
409+
}
406410
return;
407411
}
408412
if (prefix && !name.startsWith(prefix)) {
@@ -485,6 +489,9 @@ export const rule: GraphQLESLintRule<RuleOptions> = {
485489
};
486490

487491
const checkUnderscore = (isLeading: boolean) => (node: GraphQLESTreeNode<NameNode>) => {
492+
if (ignoredNodes.has(node)) {
493+
return;
494+
}
488495
if (node.parent.kind === 'Field' && node.parent.alias !== node) {
489496
return;
490497
}

0 commit comments

Comments
 (0)