Skip to content

Commit 388a0bf

Browse files
Godsenaldotansimha
andauthored
Support OperationDefinition naming convention (#426)
* Add OperationDefinition to naming-convertion rule * Add OperationDefinition test to naming convention test * added missing changeset file Co-authored-by: Dotan Simha <[email protected]>
1 parent 5fcbf33 commit 388a0bf

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

.changeset/ninety-colts-switch.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+
Support OperationDefinition in naming-convention rule

.husky/_/husky.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
if [ -z "$husky_skip_init" ]; then
3+
debug () {
4+
[ "$HUSKY_DEBUG" = "1" ] && echo "husky (debug) - $1"
5+
}
6+
7+
readonly hook_name="$(basename "$0")"
8+
debug "starting $hook_name..."
9+
10+
if [ "$HUSKY" = "0" ]; then
11+
debug "HUSKY env variable is set to 0, skipping hook"
12+
exit 0
13+
fi
14+
15+
if [ -f ~/.huskyrc ]; then
16+
debug "sourcing ~/.huskyrc"
17+
. ~/.huskyrc
18+
fi
19+
20+
export readonly husky_skip_init=1
21+
sh -e "$0" "$@"
22+
exitCode="$?"
23+
24+
if [ $exitCode != 0 ]; then
25+
echo "husky - $hook_name hook exited with code $exitCode (error)"
26+
exit $exitCode
27+
fi
28+
29+
exit 0
30+
fi

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,12 @@ const rule: GraphQLESLintRule<NamingConventionRuleConfig> = {
327327
checkNode(node.name, property, 'Input property');
328328
}
329329
},
330+
OperationDefinition: node => {
331+
if (options.OperationDefinition) {
332+
const property = normalisePropertyOption(options.OperationDefinition);
333+
checkNode(node.name, property, 'Operation');
334+
}
335+
},
330336
FragmentDefinition: node => {
331337
if (options.FragmentDefinition) {
332338
const property = normalisePropertyOption(options.FragmentDefinition);

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ ruleTester.runGraphQLTests('naming-convention', rule, {
2424
}`,
2525
options: [
2626
{
27+
OperationDefinition: 'PascalCase',
2728
ObjectTypeDefinition: 'PascalCase',
2829
FieldDefinition: 'camelCase',
2930
EnumValueDefinition: 'UPPER_CASE',
@@ -226,5 +227,17 @@ ruleTester.runGraphQLTests('naming-convention', rule, {
226227
{ message: 'Query "getC" should not have one of the following prefix(es): get, query' },
227228
],
228229
},
230+
{
231+
code: 'query Foo { foo } query getBar { bar }',
232+
options: [
233+
{
234+
OperationDefinition: { style: 'camelCase', forbiddenPrefixes: ['get'] },
235+
},
236+
],
237+
errors: [
238+
{ message: 'Operation name "Foo" should be in camelCase format' },
239+
{ message: 'Operation "getBar" should not have one of the following prefix(es): get' },
240+
],
241+
},
229242
],
230243
});

0 commit comments

Comments
 (0)