theforeman/foreman

View on GitHub

Showing 722 of 1,271 total issues

File audits_helper.rb has 367 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module AuditsHelper
  AUDIT_ADD = 'add'
  AUDIT_REMOVE = 'remove'

  # lookup the Model representing the numerical id and return its label
Severity: Minor
Found in app/helpers/audits_helper.rb - About 4 hrs to fix

    File Layout.fixtures.js has 365 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    const mockOnClick = jest.fn();
    
    const subItemsA = [
      {
        title: 'Aa',

      Method id_to_label has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
      Open

        def id_to_label(name, change, audit: @audit, truncate: true)
          return _("N/A") if change.nil?
          case name
            when "ancestry"
              label = change.blank? ? "" : change.split('/').map { |i| Hostgroup.find(i).name rescue _("N/A") }.join('/')
      Severity: Minor
      Found in app/helpers/audits_helper.rb - About 4 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      File form_helper.rb has 362 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      module FormHelper
        def text_f(f, attr, options = {})
          field(f, attr, options) do
            addClass options, "form-control"
            options[:focus_on_load] = true if options[:focus_on_load].nil? && attr.to_s == 'name'
      Severity: Minor
      Found in app/helpers/form_helper.rb - About 4 hrs to fix

        File compute_resource.rb has 360 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        class ComputeResource < ApplicationRecord
          audited :except => [:attrs]
          include Taxonomix
          include Encryptable
          include Authorizable
        Severity: Minor
        Found in app/models/compute_resource.rb - About 4 hrs to fix

          Method try_to_login has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
          Open

            def self.try_to_login(login, password, api_request = false)
              # Make sure no one can sign in with an empty password
              return nil if password.to_s.empty?
          
              # user is already in local database
          Severity: Minor
          Found in app/models/user.rb - About 4 hrs to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function get has 114 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            get: async url => {
              if (url === '/api/v2/roles?per_page=all&search=locked=false') {
                return {
                  data: {
                    total: 3,

            File subnet.rb has 353 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            require 'ipaddr'
            
            class Subnet < ApplicationRecord
              audited
              IP_FIELDS = [:network, :mask, :gateway, :dns_primary, :dns_secondary, :from, :to]
            Severity: Minor
            Found in app/models/subnet.rb - About 4 hrs to fix

              File host_edit_interfaces.js has 351 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              $(document).ready(function() {
                $('#host_name').select();
                $('#host_name').focus();
              });
              
              
              Severity: Minor
              Found in app/assets/javascripts/host_edit_interfaces.js - About 4 hrs to fix

                Method set_taxonomy has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
                Open

                  def set_taxonomy
                    TopbarSweeper.expire_cache
                    user = User.current
                    return if user.nil?
                
                
                Severity: Minor
                Found in app/controllers/concerns/application_shared.rb - About 4 hrs to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Class FactParser has 33 methods (exceeds 20 allowed). Consider refactoring.
                Open

                class FactParser
                  delegate :logger, :to => :Rails
                  VIRTUAL = /\A([a-z0-9]+)[_|.|:]([a-z0-9]+)\Z/
                  BRIDGES = /\A(vir|lxc)?br(\d+|-[a-z0-9]+)(_nic)?\Z/
                  BONDS = /\A(bond\d+)\Z|\A(lagg\d+)\Z/
                Severity: Minor
                Found in app/services/fact_parser.rb - About 4 hrs to fix

                  Class Filter has 32 methods (exceeds 20 allowed). Consider refactoring.
                  Open

                  class Filter < ApplicationRecord
                    audited :associated_with => :role
                  
                    include Taxonomix
                    include Authorizable
                  Severity: Minor
                  Found in app/models/filter.rb - About 4 hrs to fix

                    Class TemplateSnapshotService has 32 methods (exceeds 20 allowed). Consider refactoring.
                    Open

                      class TemplateSnapshotService
                        TEMPLATES_DIRECTORY = Rails.root.join('app', 'views', 'unattended', 'provisioning_templates')
                    
                        def self.templates
                          new.templates
                    Severity: Minor
                    Found in app/services/foreman/template_snapshot_service.rb - About 4 hrs to fix

                      File application_controller.rb has 332 lines of code (exceeds 250 allowed). Consider refactoring.
                      Open

                      class ApplicationController < ActionController::Base
                        include ApplicationShared
                      
                        include Foreman::Controller::Flash
                        include Foreman::Controller::Authorize
                      Severity: Minor
                      Found in app/controllers/application_controller.rb - About 4 hrs to fix

                        File lookup_keys.js has 330 lines of code (exceeds 250 allowed). Consider refactoring.
                        Open

                        //on load
                        $(document).on('ContentLoad', function() {
                          //select the first tab
                          select_first_tab();
                          $(document).on('click', '.nav-tabs a[data-toggle="tab"]', function() {
                        Severity: Minor
                        Found in app/assets/javascripts/lookup_keys.js - About 3 hrs to fix

                          File application_helper.rb has 329 lines of code (exceeds 250 allowed). Consider refactoring.
                          Open

                          module ApplicationHelper
                            def link_to_function(name, function, html_options = {})
                              onclick_tag = "#{html_options[:onclick]}; " if html_options[:onclick]
                              onclick = "#{onclick_tag}#{function}; return false;"
                              href = html_options[:href] || '#'
                          Severity: Minor
                          Found in app/helpers/application_helper.rb - About 3 hrs to fix

                            File operatingsystem.rb has 326 lines of code (exceeds 250 allowed). Consider refactoring.
                            Open

                            require 'ostruct'
                            require 'uri'
                            
                            class Operatingsystem < ApplicationRecord
                              audited
                            Severity: Minor
                            Found in app/models/operatingsystem.rb - About 3 hrs to fix

                              Method load has 95 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                  def self.load
                                    Manager.map :header_menu
                              
                                    Manager.map :side_menu do |menu|
                                      menu.sub_menu :user_menu, :caption => N_('User'), :icon => 'fa fa-user' do
                              Severity: Major
                              Found in app/registries/menu/loader.rb - About 3 hrs to fix

                                Method setComputeDetails has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
                                Open

                                  def setComputeDetails
                                    if vm
                                      attrs = compute_resource.provided_attributes
                                
                                      attrs.each do |foreman_attr, fog_attr|
                                Severity: Minor
                                Found in app/models/concerns/orchestration/compute.rb - About 3 hrs to fix

                                Cognitive Complexity

                                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                A method's cognitive complexity is based on a few simple rules:

                                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                • Code is considered more complex for each "break in the linear flow of the code"
                                • Code is considered more complex when "flow breaking structures are nested"

                                Further reading

                                File index.js has 321 lines of code (exceeds 250 allowed). Consider refactoring.
                                Open

                                /* eslint-disable max-lines */
                                import React, { useState, useEffect, useCallback } from 'react';
                                import { useSelector, useDispatch } from 'react-redux';
                                
                                import {
                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language