Skip to content

Commit

Permalink
fix: allow single letter for snake_case and UPPER_CASE in `naming-con…
Browse files Browse the repository at this point in the history
…vention` rule (#1008)
  • Loading branch information
dimaMachina committed Mar 29, 2022
1 parent bb66e8d commit 3e821de
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/early-cooks-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-eslint/eslint-plugin': patch
---

fix: allow single letter for snake_case and UPPER_CASE in `naming-convention` rule
4 changes: 2 additions & 2 deletions packages/plugin/src/rules/naming-convention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ type AllowedStyle = 'camelCase' | 'PascalCase' | 'snake_case' | 'UPPER_CASE';
const StyleToRegex: Record<AllowedStyle, RegExp> = {
camelCase: /^[a-z][\dA-Za-z]*$/,
PascalCase: /^[A-Z][\dA-Za-z]*$/,
snake_case: /^[a-z][\d_a-z]*[\da-z]$/,
UPPER_CASE: /^[A-Z][\dA-Z_]*[\dA-Z]$/,
snake_case: /^[a-z][\d_a-z]*[\da-z]*$/,
UPPER_CASE: /^[A-Z][\dA-Z_]*[\dA-Z]*$/,
};

const ALLOWED_KINDS = Object.keys(KindToDisplayName).sort() as AllowedKind[];
Expand Down
20 changes: 20 additions & 0 deletions packages/plugin/tests/naming-convention.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,26 @@ ruleTester.runGraphQLTests<[NamingConventionRuleConfig]>('naming-convention', ru
},
],
},
{
name: 'should allow single letter for camelCase',
code: 'type t',
options: [{ ObjectTypeDefinition: 'camelCase' }]
},
{
name: 'should allow single letter for PascalCase',
code: 'type T',
options: [{ ObjectTypeDefinition: 'PascalCase' }]
},
{
name: 'should allow single letter for snake_case',
code: 'type t',
options: [{ ObjectTypeDefinition: 'snake_case' }]
},
{
name: 'should allow single letter for UPPER_CASE',
code: 'type T',
options: [{ ObjectTypeDefinition: 'UPPER_CASE' }]
}
],
invalid: [
{
Expand Down

0 comments on commit 3e821de

Please sign in to comment.