From b3fce3997c3eedcbf6dcf2fc8119d747dc5f77e6 Mon Sep 17 00:00:00 2001 From: akumari Date: Sat, 30 Mar 2024 00:43:54 +0530 Subject: [PATCH] Use theforeman-rubocop gem Inherited strictest.yml here, because this closely matches with what rules we already have in our rubocop.yml config. Also dropped Rails, Style/HashSyntax, Style/Documentation and Style/SymbolArray from here because that was included in the inherited file. --- .github/workflows/ruby_tests.yml | 2 + .rubocop.yml | 21 +-- .rubocop_todo.yml | 228 +++++++++++++++++++++++-------- Gemfile | 7 +- 4 files changed, 179 insertions(+), 79 deletions(-) diff --git a/.github/workflows/ruby_tests.yml b/.github/workflows/ruby_tests.yml index 98b48f72d..da5886e9b 100644 --- a/.github/workflows/ruby_tests.yml +++ b/.github/workflows/ruby_tests.yml @@ -16,6 +16,8 @@ jobs: rubocop: name: Rubocop uses: theforeman/actions/.github/workflows/rubocop.yml@v0 + with: + command: bundle exec rubocop --parallel --format github test_ruby: name: Ruby diff --git a/.rubocop.yml b/.rubocop.yml index 86c6e923f..8f5c054f2 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,10 +1,9 @@ inherit_from: - .rubocop_todo.yml -require: - - rubocop-performance - - rubocop-rails - - rubocop-minitest +inherit_gem: + theforeman-rubocop: + - strictest.yml AllCops: TargetRubyVersion: 2.7 @@ -17,7 +16,7 @@ AllCops: # Just so it looks like core Foreman Layout/DotPosition: - EnforcedStyle: 'trailing' + EnforcedStyle: "trailing" Layout/EmptyLineAfterGuardClause: Enabled: false @@ -31,9 +30,6 @@ Metrics: Performance/RegexpMatch: Enabled: false -Rails: - Enabled: true - Rails/ActionFilter: EnforcedStyle: action @@ -43,14 +39,5 @@ Rails/SkipsModelValidations: Style/FormatStringToken: EnforcedStyle: template -Style/HashSyntax: - EnforcedStyle: no_mixed_keys - Style/RaiseArgs: EnforcedStyle: compact - -Style/SymbolArray: - EnforcedStyle: brackets - -Style/Documentation: - Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 79b4382fa..922225328 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,57 +1,78 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2020-08-03 20:17:14 UTC using RuboCop version 0.87.1. +# on 2024-03-29 19:24:18 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: 1 +# Configuration parameters: Include. +# Include: **/*.gemspec +Gemspec/RequiredRubyVersion: + Exclude: + - 'foreman_ansible.gemspec' + +# Offense count: 210 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: with_first_argument, with_fixed_indentation +Layout/ArgumentAlignment: + Enabled: false + +# Offense count: 5 # Cop supports --auto-correct. Layout/ClosingHeredocIndentation: Exclude: - 'test/unit/helpers/ansible_reports_helper_test.rb' -# Offense count: 6 +# Offense count: 8 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: special_inside_parentheses, consistent, align_braces -Layout/FirstHashElementIndentation: +# SupportedStyles: aligned, indented +Layout/LineEndStringConcatenationIndentation: Exclude: - - 'test/functional/ansible_variables_controller_test.rb' + - 'lib/foreman_ansible/register.rb' -# Offense count: 1 +# Offense count: 2 # Cop supports --auto-correct. -# Configuration parameters: AllowInHeredoc. -Layout/TrailingWhitespace: +Lint/BooleanSymbol: Exclude: - - 'db/migrate/20200421201839_update_ansible_inv_template_name.rb' + - 'app/models/ansible_variable.rb' # Offense count: 2 +Lint/MissingSuper: + Exclude: + - 'app/services/foreman_ansible/import_playbooks_error_notification.rb' + - 'app/services/foreman_ansible/import_roles_and_variables_error_notification.rb' + +# Offense count: 6 # Cop supports --auto-correct. -Lint/BooleanSymbol: +# Configuration parameters: EnforcedStyle. +# SupportedStyles: strict, consistent +Lint/SymbolConversion: Exclude: - - 'app/models/ansible_variable.rb' + - 'app/services/foreman_ansible/ansible_report_scanner.rb' -# Offense count: 3 +# Offense count: 2 # Cop supports --auto-correct. Minitest/AssertEmpty: Exclude: - 'test/functional/hosts_controller_test.rb' -# Offense count: 1 +# Offense count: 3 # Cop supports --auto-correct. -Minitest/AssertEqual: +Minitest/AssertEmptyLiteral: Exclude: - - 'test/unit/lib/foreman_ansible_core/command_creator_test.rb' + - 'test/unit/concerns/host_managed_extensions_test.rb' + - 'test/unit/concerns/hostgroup_extensions_test.rb' + - 'test/unit/services/inventory_creator_test.rb' -# Offense count: 3 +# Offense count: 1 # Cop supports --auto-correct. Minitest/AssertIncludes: Exclude: - 'test/functional/api/v2/ansible_inventories_controller_test.rb' - - 'test/unit/lib/foreman_ansible_core/command_creator_test.rb' # Offense count: 1 # Cop supports --auto-correct. @@ -59,20 +80,37 @@ Minitest/AssertTruthy: Exclude: - 'test/unit/services/inventory_creator_test.rb' -# Offense count: 10 +# Offense count: 2 +Minitest/AssertWithExpectedArgument: + Exclude: + - 'test/functional/api/v2/hosts_controller_test.rb' + - 'test/functional/hosts_controller_test.rb' + +# Offense count: 2 # Cop supports --auto-correct. -Minitest/GlobalExpectations: +Minitest/LiteralAsActualArgument: Exclude: - - 'test/unit/concerns/host_managed_extensions_test.rb' - - 'test/unit/concerns/hostgroup_extensions_test.rb' + - 'test/unit/ansible_provider_test.rb' + +# Offense count: 1 +Minitest/MultipleAssertions: + Max: 13 # Offense count: 1 # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. -# AllowedNames: io, id, to, by, on, in, at, ip, db, os, pp +# AllowedNames: at, by, db, id, in, io, ip, of, on, os, pp, to Naming/MethodParameterName: Exclude: - 'app/helpers/foreman_ansible/ansible_roles_helper.rb' +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect. +Performance/StringInclude: + Exclude: + - 'app/services/foreman_ansible/ansible_report_scanner.rb' + - 'app/services/foreman_ansible/insights_plan_runner.rb' + # Offense count: 1 # Configuration parameters: Include. # Include: db/migrate/*.rb @@ -97,7 +135,21 @@ Rails/InverseOf: - 'app/models/concerns/foreman_ansible/host_managed_extensions.rb' - 'app/models/concerns/foreman_ansible/hostgroup_extensions.rb' -# Offense count: 19 +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: Include. +# Include: config/routes.rb, config/routes/**/*.rb +Rails/MatchRoute: + Exclude: + - 'config/routes.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +Rails/Pluck: + Exclude: + - 'test/foreman_ansible/helpers/ansible_roles_helper_test.rb' + +# Offense count: 17 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, Include. # SupportedStyles: assert_not, refute @@ -112,54 +164,56 @@ Rails/RefuteMethods: - 'test/unit/services/inventory_creator_test.rb' - 'test/unit/services/ui_roles_importer_test.rb' -# Offense count: 13 -Style/Documentation: +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: exists, where +Rails/WhereExists: Exclude: - - 'spec/**/*' - - 'test/**/*' - - 'app/controllers/api/v2/ansible_inventories_controller.rb' - - 'app/controllers/ui_ansible_roles_controller.rb' - - 'app/helpers/foreman_ansible/hosts_helper_extensions.rb' - - 'app/models/concerns/foreman_ansible/host_managed_extensions.rb' - - 'app/services/foreman_ansible/ansible_info.rb' - - 'db/migrate/20190318094437_add_imported_attr_to_ansible_variables.rb' - - 'db/migrate/20190328114657_remove_top_level_ansible_variables_setting.rb' - - 'db/migrate/20191010074208_remove_ansible_implementation_setting.rb' - - 'db/migrate/20200421201839_update_ansible_inv_template_name.rb' - - 'lib/foreman_ansible_core/runner/ansible_runner.rb' - - 'lib/foreman_ansible_core/task_launcher/ansible_runner.rb' - - 'lib/foreman_ansible_core/task_launcher/playbook.rb' + - 'app/models/ansible_variable.rb' -# Offense count: 2 +# Offense count: 1 # Cop supports --auto-correct. -Style/ExpandPathArguments: +Style/CaseLikeIf: Exclude: - - 'foreman_ansible.gemspec' - - 'foreman_ansible_core.gemspec' + - 'app/helpers/foreman_ansible/ansible_roles_data_preparations.rb' -# Offense count: 2 +# Offense count: 3 +# Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. -# SupportedStyles: annotated, template, unannotated -Style/FormatStringToken: +# SupportedStyles: compact, expanded +Style/EmptyMethod: Exclude: - - 'lib/foreman_ansible_core/exception.rb' + - 'app/controllers/ansible_variables_controller.rb' + - 'app/controllers/api/v2/ansible_roles_controller.rb' + - 'app/controllers/api/v2/ansible_variables_controller.rb' -# Offense count: 22 +# Offense count: 49 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: always, always_true, never Style/FrozenStringLiteralComment: Enabled: false -# Offense count: 13 +# Offense count: 1 +# Cop supports --auto-correct. +Style/GlobalStdStream: + Exclude: + - 'db/migrate/20180410125416_rename_ansible_job_categories.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowSplatArgument. +Style/HashConversion: + Exclude: + - 'app/services/foreman_ansible/inventory_creator.rb' + +# Offense count: 947 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys Style/HashSyntax: - Exclude: - - 'app/models/ansible_role.rb' - - 'app/models/concerns/foreman_ansible/host_managed_extensions.rb' - - 'app/services/foreman_ansible/renderer_methods.rb' + Enabled: false # Offense count: 3 # Cop supports --auto-correct. @@ -169,13 +223,46 @@ Style/IfUnlessModifier: - 'app/services/foreman_ansible/variables_importer.rb' - 'db/seeds.d/62_ansible_proxy_feature.rb' +# Offense count: 3 +Style/OpenStructUse: + Exclude: + - 'test/unit/services/insights_plan_runner_test.rb' + - 'test/unit/services/inventory_creator_test.rb' + +# Offense count: 1 +# Configuration parameters: AllowedMethods. +# AllowedMethods: respond_to_missing? +Style/OptionalBooleanParameter: + Exclude: + - 'app/helpers/foreman_ansible/ansible_roles_data_preparations.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Style/RedundantAssignment: + Exclude: + - 'app/services/foreman_ansible/api_roles_importer.rb' + - 'app/services/foreman_ansible/inventory_creator.rb' + # Offense count: 1 # Cop supports --auto-correct. Style/RedundantBegin: Exclude: - 'lib/tasks/foreman_ansible_tasks.rake' -# Offense count: 43 +# Offense count: 6 +# Cop supports --auto-correct. +Style/RedundantRegexpEscape: + Exclude: + - 'config/routes.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: Mode. +Style/StringConcatenation: + Exclude: + - 'app/lib/proxy_api/ansible.rb' + +# Offense count: 29 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. # SupportedStyles: single_quotes, double_quotes @@ -190,7 +277,34 @@ Style/StringLiterals: - 'app/views/ui_ansible_roles/index.json.rabl' - 'app/views/ui_ansible_roles/main.json.rabl' - 'app/views/ui_ansible_roles/show.json.rabl' - - 'lib/foreman_ansible_core/runner/ansible_runner.rb' - 'test/functional/api/v2/ansible_inventories_controller_test.rb' - - 'test/unit/services/fact_parser_test.rb' - 'test/unit/services/inventory_creator_test.rb' + +# Offense count: 41 +# Cop supports --auto-correct. +# Configuration parameters: MinSize. +# SupportedStyles: percent, brackets +Style/SymbolArray: + EnforcedStyle: brackets + +# Offense count: 12 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleForMultiline. +# SupportedStylesForMultiline: comma, consistent_comma, no_comma +Style/TrailingCommaInArrayLiteral: + Exclude: + - 'app/helpers/foreman_ansible/ansible_roles_data_preparations.rb' + - 'app/lib/proxy_api/ansible.rb' + - 'app/models/foreman_ansible/ansible_provider.rb' + - 'app/services/foreman_ansible/insights_notification_builder.rb' + - 'db/seeds.d/100_common_parameters.rb' + - 'db/seeds.d/90_notification_blueprints.rb' + - 'lib/foreman_ansible/register.rb' + - 'test/unit/helpers/ansible_reports_helper_test.rb' + +# Offense count: 70 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleForMultiline. +# SupportedStylesForMultiline: comma, consistent_comma, no_comma +Style/TrailingCommaInHashLiteral: + Enabled: false diff --git a/Gemfile b/Gemfile index 6df201afa..263643cdc 100644 --- a/Gemfile +++ b/Gemfile @@ -2,9 +2,6 @@ source 'http://rubygems.org' -gemspec :name => 'foreman_ansible' +gemspec -gem 'rubocop', '~> 0.87.0' -gem 'rubocop-minitest', '~> 0.9.0' -gem 'rubocop-performance', '~> 1.5.2' -gem 'rubocop-rails', '~> 2.7.1' +gem 'theforeman-rubocop', '~> 0.1.0'