Skip to content

Commit

Permalink
style: code cleanup (nanego#317)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-brousse authored Jan 30, 2025
1 parent ae4dd00 commit ce2797e
Show file tree
Hide file tree
Showing 58 changed files with 69 additions and 135 deletions.
39 changes: 0 additions & 39 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,6 @@ Layout/ArgumentAlignment:
- 'app/queries/frames/including_servers_query.rb'
- 'db/migrate/20180110152701_add_attributes_to_servers.rb'

# Offense count: 28
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: empty_lines, no_empty_lines
Layout/EmptyLinesAroundBlockBody:
Exclude:
- 'app/controllers/servers_grids_controller.rb'
- 'app/helpers/servers_helper.rb'
- 'db/migrate/20160318101235_create_connections.rb'
- 'db/migrate/20160318103009_create_ports.rb'
- 'db/migrate/20160411154022_init_coupled_baies.rb'
- 'lib/tasks/fix_duplicated_slots.rake'
- 'lib/tasks/init_pdus.rake'
- 'lib/tasks/update_pdu_lines.rake'
- 'lib/tasks/update_position_by_name.rake'

# Offense count: 24
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
Expand Down Expand Up @@ -727,13 +711,6 @@ Style/RedundantConstantBase:
Exclude:
- 'config/environments/production.rb'

# Offense count: 4
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: SafeForConstants.
Style/RedundantFetchBlock:
Exclude:
- 'config/puma.rb'

# Offense count: 13
# This cop supports safe autocorrection (--autocorrect).
Style/RedundantFreeze:
Expand Down Expand Up @@ -853,14 +830,6 @@ Style/StringLiteralsInInterpolation:
- 'app/helpers/servers_helper.rb'
- 'app/models/islet.rb'

# Offense count: 68
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: .
# SupportedStyles: percent, brackets
Style/SymbolArray:
EnforcedStyle: percent
MinSize: 12

# Offense count: 10
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowMethodsWithArguments, AllowedMethods, AllowedPatterns, AllowComments.
Expand Down Expand Up @@ -899,14 +868,6 @@ Style/TrailingCommaInHashLiteral:
- 'lib/tasks/convert_activities_to_changelog_entries.rake'
- 'spec/components/previews/list/data_table_component_preview.rb'

# Offense count: 7
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: WordRegex.
# SupportedStyles: percent, brackets
Style/WordArray:
EnforcedStyle: percent
MinSize: 5

# Offense count: 91
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/architectures_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class ArchitecturesController < ApplicationController
before_action :set_architecture, only: [:show, :edit, :update, :destroy]
before_action :set_architecture, only: %i[show edit update destroy]

# GET /architectures
# GET /architectures.json
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/bays_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class BaysController < ApplicationController
include RoomsHelper

before_action :set_bay, only: [:edit, :update, :destroy, :show]
before_action :set_bay, only: %i[edit update destroy show]

def index
@filter = ProcessorFilter.new(Bay.joins(:room, :islet).order('rooms.position, islets.name, bays.lane, bays.position'), params)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/cables_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class CablesController < ApplicationController

def index
@cables = Cable.includes(:connections,
connections: [:port, :server, :card],
connections: %i[port server card],
cards: [:card_type],
card_types: [:port_type])
.order(created_at: :desc)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/card_types_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class CardTypesController < ApplicationController
before_action :set_card_type, only: [:show, :edit, :update, :destroy]
before_action :set_card_type, only: %i[show edit update destroy]

def index
@filter = ProcessorFilter.new(CardType.sorted, params)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/categories_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class CategoriesController < ApplicationController
before_action :set_category, only: [:show, :edit, :update, :destroy]
before_action :set_category, only: %i[show edit update destroy]

# GET /categories
# GET /categories.json
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/colors_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class ColorsController < ApplicationController
before_action :set_color, only: [:show, :edit, :update, :destroy]
before_action :set_color, only: %i[show edit update destroy]

def index
@colors = sorted Color.order('parent_type asc, parent_id asc')
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/disk_types_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class DiskTypesController < ApplicationController
before_action :set_disk_type, only: [:show, :edit, :update, :destroy]
before_action :set_disk_type, only: %i[show edit update destroy]

# GET /disk_types
# GET /disk_types.json
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/disks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class DisksController < ApplicationController
before_action :set_disk, only: [:show, :edit, :update, :destroy]
before_action :set_disk, only: %i[show edit update destroy]

# GET /disks
# GET /disks.json
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/documents_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class DocumentsController < ApplicationController
before_action :set_document, only: [:show, :edit, :update, :destroy]
before_action :set_document, only: %i[show edit update destroy]

def index
@documents = Document.all
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/domaines_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class DomainesController < ApplicationController
before_action :set_domaine, only: [:show, :edit, :update, :destroy]
before_action :set_domaine, only: %i[show edit update destroy]

# GET /domaines
# GET /domaines.json
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/external_app_records_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def settings
end

def sync_all_servers_with_glpi
if ExternalAppRequest.exists?(status: ["pending", "in_progress"], external_app_name: "glpi")
if ExternalAppRequest.exists?(status: %w[pending in_progress], external_app_name: "glpi")
render json: { error: "Another request is already in progress" }
else
request = ExternalAppRequest.create!(status: :pending, user: current_user, external_app_name: "glpi")
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/gestions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class GestionsController < ApplicationController
before_action :set_gestion, only: [:show, :edit, :update, :destroy]
before_action :set_gestion, only: %i[show edit update destroy]

# GET /gestions
# GET /gestions.json
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/islets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class IsletsController < ApplicationController
include RoomsHelper

before_action :set_islet, only: [:show, :edit, :update, :destroy, :print]
before_action :set_islet, only: %i[show edit update destroy print]
before_action :set_room, only: %i[show print]
before_action :set_servers_per_frames, only: %i[show print]

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/manufacturers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class ManufacturersController < ApplicationController
before_action :set_manufacturer, only: [:show, :edit, :update, :destroy]
before_action :set_manufacturer, only: %i[show edit update destroy]

# GET /manufacturers
# GET /manufacturers.json
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/memory_components_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class MemoryComponentsController < ApplicationController
before_action :set_memory_component, only: [:show, :edit, :update, :destroy]
before_action :set_memory_component, only: %i[show edit update destroy]

# GET /memory_components
# GET /memory_components.json
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/memory_types_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class MemoryTypesController < ApplicationController
before_action :set_memory_type, only: [:show, :edit, :update, :destroy]
before_action :set_memory_type, only: %i[show edit update destroy]

# GET /memory_types
# GET /memory_types.json
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/modeles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class ModelesController < ApplicationController
include ModelesHelper

before_action :set_modele, only: [:show, :edit, :update, :destroy]
before_action :set_modele, only: %i[show edit update destroy]

def index
@filter = ProcessorFilter.new(Modele.includes(:category, :enclosures).order(:name), params)
Expand Down Expand Up @@ -104,7 +104,7 @@ def modele_params
network_types: [],
enclosures_attributes: [
:id, :modele_id, :_destroy, :position, :display, :grid_areas,
composants_attributes: [:type_composant_id, :enclosure_id, :name, :position, :_destroy, :id],
composants_attributes: %i[type_composant_id enclosure_id name position _destroy id],
]
)
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/moves_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

class MovesController < ApplicationController
before_action :set_move, only: [:show, :edit, :update, :destroy, :execute_movement]
before_action :load_form_data, only: [:new, :edit]
before_action :set_move, only: %i[show edit update destroy execute_movement]
before_action :load_form_data, only: %i[new edit]
before_action :set_frame_updated, only: %i[frame print]

def index
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/port_types_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class PortTypesController < ApplicationController
before_action :set_port_type, only: [:show, :edit, :update, :destroy]
before_action :set_port_type, only: %i[show edit update destroy]

def index
@port_types = sorted PortType.order('lower(name)')
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/server_states_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class ServerStatesController < ApplicationController
before_action :set_server_state, only: [:show, :edit, :update, :destroy]
before_action :set_server_state, only: %i[show edit update destroy]

# GET /server_states
# GET /server_states.json
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/servers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class ServersController < ApplicationController
include ServersHelper

before_action :set_server, only: [:show, :edit, :update, :destroy, :destroy_connections]
before_action :set_server, only: %i[show edit update destroy destroy_connections]

def index
# Let server knows that now name is not used anymore for research
Expand Down Expand Up @@ -127,7 +127,7 @@ def destroy_connections

# Use callbacks to share common setup or constraints between actions.
def set_server
@server = Server.where('lower(numero) = ?', params[:id].to_s.downcase).includes(:cards => [:ports => [:connection, :cable], :card_type => [:port_type]]).first
@server = Server.where('lower(numero) = ?', params[:id].to_s.downcase).includes(:cards => [:ports => %i[connection cable], :card_type => [:port_type]]).first
@server = Server.friendly.find(params[:id].to_s.downcase) unless @server
end

Expand All @@ -136,10 +136,10 @@ def server_params
params.require(:server).permit(:photo, :stack_id, :server_state_id, :comment, :cluster_id, :position, :frame_id, :gestion_id, :fc_futur, :rj45_cm, :name, :modele_id, :numero, :critique, :domaine_id, :fc_total, :fc_utilise, :rj45_total, :rj45_utilise, :rj45_futur, :ipmi_utilise, :ipmi_futur, :ipmi_dedie,
:frame, # TODO: Check if it should be removed or if it's used somewhere
network_types: [],
:cards_attributes => [:composant_id, :card_type_id, :_destroy, :id, :twin_card_id, :orientation, :name, :first_position],
:disks_attributes => [:quantity, :disk_type_id, :_destroy, :id],
:memory_components_attributes => [:quantity, :memory_type_id, :_destroy, :id],
:documents_attributes => [:document, :id, :_destroy])
:cards_attributes => %i[composant_id card_type_id _destroy id twin_card_id orientation name first_position],
:disks_attributes => %i[quantity disk_type_id _destroy id],
:memory_components_attributes => %i[quantity memory_type_id _destroy id],
:documents_attributes => %i[document id _destroy])
end

def search_params
Expand Down
1 change: 0 additions & 1 deletion app/controllers/servers_grids_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def index
@servers = ServersGrid.new(params[:servers_grid])
logger.error ex.message
end

end
format.csv do
@servers = ServersGrid.new(params.to_unsafe_h[:servers_grid])
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/sites_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class SitesController < ApplicationController
before_action :set_site, only: [:show, :edit, :update, :destroy]
before_action :set_site, only: %i[show edit update destroy]

def index
@sites = sorted Site.sorted
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/stacks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class StacksController < ApplicationController
before_action :set_stack, only: [:show, :edit, :update, :destroy]
before_action :set_stack, only: %i[show edit update destroy]

# GET /stacks
# GET /stacks.json
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/visualization/frames_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def print
private

def set_frame
@frame = Frame.includes(servers: [modele: [:category, :composants],
@frame = Frame.includes(servers: [modele: %i[category composants],
cards: [:composant,
{ ports: [connection: [cable: :connections]],
card_type: [:port_type] },]],
Expand Down
5 changes: 1 addition & 4 deletions app/helpers/servers_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def ports_by_card_minimal(card:)
html += "<td><div class='d-flex'>"

ports_per_cell.times do |cell_index|

position = get_current_position(card.orientation, card_type, cell_index, row_index, column_index, ports_per_cell)
port_data = card.ports.detect { |p| p.position == position }
port_id = port_data.try(:id)
Expand All @@ -42,7 +41,6 @@ def ports_by_card_minimal(card:)
if (cell_index + 1) % number_of_columns_in_cell(card.orientation, ports_per_cell, card_type.max_aligned_ports) == 0 # Every XX ports do
html += '</div><div class="d-flex">'
end

end

html += "</div></td>"
Expand All @@ -65,7 +63,6 @@ def ports_by_card_with_presentation(card:, selected_port: nil, moved_connections
html += "<td><div class='d-flex'>"

ports_per_cell.times do |cell_index|

position = get_current_position(card.orientation, card_type, cell_index, row_index, column_index, ports_per_cell)
port_data = card.ports.detect { |p| p.position == position }
port_id = port_data.try(:id)
Expand Down Expand Up @@ -137,7 +134,7 @@ def link_to_port(position, port_data, port_type, card_id, port_id, default_label

def link_to_port_by_type(label, type, port_data, position, card_id, port_id)
edit_port_url = port_id ? connections_edit_path(from_port_id: port_id) : edit_port_path(id: 0, card_id: card_id, position: position)
if ['RJ', 'XRJ', 'FC', 'ALIM'].include? type
if %w[RJ XRJ FC ALIM].include? type
port_class = type
else
port_class = "SCSI"
Expand Down
2 changes: 1 addition & 1 deletion app/models/bay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Bay < ApplicationRecord
has_changelog
acts_as_list scope: [:lane, :islet_id]
acts_as_list scope: %i[lane islet_id]

belongs_to :bay_type
belongs_to :islet
Expand Down
2 changes: 1 addition & 1 deletion app/models/composant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Composant < ApplicationRecord
has_changelog
acts_as_list scope: [:enclosure_id, :type_composant_id]
acts_as_list scope: %i[enclosure_id type_composant_id]

belongs_to :enclosure
belongs_to :type_composant
Expand Down
2 changes: 1 addition & 1 deletion app/models/disk_type.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class DiskType < ApplicationRecord
UNITS = ["Tb", "Gb"]
UNITS = %w[Tb Gb]
TECHNOLOGIES = ["", "SSD"]

has_changelog
Expand Down
2 changes: 1 addition & 1 deletion app/models/external_app_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ExternalAppRequest < ApplicationRecord
scope :in_progress, -> { where(status: :in_progress) }
scope :completed, -> { where(status: :completed) }
scope :failed, -> { where(status: :failed) }
scope :running, -> { where(status: [:pending, :in_progress]) }
scope :running, -> { where(status: %i[pending in_progress]) }

private

Expand Down
Loading

0 comments on commit ce2797e

Please sign in to comment.