Skip to content

Commit 3e821de

Browse files
authored
fix: allow single letter for snake_case and UPPER_CASE in naming-convention rule (#1008)
1 parent bb66e8d commit 3e821de

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

.changeset/early-cooks-taste.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-eslint/eslint-plugin': patch
3+
---
4+
5+
fix: allow single letter for snake_case and UPPER_CASE in `naming-convention` rule

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ type AllowedStyle = 'camelCase' | 'PascalCase' | 'snake_case' | 'UPPER_CASE';
3030
const StyleToRegex: Record<AllowedStyle, RegExp> = {
3131
camelCase: /^[a-z][\dA-Za-z]*$/,
3232
PascalCase: /^[A-Z][\dA-Za-z]*$/,
33-
snake_case: /^[a-z][\d_a-z]*[\da-z]$/,
34-
UPPER_CASE: /^[A-Z][\dA-Z_]*[\dA-Z]$/,
33+
snake_case: /^[a-z][\d_a-z]*[\da-z]*$/,
34+
UPPER_CASE: /^[A-Z][\dA-Z_]*[\dA-Z]*$/,
3535
};
3636

3737
const ALLOWED_KINDS = Object.keys(KindToDisplayName).sort() as AllowedKind[];

packages/plugin/tests/naming-convention.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,26 @@ ruleTester.runGraphQLTests<[NamingConventionRuleConfig]>('naming-convention', ru
140140
},
141141
],
142142
},
143+
{
144+
name: 'should allow single letter for camelCase',
145+
code: 'type t',
146+
options: [{ ObjectTypeDefinition: 'camelCase' }]
147+
},
148+
{
149+
name: 'should allow single letter for PascalCase',
150+
code: 'type T',
151+
options: [{ ObjectTypeDefinition: 'PascalCase' }]
152+
},
153+
{
154+
name: 'should allow single letter for snake_case',
155+
code: 'type t',
156+
options: [{ ObjectTypeDefinition: 'snake_case' }]
157+
},
158+
{
159+
name: 'should allow single letter for UPPER_CASE',
160+
code: 'type T',
161+
options: [{ ObjectTypeDefinition: 'UPPER_CASE' }]
162+
}
143163
],
144164
invalid: [
145165
{

0 commit comments

Comments
 (0)