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

1 implement rubocop #15

Merged
merged 5 commits into from
Jul 2, 2024
Merged

1 implement rubocop #15

merged 5 commits into from
Jul 2, 2024

Conversation

mikeheft
Copy link
Owner

@mikeheft mikeheft commented Jul 2, 2024

Closes #1

  • Implements RuboCop for code consistency, autocorrecting, etc.
  • Adds github action to ensure that all new additions pass and maintain same code formatting

@mikeheft mikeheft linked an issue Jul 2, 2024 that may be closed by this pull request
config.generators.after_generate do |files|
parsable_files = files.filter { |file| file.end_with?('.rb') }
unless parsable_files.empty?
system("bundle exec rubocop -A --fail-level=E #{parsable_files.shelljoin}", exception: true)
Copy link
Owner Author

Choose a reason for hiding this comment

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

From the rubocop documentation, this will autocorrect issues when using rails g

# This cop enforces that private methods are defined using
# `private def` for instance methods or
# `private_class_method def self` for class methods.
class PrivateMethodStyle < Base
Copy link
Owner Author

Choose a reason for hiding this comment

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

This is just a personal preference. I like having each method inlined with the modifier. IMO this makes is more clear and future developers won't need to find the visibility modifier to make sure that new private methods are within that scope.

# frozen_string_literal: true

# Load all Ruby files in the custom directory
Dir[File.join(__dir__, "**/*.rb")].each { |file| require file }
Copy link
Owner Author

@mikeheft mikeheft Jul 2, 2024

Choose a reason for hiding this comment

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

Ensures that the custom cops are required in the .rubocop.yml file. This is a forward fix that will make sure that any new cops are automatically included.

__dir__ Returns the canonicalized absolute path of the directory of the file from which this method is called

Documentation link

@mikeheft mikeheft merged commit 4726de1 into main Jul 2, 2024
1 check passed
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.

Implement RuboCop
1 participant