Skip to content

Commit 0fa2f5c

Browse files
committed
aa
1 parent 322f87d commit 0fa2f5c

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ export const rule: GraphQLESLintRule<RuleOptions> = {
364364
requiredPrefixes,
365365
requiredSuffixes,
366366
forbiddenPattern,
367+
requiredPattern
367368
} = normalisePropertyOption(selector);
368369
const nodeName = node.value;
369370
const error = getError();
@@ -411,6 +412,17 @@ export const rule: GraphQLESLintRule<RuleOptions> = {
411412
renameToNames: [name.replace(new RegExp(forbidden), '')],
412413
};
413414
}
415+
if (
416+
requiredPattern &&
417+
!requiredPattern.some(pattern => new RegExp(pattern).test(name))
418+
) {
419+
return {
420+
errorMessage: `contain the required pattern: ${englishJoinWords(
421+
requiredPattern,
422+
)}`,
423+
renameToNames: []
424+
};
425+
}
414426
const forbiddenPrefix = forbiddenPrefixes?.find(prefix => name.startsWith(prefix));
415427
if (forbiddenPrefix) {
416428
return {

packages/plugin/src/rules/naming-convention/snapshot.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,7 +1984,7 @@ exports[`naming-convention > invalid > requiredPattern 1`] = `
19841984
{
19851985
"FieldDefinition[gqlType.gqlType.name.value=Boolean]": {
19861986
"style": "camelCase",
1987-
"requiredPrefixes": [
1987+
"requiredPattern": [
19881988
"^is",
19891989
"^has"
19901990
]
@@ -1994,15 +1994,7 @@ exports[`naming-convention > invalid > requiredPattern 1`] = `
19941994
#### ❌ Error
19951995

19961996
> 1 | type Test { enabled: Boolean! }
1997-
| ^^^^^^^ Field "enabled" should have one of the following prefixes: ^is or ^has
1998-
1999-
#### 💡 Suggestion 1/2: Rename to \`isEnabled\`
2000-
2001-
1 | type Test { isEnabled: Boolean! }
2002-
2003-
#### 💡 Suggestion 2/2: Rename to \`hasEnabled\`
2004-
2005-
1 | type Test { hasEnabled: Boolean! }
1997+
| ^^^^^^^ Field "enabled" should contain the required pattern: ^is or ^has
20061998
`;
20071999

20082000
exports[`naming-convention > invalid > schema-recommended config 1`] = `

0 commit comments

Comments
 (0)