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

Implement ExtractType cop #7

Merged
merged 3 commits into from
Jun 19, 2020

Conversation

0legovich
Copy link
Contributor

@DmitryTsepelev Added cop GraphQL/ExtractType.
Closes #5

Copy link
Owner

@DmitryTsepelev DmitryTsepelev left a comment

Choose a reason for hiding this comment

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

Hi @0legovich, thanks for the contribution, great job! I've added some comments and ideas and please add yourself to the Changelog (right after the ## master line)

lib/rubocop/cop/graphql/extract_type.rb Outdated Show resolved Hide resolved
lib/rubocop/cop/graphql/extract_type.rb Outdated Show resolved Hide resolved
lib/rubocop/cop/graphql/extract_type.rb Outdated Show resolved Hide resolved
spec/rubocop/cop/graphql/extract_type_spec.rb Show resolved Hide resolved
lib/rubocop/cop/graphql/extract_type.rb Outdated Show resolved Hide resolved
@0legovich
Copy link
Contributor Author

@DmitryTsepelev Hi. Thank you for your quick feedback.
I updated the PR according to the comments.

Copy link
Owner

@DmitryTsepelev DmitryTsepelev left a comment

Choose a reason for hiding this comment

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

LGTM! I tried to run the cop in the real–world project and realized that my initial requirements were not full. In some cases we don't need to extract the type, for instance, some teams name Boolean fields starting with is_, and of course when there are more then two fields gem suggests to extract the new type Is.

Solution should be simple: we can add one more config option called Prefixes and skip the check for listed prefixes (example from rubocop-rspec). I guess defaults could be is, avg, min, max.

However, the initial task is definitely completed, please let me know if you want to face this last challenge, or we can call it a day and handle it later 🙂

@0legovich
Copy link
Contributor Author

I think I will add the Prefixes parameter and its processing within the current PR, as a separate commit.

@0legovich
Copy link
Contributor Author

@DmitryTsepelev I also thought about composite prefixes.
For example:

field :contact_info_phone, String, null: false
field :contact_info_name, String, null: false

Here the composite prefix is contact_info.
Do you think we should handle such cases?

@DmitryTsepelev
Copy link
Owner

Yeah, it would be really helpful to handle such cases too, good catch

@0legovich
Copy link
Contributor Author

@DmitryTsepelev Now we are able to recognize composite prefixes. What do you think about this implementation?

Copy link
Owner

@DmitryTsepelev DmitryTsepelev left a comment

Choose a reason for hiding this comment

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

LGTM! I'm going to merge it right now and make some minor tweaks in the master branch, thank you for the hard work!

@DmitryTsepelev DmitryTsepelev merged commit e33acfe into DmitryTsepelev:master Jun 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add cop: ExtractType
2 participants