-
-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create new lone-executable-definition rule #1316
Create new lone-executable-definition rule #1316
Conversation
🦋 Changeset detectedLatest commit: 866828c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Amazing! Hope it was fun! Will be part of next release 🎉 |
It was! And actually relatively easy to implement. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will fix conflicts
@@ -24,7 +24,7 @@ const uppercaseFirst = (string: string) => string.slice(0, 1).toUpperCase() + st | |||
const isDefinitionNode = (node: { kind: string }): node is DefinitionESTreeNode => | |||
node.kind === Kind.OPERATION_DEFINITION || node.kind === Kind.FRAGMENT_DEFINITION; | |||
|
|||
const rule: GraphQLESLintRule<[LoneExecutableDefinitionConfig]> = { | |||
export const rule: GraphQLESLintRule<[LoneExecutableDefinitionConfig]> = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that this change (named instead of default export) is breaking the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I already fixed it, made some refactoring to use ESLint selectors, you should like it
items: { | ||
type: 'object', | ||
minProperties: 1, | ||
additionalProperties: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this prop was missing to catch JSON schema mistake
minProperties: 1, | ||
additionalProperties: false, | ||
properties: { | ||
ignore: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
previously it was ignores
, but you passed ignore
to ESLint
':matches(OperationDefinition, FragmentDefinition)'(node: DefinitionESTreeNode) { | ||
const type = 'operation' in node ? node.operation : 'fragment'; | ||
if (!ignore.has(type)) { | ||
definitions.push({ type, node }); | ||
} | ||
}, | ||
'Program:exit'() { | ||
for (const { node, type } of definitions.slice(1) /* ignore first definition */) { | ||
let name = pascalCase(type); | ||
const definitionName = node.name?.value; | ||
if (definitionName) { | ||
name += ` "${definitionName}"`; | ||
} | ||
context.report({ | ||
loc: node.name?.loc || getLocation(node.loc.start, type), | ||
messageId: RULE_ID, | ||
data: { name }, | ||
}); | ||
} | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here I made some refactoring, looks cleanly now
const pascalCase = (str: string): string => | ||
export const pascalCase = (str: string): string => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can use this function instead manual upperCase
* Create new `lone-executable-definition` rule * Generate docs and configs * Other prettier changes * Allow ignoring first definition * refactor * fix typecheck on GraphQL 15 * add changeset Co-authored-by: Dimitri POSTOLOV <dmytropostolov@gmail.com>
Description
Adds the suggested rule from #1311 to require one file per query/fragment/mutation/subscription. Fixes #1311.
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
I've created new unit tests for the rule, and also ran
npm test
to be sure that I did not break anything.Test Environment:
Checklist:
CONTRIBUTING doc and the
style guidelines of this project
Further comments
The latest commit (b0b0cc8) were automatically generated with
npm run prettier
. I'm happy to revert it if required.