diff --git a/.github/workflows/ruby_tests.yml b/.github/workflows/ruby_tests.yml index f71df01fa..4695e98b2 100644 --- a/.github/workflows/ruby_tests.yml +++ b/.github/workflows/ruby_tests.yml @@ -11,6 +11,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 e709baf9c..2a9c11af7 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,10 +1,9 @@ -require: - - rubocop-minitest - - rubocop-performance - - rubocop-rails - inherit_from: .rubocop_todo.yml +inherit_gem: + theforeman-rubocop: + - lenient.yml + AllCops: Exclude: - 'node_modules/**/*' @@ -15,25 +14,10 @@ AllCops: Lint/ShadowingOuterLocalVariable: Enabled: false -Rails: - Enabled: true - -# Don't prefer is_a? over kind_of? -Style/ClassCheck: - Enabled: false - -# Don't enforce documentation -Style/Documentation: - Enabled: false - # Support both ruby19 and hash_rockets Style/HashSyntax: Enabled: false -# Both double and single quotes are OK -Style/StringLiterals: - Enabled: false - # Don't enforce frozen string literals Style/FrozenStringLiteralComment: Enabled: false @@ -61,21 +45,17 @@ Layout/LineLength: Naming/FileName: Exclude: - - '*.gemspec' + - "*.gemspec" - Gemfile - db/seeds.d/* - lib/foreman-tasks.rb - gemfile.d/foreman-tasks.rb - Layout/HeredocIndentation: Exclude: - - '*.gemspec' + - "*.gemspec" - bin/* -Layout/EmptyLineAfterGuardClause: - Enabled: false - Style/RescueStandardError: Enabled: false @@ -111,12 +91,3 @@ Rails/HelperInstanceVariable: Naming/RescuedExceptionsVariableName: Enabled: false - -Style/WordArray: - Enabled: false - -Style/TrailingCommaInArrayLiteral: - EnforcedStyleForMultiline: comma - -Style/TrailingCommaInHashLiteral: - EnforcedStyleForMultiline: comma diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b9595c999..b730043e1 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,35 +1,95 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2020-08-07 08:31:32 UTC using RuboCop version 0.89.0. +# on 2024-04-12 08:56:48 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: 2 +# Offense count: 1 # Configuration parameters: Include. # Include: **/*.gemspec Gemspec/RequiredRubyVersion: Exclude: - 'foreman-tasks.gemspec' +# Offense count: 106 +# 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. +# Configuration parameters: EnforcedStyleAlignWith, Severity. +# SupportedStylesAlignWith: start_of_line, begin +Layout/BeginEndAlignment: + Exclude: + - 'app/models/foreman_tasks/remote_task.rb' + - 'app/models/foreman_tasks/task/dynflow_task.rb' + - 'lib/tasks/gettext.rake' + - 'test/unit/actions/proxy_action_test.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: AllowAliasSyntax, AllowedMethods. +# AllowedMethods: alias_method, public, protected, private +Layout/EmptyLinesAroundAttributeAccessor: + Exclude: + - 'app/models/foreman_tasks/lock.rb' + - 'lib/foreman_tasks/cleaner.rb' + - 'lib/foreman_tasks/triggers.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: consistent, consistent_relative_to_receiver, special_for_inner_method_call, special_for_inner_method_call_in_parentheses +Layout/FirstArgumentIndentation: + Exclude: + - 'test/support/dummy_dynflow_action.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +Layout/RescueEnsureAlignment: + Exclude: + - 'app/models/foreman_tasks/remote_task.rb' + - 'lib/foreman_tasks/cleaner.rb' + - 'lib/tasks/gettext.rake' + - 'test/unit/actions/proxy_action_test.rb' + +# Offense count: 8 +# Configuration parameters: AllowedMethods. +# AllowedMethods: enums +Lint/ConstantDefinitionInBlock: + Exclude: + - 'lib/foreman_tasks/tasks/export_tasks.rake' + - 'lib/foreman_tasks/tasks/generate_task_actions.rake' + - 'test/controllers/api/tasks_controller_test.rb' + - 'test/unit/cleaner_test.rb' + - 'test/unit/locking_test.rb' + +# Offense count: 5 +Lint/MissingSuper: + Exclude: + - 'app/lib/actions/helpers/humanizer.rb' + - 'app/services/ui_notifications/tasks.rb' + - 'app/services/ui_notifications/tasks/task_bulk_cancel.rb' + - 'app/services/ui_notifications/tasks/task_bulk_resume.rb' + - 'app/services/ui_notifications/tasks/task_bulk_stop.rb' + # Offense count: 1 Lint/UselessAssignment: Exclude: - 'lib/foreman_tasks/tasks/export_tasks.rake' # Offense count: 1 -# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, Regex, IgnoreExecutableScripts, AllowedAcronyms. -# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS -Naming/FileName: +# Cop supports --auto-correct. +Minitest/AssertEmptyLiteral: Exclude: - - '*.gemspec' - - 'Gemfile' - - 'db/seeds.d/*' - - 'lib/foreman-tasks.rb' - - 'gemfile.d/foreman-tasks.rb' + - 'test/unit/cleaner_test.rb' -# Offense count: 3 +# Offense count: 2 # Configuration parameters: EnforcedStyleForLeadingUnderscores. # SupportedStylesForLeadingUnderscores: disallowed, required, optional Naming/MemoizedInstanceVariableName: @@ -52,9 +112,15 @@ Naming/MethodParameterName: # MethodDefinitionMacros: define_method, define_singleton_method Naming/PredicateName: Exclude: - - 'spec/**/*' - 'app/models/foreman_tasks/task/status_explicator.rb' +# Offense count: 2 +# Configuration parameters: MinSize. +Performance/CollectionLiteralInLoop: + Exclude: + - 'app/lib/actions/middleware/watch_delegated_proxy_sub_tasks.rb' + - 'db/seeds.d/61-foreman_tasks_bookmarks.rb' + # Offense count: 6 # Configuration parameters: Include. # Include: db/migrate/*.rb @@ -67,6 +133,7 @@ Rails/CreateTableWithTimestamps: - 'db/migrate/20151112152108_create_triggerings.rb' # Offense count: 1 +# Cop supports --auto-correct. # Configuration parameters: Include. # Include: app/**/*.rb, config/**/*.rb, db/**/*.rb, lib/**/*.rb Rails/Output: @@ -78,18 +145,47 @@ Rails/OutputSafety: Exclude: - 'app/helpers/foreman_tasks/foreman_tasks_helper.rb' -# Offense count: 2 +# Offense count: 1 +# Cop supports --auto-correct. +Rails/Pick: + Exclude: + - 'app/lib/actions/helpers/lifecycle_logging.rb' + +# Offense count: 1 +# Cop supports --auto-correct. # Configuration parameters: Include. # Include: **/Rakefile, **/*.rake Rails/RakeEnvironment: Exclude: - - 'lib/capistrano/tasks/**/*.rake' - 'lib/foreman_tasks/tasks/dynflow.rake' - - 'lib/foreman_tasks/tasks/test.rake' -# Offense count: 12 +# Offense count: 1 +# Cop supports --auto-correct. +Rails/RedundantForeignKey: + Exclude: + - 'app/models/foreman_tasks/triggering.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: separated, grouped +Style/AccessorGrouping: + Exclude: + - 'lib/foreman_tasks/task_error.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: prefer_alias, prefer_alias_method +Style/Alias: + Exclude: + - 'app/models/foreman_tasks/concerns/action_triggering.rb' + - 'app/models/foreman_tasks/task.rb' + - 'app/models/foreman_tasks/task_groups/recurring_logic_task_group.rb' + +# Offense count: 10 # Cop supports --auto-correct. -# Configuration parameters: AutoCorrect, EnforcedStyle. +# Configuration parameters: EnforcedStyle. # SupportedStyles: nested, compact Style/ClassAndModuleChildren: Exclude: @@ -98,21 +194,117 @@ Style/ClassAndModuleChildren: - 'app/models/foreman_tasks/task/status_explicator.rb' - 'app/models/foreman_tasks/task/summarizer.rb' - 'app/models/foreman_tasks/task/task_cancelled_exception.rb' - - 'app/models/setting/foreman_tasks.rb' - 'lib/foreman_tasks/dynflow/configuration.rb' - 'lib/foreman_tasks/dynflow/console_authorizer.rb' - - 'lib/foreman_tasks/dynflow/persistence.rb' - 'test/controllers/api/recurring_logics_controller_test.rb' - 'test/controllers/api/tasks_controller_test.rb' +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: IgnoredMethods. +# IgnoredMethods: ==, equal?, eql? +Style/ClassEqualityComparison: + Exclude: + - 'app/lib/actions/proxy_action.rb' + - 'app/models/foreman_tasks/task/dynflow_task.rb' + - 'lib/foreman_tasks/test_extensions.rb' + # Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: Keywords, RequireColon. +# Keywords: TODO, FIXME, OPTIMIZE, HACK, REVIEW, NOTE +Style/CommentAnnotation: + Exclude: + - 'app/models/foreman_tasks/task.rb' + +# Offense count: 14 +# Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. -# SupportedStyles: allowed_in_returns, forbidden -Style/DoubleNegation: +# SupportedStyles: compact, expanded +Style/EmptyMethod: Exclude: - - 'app/models/foreman_tasks/recurring_logic.rb' + - 'app/controllers/foreman_tasks/api/recurring_logics_controller.rb' + - 'app/controllers/foreman_tasks/api/tasks_controller.rb' + - 'app/controllers/foreman_tasks/recurring_logics_controller.rb' + - 'app/lib/actions/helpers/humanizer.rb' + - 'app/models/foreman_tasks/concerns/action_triggering.rb' + - 'test/lib/actions/middleware/keep_current_taxonomies_test.rb' + - 'test/lib/actions/middleware/keep_current_timezone_test.rb' + - 'test/lib/actions/middleware/keep_current_user_test.rb' + - 'test/unit/actions/action_with_sub_plans_test.rb' -# Offense count: 35 +# Offense count: 6 +# Cop supports --auto-correct. +Style/ExplicitBlockArgument: + Exclude: + - 'app/lib/actions/middleware/keep_current_request_id.rb' + - 'app/lib/actions/middleware/keep_current_taxonomies.rb' + - 'app/lib/actions/middleware/keep_current_timezone.rb' + - 'app/lib/actions/middleware/keep_current_user.rb' + - 'app/lib/actions/middleware/watch_delegated_proxy_sub_tasks.rb' + - 'lib/foreman_tasks.rb' + +# Offense count: 31 # Configuration parameters: MinBodyLength. Style/GuardClause: - Enabled: false + Exclude: + - 'app/lib/actions/bulk_action.rb' + - 'app/lib/actions/entry_action.rb' + - 'app/lib/actions/helpers/humanizer.rb' + - 'app/lib/actions/helpers/with_delegated_action.rb' + - 'app/lib/actions/proxy_action.rb' + - 'app/models/foreman_tasks/concerns/action_triggering.rb' + - 'app/models/foreman_tasks/concerns/user_extensions.rb' + - 'app/models/foreman_tasks/task/dynflow_task.rb' + - 'app/models/foreman_tasks/triggering.rb' + - 'db/migrate/20161003091412_add_missing_indexes.rb' + - 'db/migrate/20180216092715_use_uuid.rb' + - 'lib/foreman_tasks/dynflow/console_authorizer.rb' + - 'lib/foreman_tasks/tasks/export_tasks.rake' + - 'lib/foreman_tasks/test_extensions.rb' + - 'test/controllers/api/tasks_controller_test.rb' + +# Offense count: 2 +# Configuration parameters: MinBranchesCount. +Style/HashLikeCase: + Exclude: + - 'app/models/foreman_tasks/recurring_logic.rb' + - 'app/models/foreman_tasks/task.rb' + +# Offense count: 6 +# Configuration parameters: AllowedMethods. +# AllowedMethods: respond_to_missing? +Style/OptionalBooleanParameter: + Exclude: + - 'app/helpers/foreman_tasks/foreman_tasks_helper.rb' + - 'app/lib/actions/proxy_action.rb' + - 'app/models/foreman_tasks/task/dynflow_task.rb' + - 'lib/foreman_tasks/cleaner.rb' + - 'test/controllers/api/tasks_controller_test.rb' + - 'test/lib/actions/middleware/keep_current_request_id_test.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Style/RedundantAssignment: + Exclude: + - 'bin/dynflow-executor' + - 'lib/foreman_tasks/cleaner.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Style/RedundantBegin: + Exclude: + - 'app/models/foreman_tasks/task/dynflow_task.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Style/SlicingWithRange: + Exclude: + - 'test/unit/task_test.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowModifier. +Style/SoleNestedConditional: + Exclude: + - 'app/lib/actions/task_synchronization.rb' diff --git a/Gemfile b/Gemfile index bacea760a..37b7e4c15 100644 --- a/Gemfile +++ b/Gemfile @@ -1,20 +1,5 @@ source "https://rubygems.org" -# Declare your gem's dependencies in tasks.gemspec. -# Bundler will treat runtime dependencies like base dependencies, and -# development dependencies will be added by default to the :development group. +gemspec -gemspec :name => 'foreman-tasks' - -# Declare any dependencies that are still in development here instead of in -# your gemspec. These might include edge Rails or gems from your path or -# Git. Remember to move these dependencies to your gemspec before releasing -# your gem to rubygems.org. - -# To use debugger -# gem 'debugger' - -gem 'rubocop', '~> 0.87' -gem 'rubocop-minitest', '~> 0.9.0' -gem 'rubocop-performance', '~> 1.5.2' -gem 'rubocop-rails', '~> 2.5.2' +gem 'theforeman-rubocop', '~> 0.1.0' diff --git a/lib/foreman_tasks/tasks/export_tasks.rake b/lib/foreman_tasks/tasks/export_tasks.rake index 771fbf3b1..94437b44f 100644 --- a/lib/foreman_tasks/tasks/export_tasks.rake +++ b/lib/foreman_tasks/tasks/export_tasks.rake @@ -51,7 +51,7 @@ namespace :foreman_tasks do end def template(filename) - File.join(Gem::Specification.find_by_name('dynflow').gem_dir, 'web', 'views', "#{filename}.erb") # rubocop:disable Rails/DynamicFindBy + File.join(Gem::Specification.find_by_name('dynflow').gem_dir, 'web', 'views', "#{filename}.erb") end def erb(file, options = {}) @@ -216,7 +216,7 @@ namespace :foreman_tasks do 'javascripts/application.js', 'vendor/bootstrap/css/bootstrap.css', 'stylesheets/application.css'].each do |file| - filename = File.join(Gem::Specification.find_by_name('dynflow').gem_dir, 'web', 'assets', file) # rubocop:disable Rails/DynamicFindBy + filename = File.join(Gem::Specification.find_by_name('dynflow').gem_dir, 'web', 'assets', file) FileUtils.copy_file(filename, File.join(tmp_dir, File.basename(file))) end end