Skip to content
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

[naming-convention] Update property schema to accept objects. Add prefix and suffix option #201

Merged

Conversation

eddeee888
Copy link
Contributor

@eddeee888 eddeee888 commented Dec 7, 2020

To make this rule more flexible, it needs to be able to take an object as well as format style string. For example, we might want to check whether a field has a certain suffix. More details: #195

The config is normalized into an object before passing into the validation function.

Note that we can no longer rely on the default enum check because it also tries to validate that an object is part of the enum. Therefore, the validation function needs to check the format enums now.

Also, added a suffix option. The targeted property must have the correct suffix or it will error.

TODO

  • Update docs ?

@changeset-bot
Copy link

changeset-bot bot commented Dec 7, 2020

🦋 Changeset detected

Latest commit: 1177431

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@graphql-eslint/eslint-plugin Minor

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

@dotansimha
Copy link
Member

Thanks @eddeee888 ! Sorry for the late reply. I will look into that and review in a few days :)

Copy link
Member

@dotansimha dotansimha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you @eddeee888 . A few notes:

  1. Please make sure to add a changeset (run yarn changeset and it will guide you). Please bump minor.
  2. We have self-documenting rules now, so I had to make some changes to the rules definition, can you please rebase? (to run the docs generation, use yarn generate:docs.

…fix rule

To make this rule more flexible, it needs to be able to take an object as well as format style string
The config is normalised into an object before passing into the validation function.

Note that we can no longer rely on the default enum check because it also tries
to validate that an object is part of the enum. Therefore, the validation function needs to check
the format enums now.

Add suffix rule
@eddeee888 eddeee888 force-pushed the naming-convention-more-options branch from 58d063d to d337729 Compare December 22, 2020 09:27
@eddeee888 eddeee888 changed the title [naming-convention] Update property schema to accept objects. Add suffix option [naming-convention] Update property schema to accept objects. Add prefix and suffix option Dec 22, 2020
@eddeee888
Copy link
Contributor Author

Hi @dotansimha, thank you for your feedback! I have made some changes as suggested. Please let me know if you still see problems!

The only thing I'm not 100% sure about is the doc generation. I have run yarn generate:doc it but it looks like it's not handling the object case very well. Am I supposed to fill in the missing space?

@eddeee888 eddeee888 requested a review from dotansimha December 22, 2020 09:51
@dotansimha
Copy link
Member

Hi @dotansimha, thank you for your feedback! I have made some changes as suggested. Please let me know if you still see problems!

The only thing I'm not 100% sure about is the doc generation. I have run yarn generate:doc it but it looks like it's not handling the object case very well. Am I supposed to fill in the missing space?

Thank you so much!

It should be generated correctly, so maybe it's just something with the generation script. Can you please point me to the missing/incorrect generate doc? I will try to fix that.

@eddeee888
Copy link
Contributor Author

eddeee888 commented Dec 22, 2020

Looking at the generated doc file, there are only headers with no expected values / comment in between:
https://github.com/dotansimha/graphql-eslint/blob/1764bca129cef8ac62ab38f9348757b601f5a822/docs/rules/naming-convention.md

Maybe it's how the doc generator works but maybe something like this communicates the config values a bit better? :)

#### `InputValueDefinition` (string,object)
- style: string, enum
  - `option1`
  - `option2`
  -  ...
- prefix: string
- suffix: string

@dotansimha
Copy link
Member

Oh it should follow JSON schema structure, and I think declaring type: ['string', 'object'], along with properties isn't valid in this case. Also, there is a bug in the json-schema-to-markdown we are using (see saibotsivad/json-schema-to-markdown#15).

It seems like using definitions should fix that, but then it doesn't support enum correctly. I think eventually we'll have to switch to a different library, but I couldn't find one that is stable/maintained/output single-file.

I applied a workaround and it seems good enough for now. Thank you @eddeee888 !

@dotansimha dotansimha merged commit 174a66f into graphql-hive:master Dec 23, 2020
@eddeee888 eddeee888 deleted the naming-convention-more-options branch December 17, 2021 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants