Skip to content

Commit

Permalink
Rubocop
Browse files Browse the repository at this point in the history
- Use Foreman action
- Fix Rubocop auto corrections
- Add .rubocop_todo.yml
  • Loading branch information
stejskalleos committed Mar 14, 2024
1 parent ec715a3 commit 768ae14
Show file tree
Hide file tree
Showing 33 changed files with 554 additions and 329 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ concurrency:
cancel-in-progress: true

jobs:
test:
rubocop:
name: Rubocop
uses: theforeman/actions/.github/workflows/rubocop.yml@v0

test_ruby:
name: Ruby
needs: rubocop
uses: theforeman/actions/.github/workflows/foreman_plugin.yml@v0
with:
plugin: foreman_azure_rm
25 changes: 25 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
inherit_from: .rubocop_todo.yml

AllCops:
NewCops: enable

Layout/LineLength:
Enabled: false

Metrics:
Enabled: false

Style/HashSyntax:
EnforcedStyle: no_mixed_keys

Style/SymbolArray:
EnforcedStyle: brackets

Style/Documentation:
Enabled: false

Style/StringLiterals:
Enabled: false

Style/FrozenStringLiteralComment:
Enabled: false
129 changes: 129 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-03-14 09:55:55 UTC using RuboCop version 1.50.2.
# 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
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Severity, Include.
# Include: **/*.gemspec
Gemspec/DeprecatedAttributeAssignment:
Exclude:
- 'foreman_azure_rm.gemspec'

# Offense count: 1
# Configuration parameters: EnforcedStyle, AllowedGems, Include.
# SupportedStyles: Gemfile, gems.rb, gemspec
# Include: **/*.gemspec, **/Gemfile, **/gems.rb
Gemspec/DevelopmentDependencies:
Exclude:
- 'foreman_azure_rm.gemspec'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Severity, Include.
# Include: **/*.gemspec
Gemspec/RequireMFA:
Exclude:
- 'foreman_azure_rm.gemspec'

# Offense count: 1
# Configuration parameters: Severity, Include.
# Include: **/*.gemspec
Gemspec/RequiredRubyVersion:
Exclude:
- 'foreman_azure_rm.gemspec'

# Offense count: 1
# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches.
Lint/DuplicateBranch:
Exclude:
- 'app/models/foreman_azure_rm/azure_rm.rb'

# Offense count: 4
Lint/DuplicateMethods:
Exclude:
- 'app/models/foreman_azure_rm/azure_rm_compute.rb'

# Offense count: 2
Lint/NoReturnInBeginEndBlocks:
Exclude:
- 'app/models/foreman_azure_rm/azure_rm_compute.rb'

# Offense count: 1
Lint/RescueException:
Exclude:
- 'app/helpers/azure_compute_resource_helper.rb'

# Offense count: 1
Lint/ShadowingOuterLocalVariable:
Exclude:
- 'app/models/foreman_azure_rm/azure_rm.rb'

# Offense count: 1
# Configuration parameters: AllowedPatterns.
# AllowedPatterns: (?-mix:(exactly|at_least|at_most)\(\d+\)\.times)
Lint/UnreachableLoop:
Exclude:
- 'lib/foreman_azure_rm/azure_sdk_adapter.rb'

# Offense count: 8
Lint/UselessAssignment:
Exclude:
- 'app/helpers/azure_compute_resource_helper.rb'
- 'app/models/concerns/foreman_azure_rm/vm_extensions/managed_vm.rb'
- 'app/models/foreman_azure_rm/azure_rm.rb'
- 'app/models/foreman_azure_rm/azure_rm_compute.rb'
- 'lib/foreman_azure_rm/azure_sdk_adapter.rb'

# Offense count: 1
# Configuration parameters: CheckForMethodsWithNoSideEffects.
Lint/Void:
Exclude:
- 'test/azure_rm_test_helper.rb'

# Offense count: 1
Naming/AccessorMethodName:
Exclude:
- 'lib/foreman_azure_rm/azure_sdk_adapter.rb'

# Offense count: 4
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to
Naming/MethodParameterName:
Exclude:
- 'app/helpers/azure_compute_resource_helper.rb'
- 'app/models/foreman_azure_rm/azure_rm.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/CollectionCompact:
Exclude:
- 'app/models/foreman_azure_rm/azure_rm.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Style/IfUnlessModifier:
Exclude:
- 'app/models/foreman_azure_rm/azure_rm.rb'

# Offense count: 1
Style/MultilineBlockChain:
Exclude:
- 'app/models/foreman_azure_rm/azure_rm.rb'

# Offense count: 3
Style/OpenStructUse:
Exclude:
- 'app/models/foreman_azure_rm/azure_rm.rb'
- 'app/models/foreman_azure_rm/azure_rm_compute.rb'

# Offense count: 3
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: MinSize.
# SupportedStyles: percent, brackets
Style/SymbolArray:
EnforcedStyle: percent
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0.6
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec
gemspec
8 changes: 5 additions & 3 deletions Rakefile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env rake
# frozen_string_literal: true

begin
require 'bundler/setup'
rescue LoadError
Expand All @@ -20,7 +22,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_files.include('lib/**/*.rb')
end

APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)

Bundler::GemHelper.install_tasks

Expand All @@ -38,10 +40,10 @@ task default: :test
begin
require 'rubocop/rake_task'
RuboCop::RakeTask.new
rescue => _
rescue StandardError => _e
puts 'Rubocop not loaded.'
end

task :default do
Rake::Task['rubocop'].execute
end
end
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ForemanAzureRm
module Concerns
module ComputeResourcesControllerExtensions
Expand All @@ -7,45 +9,45 @@ module ComputeResourcesControllerExtensions
update_api(:create, :update) do
param :compute_resource, Hash do
# Not adding :tenant as already specified in core.
param :app_ident, String, :desc => N_("Client ID for AzureRm")
param :secret_key, String, :desc => N_("Client Secret for AzureRm")
param :sub_id, String, :desc => N_("Subscription ID for AzureRm")
param :cloud, String, :desc => N_("Cloud")
param :app_ident, String, desc: N_('Client ID for AzureRm')
param :secret_key, String, desc: N_('Client Secret for AzureRm')
param :sub_id, String, desc: N_('Subscription ID for AzureRm')
param :cloud, String, desc: N_('Cloud')
end
end

def available_resource_groups
compute_resource = ComputeResource.find_by_id(params[:id])
@available_resource_groups = compute_resource.available_resource_groups
render :available_resource_groups, :layout => 'api/v2/layouts/index_layout'
render :available_resource_groups, layout: 'api/v2/layouts/index_layout'
end

def available_sizes
compute_resource = ComputeResource.find_by_id(params[:id])
@available_sizes = compute_resource.vm_sizes(params[:region_id])
render :available_sizes, :layout => 'api/v2/layouts/index_layout'
render :available_sizes, layout: 'api/v2/layouts/index_layout'
end

def available_subnets
compute_resource = ComputeResource.find_by_id(params[:id])
@available_subnets = compute_resource.available_subnets
render :available_subnets, :layout => 'api/v2/layouts/index_layout'
render :available_subnets, layout: 'api/v2/layouts/index_layout'
end

def available_vnets
compute_resource = ComputeResource.find_by_id(params[:id])
@available_vnets = compute_resource.available_vnets
render :available_vnets, :layout => 'api/v2/layouts/index_layout'
render :available_vnets, layout: 'api/v2/layouts/index_layout'
end

def action_permission
case params[:action]
when 'available_resource_groups', 'available_sizes', 'available_subnets', 'available_vnets'
:view
else
super
when 'available_resource_groups', 'available_sizes', 'available_subnets', 'available_vnets'
:view
else
super
end
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ForemanAzureRm
module Concerns
module HostsControllerExtensions
Expand All @@ -6,10 +8,10 @@ module HostsControllerExtensions
def sizes
azure_rm_resource = ComputeResource.unscoped.find_by_id(params[:compute_resource_id])
if azure_rm_resource.present?
render :json => azure_rm_resource.vm_sizes.map { |size| size.name }
render json: azure_rm_resource.vm_sizes.map(&:name)
else
no_sizes = _('The region you selected has no sizes associated with it')
render :json => "[\"#{no_sizes}\"]"
render json: "[\"#{no_sizes}\"]"
end
end

Expand All @@ -18,14 +20,14 @@ def subnets
if azure_rm_resource.present?
subnets = azure_rm_resource.subnets
if subnets.present?
render :json => subnets
render json: subnets
else
no_subnets = _('The selected region has no subnets')
render :json => "[\"#{no_subnets}\"]"
render json: "[\"#{no_subnets}\"]"
end
else
no_compute = _('The selected image has no associated compute resource')
render :json => "[\"#{no_compute}\"]"
render json: "[\"#{no_compute}\"]"
end
end
end
Expand Down
14 changes: 9 additions & 5 deletions app/helpers/azure_compute_resource_helper.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
# frozen_string_literal: true

module AzureComputeResourceHelper
def regions_list(azurerm_cr, f)
begin
regions = azurerm_cr.regions || []
rescue StandardError
#do nothing
# do nothing
regions = []
rescue Exception => ex
return information_box("Regions could not be loaded due to exception: #{ex}")
rescue Exception => e
return information_box("Regions could not be loaded due to exception: #{e}")
end
selectable_f(f, :url, regions, {}, {:label => _('Azure Region'), :disabled => regions.empty?, :required => true, :help_inline_permanent => load_button_f(f, regions.present?, _("Load Regions")) })
selectable_f(f, :url, regions, {},
{ label: _('Azure Region'), disabled: regions.empty?, required: true, help_inline_permanent: load_button_f(f, regions.present?, _('Load Regions')) })
end

def azure_doc_version
doc_version = Foreman::Plugin.find(:foreman_azure_rm).version.scan(/\d+\.\d+/).first + '.x'
doc_version = "#{Foreman::Plugin.find(:foreman_azure_rm).version.scan(/\d+\.\d+/).first}.x"
end
end
Loading

0 comments on commit 768ae14

Please sign in to comment.