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

Add new rails Schema Comment cop #568

Merged
merged 1 commit into from
Nov 8, 2021
Merged

Add new rails Schema Comment cop #568

merged 1 commit into from
Nov 8, 2021

Conversation

vitormd
Copy link
Contributor

@vitormd vitormd commented Sep 30, 2021

Hi, this is my first contribuiton here, so I'm sorry if got something wrong and I hope we can fix it together :)

The cop:

Some databases like MySQL and Postgres supports comments and Rails migrations also support adding it. Some teams follow the good practice of adding comments to new columns or tables whenever creating them. This cops enforces this behaviour, but is disabled by default since this practice may not be widely spread.

PS: If this cop is accepted, I will also create one for table comments


Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.
  • If this is a new cop, consider making a corresponding update to the Rails Style Guide.

spec/rubocop/cop/rails/add_column_comment_spec.rb Outdated Show resolved Hide resolved
lib/rubocop/cop/rails/add_column_comment.rb Outdated Show resolved Hide resolved
config/default.yml Outdated Show resolved Hide resolved
config/default.yml Outdated Show resolved Hide resolved
spec/rubocop/cop/rails/add_column_comment_spec.rb Outdated Show resolved Hide resolved
@andyw8
Copy link
Contributor

andyw8 commented Oct 1, 2021

Even though your team might add a comment to all columns, I'm wondering if for wider use there should be a configuration option to specify tables/columns to ignore.

@vitormd
Copy link
Contributor Author

vitormd commented Oct 1, 2021

Even though your team might add a comment to all columns, I'm wondering if for wider use there should be a configuration option to specify tables/columns to ignore.

Makes sense, but I'm not sure how configurations get to the cop. I'll see if I figure it out in the next few days.
Do you think it'd make sense a configuration for ignoring certain column types?

Thanks for the review. I will fix the specs and description tomorrow.

@koic
Copy link
Member

koic commented Oct 1, 2021

PS: If this cop is accepted, I will also create one for table comments

It may be preferable to make the inspection of table comments and column comments as one cop. Maybe that cop name like Rails/SchemaComment cop.

config/default.yml Outdated Show resolved Hide resolved
@vitormd
Copy link
Contributor Author

vitormd commented Oct 1, 2021

I think I made all the changes with the exception of the configuration options. I'll work on that

config/default.yml Outdated Show resolved Hide resolved
@vitormd
Copy link
Contributor Author

vitormd commented Oct 4, 2021

Even though your team might add a comment to all columns, I'm wondering if for wider use there should be a configuration option to specify tables/columns to ignore.

@andyw8 do you think this configuration is essential for a first version or we could launch as it is and improve later?

@andyw8
Copy link
Contributor

andyw8 commented Oct 4, 2021

No, not essential.

@vitormd vitormd changed the title Add new rails add column comment cop Add new rails Schema Comment cop Oct 5, 2021
@vitormd
Copy link
Contributor Author

vitormd commented Oct 5, 2021

Great. Just let me know if there is anything else that I missed that can be improved code, test or description wise :)

Copy link
Member

@pirj pirj left a comment

Choose a reason for hiding this comment

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

Notes are purely cosmetic, to make the code slightly (and subjectively) more readable. It's clean and readable as is. Good job!

I'll make a note for myself to explicitly enable the cop on my current project.
❤️ Thank you!

lib/rubocop/cop/rails/schema_comment.rb Outdated Show resolved Hide resolved
lib/rubocop/cop/rails/schema_comment.rb Outdated Show resolved Hide resolved
lib/rubocop/cop/rails/schema_comment.rb Outdated Show resolved Hide resolved
lib/rubocop/cop/rails/schema_comment.rb Outdated Show resolved Hide resolved
lib/rubocop/cop/rails/schema_comment.rb Show resolved Hide resolved
spec/rubocop/cop/rails/schema_comment_spec.rb Show resolved Hide resolved
lib/rubocop/cop/rails/schema_comment.rb Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
Add `Rails/AddColumnComment` cop

Update config/default.yml

Co-authored-by: Andy Waite <[email protected]>

Update lib/rubocop/cop/rails/schema_comment.rb

Co-authored-by: Andy Waite <[email protected]>

Update Rails/SchemaComment doc

Add more column types to Rails/SchemaComment

Improve SchemaComment specs

Remove uncessary safe project config for SchemaComment

Augment rails schema definitions and use Set

Change constant into def_node_matcher @SchemaComment
@koic koic merged commit 9e4bfa3 into rubocop:master Nov 8, 2021
@koic
Copy link
Member

koic commented Nov 8, 2021

Thanks!

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.

4 participants