From 5dda920c8907960866c75290bbd95fca1abf7b00 Mon Sep 17 00:00:00 2001 From: akumari Date: Tue, 2 Apr 2024 14:28:19 +0530 Subject: [PATCH] Use theforeman-rubocop gem Choose to inherit default.yml style because this rules have target ruby and rails version included. Also dropped Style/Documentation because that was already present in inherited gem. default.yml: https://github.com/theforeman/theforeman-rubocop/?tab=readme-ov-file#basic-style---default-performance-and-rails-cops This is part of Rubocop standerdization, link for the reference: https://community.theforeman.org/t/standardizing-rubocop-with-theforeman-rubocop/37239 --- .github/workflows/ci.yml | 2 + .rubocop.yml | 11 ++- .rubocop_todo.yml | 140 +++++++++++++++++++++++++++++++++++++++ Gemfile | 7 +- 4 files changed, 148 insertions(+), 12 deletions(-) create mode 100644 .rubocop_todo.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 648022a..57c616d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,6 +14,8 @@ jobs: rubocop: name: Rubocop uses: theforeman/actions/.github/workflows/rubocop.yml@v0 + with: + command: bundle exec rubocop --parallel --format github test: name: Ruby diff --git a/.rubocop.yml b/.rubocop.yml index 6f7ac32..0b4fffe 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,9 +1,8 @@ -AllCops: - TargetRubyVersion: 2.5 - TargetRailsVersion: 6.0 +inherit_from: .rubocop_todo.yml -Style/Documentation: - Enabled: false +inherit_gem: + theforeman-rubocop: + - default.yml Metrics: Enabled: false @@ -21,4 +20,4 @@ Style/ClassAndModuleChildren: Enabled: false Style/StringLiterals: - Enabled: false \ No newline at end of file + Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..6c8e43f --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,140 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2024-04-02 08:55:39 UTC using RuboCop version 1.23.0. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 53 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: with_first_argument, with_fixed_indentation +Layout/ArgumentAlignment: + Exclude: + - 'app/controllers/api/v2/webhook_templates_controller.rb' + - 'app/controllers/concerns/foreman_webhooks/controller/parameters/webhook.rb' + - 'app/services/foreman_webhooks/webhook_service.rb' + - 'app/views/api/v2/webhooks/show.json.rabl' + - 'config/routes.rb' + - 'lib/foreman_webhooks/engine.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +Minitest/RefuteFalse: + Exclude: + - 'test/controllers/api/v2/webhook_templates_controller_test.rb' + - 'test/controllers/api/v2/webhooks_controller_test.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: Include. +# Include: **/test/**/* +Rails/AssertNot: + Exclude: + - 'test/controllers/api/v2/webhook_templates_controller_test.rb' + - 'test/controllers/api/v2/webhooks_controller_test.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: Whitelist, AllowedMethods, AllowedReceivers. +# Whitelist: find_by_sql +# AllowedMethods: find_by_sql +# AllowedReceivers: Gem::Specification +Rails/DynamicFindBy: + Exclude: + - 'test/controllers/api/v2/webhook_templates_controller_test.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: Include, IgnoredMethods. +# Include: app/models/**/*.rb +# IgnoredMethods: order, limit, select, lock +Rails/FindEach: + Exclude: + - 'app/models/webhook.rb' + +# Offense count: 1 +# Configuration parameters: Include. +# Include: app/models/**/*.rb +Rails/HasManyOrHasOneDependent: + Exclude: + - 'app/models/webhook_template.rb' + +# Offense count: 2 +# Configuration parameters: Include. +# Include: app/models/**/*.rb +Rails/InverseOf: + Exclude: + - 'app/models/webhook.rb' + - 'app/models/webhook_template.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: NotNilAndNotEmpty, NotBlank, UnlessBlank. +Rails/Present: + Exclude: + - 'app/controllers/concerns/foreman_webhooks/controller/parameters/webhook.rb' + - 'app/services/foreman_webhooks/webhook_service.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: Include. +# Include: **/Rakefile, **/*.rake +Rails/RakeEnvironment: + Exclude: + - 'lib/tasks/foreman_webhooks_tasks.rake' + +# Offense count: 2 +# Cop supports --auto-correct. +Rails/RedundantForeignKey: + Exclude: + - 'app/models/webhook.rb' + - 'app/models/webhook_template.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, Include. +# SupportedStyles: assert_not, refute +# Include: **/test/**/* +Rails/RefuteMethods: + Exclude: + - 'test/controllers/api/v2/webhook_templates_controller_test.rb' + - 'test/models/webhook_test.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: compact, expanded +Style/EmptyMethod: + Exclude: + - 'app/controllers/api/v2/webhook_templates_controller.rb' + - 'app/controllers/api/v2/webhooks_controller.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. +# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys +Style/HashSyntax: + Exclude: + - 'config/routes.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleForMultiline. +# SupportedStylesForMultiline: comma, consistent_comma, no_comma +Style/TrailingCommaInArrayLiteral: + Exclude: + - 'lib/foreman_webhooks/engine.rb' + +# Offense count: 8 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleForMultiline. +# SupportedStylesForMultiline: comma, consistent_comma, no_comma +Style/TrailingCommaInHashLiteral: + Exclude: + - 'app/lib/foreman_webhooks/renderer/scope/webhook_template.rb' + - 'app/models/webhook.rb' + - 'app/services/foreman_webhooks/webhook_service.rb' + - 'db/migrate/20200907232758_rename_webhook_permissions.rb' + - 'test/unit/foreman_webhooks/webhook_service_test.rb' diff --git a/Gemfile b/Gemfile index ec2a6e8..6ac694d 100644 --- a/Gemfile +++ b/Gemfile @@ -4,9 +4,4 @@ source 'https://rubygems.org' gemspec -group :test do - gem 'rubocop' - gem 'rubocop-minitest' - gem 'rubocop-performance' - gem 'rubocop-rails' -end +gem 'theforeman-rubocop', '~> 0.1.0'