puppetlabs/facter

View on GitHub

Showing 117 of 386 total issues

File file_loader.rb has 921 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'open3'
require 'json'
require 'yaml'
require 'hocon'
require 'hocon/config_value_factory'
Severity: Major
Found in lib/facter/framework/core/file_loader.rb - About 2 days to fix

    File config.rb has 401 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    module Facter
      module Config
        unless defined?(OS_HIERARCHY)
          OS_HIERARCHY = [
            {
    Severity: Minor
    Found in lib/facter/config.rb - About 5 hrs to fix

      Method read_interfaces has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
      Open

              def self.read_interfaces
                ksize = Libc.getkerninfo(KINFO_RT_IFLIST, nil, nil, 0)
      
                log.debug('getkerninfo call was unsuccessful') if ksize.zero?
      
      
      Severity: Minor
      Found in lib/facter/resolvers/aix/ffi/ffi_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 facter.rb has 307 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      require 'pathname'
      require_relative 'util/api_debugger' if ENV['API_DEBUG']
      
      require_relative 'facter/version'
      require_relative 'facter/framework/core/file_loader'
      Severity: Minor
      Found in lib/facter.rb - About 3 hrs to fix

        Method which has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
        Open

                def which(bin)
                  # `echo` is allowed for facter 3.x compatibility, otherwise
                  # all commands much be found on the PATH or absolute.
                  return bin if /^echo$/i.match?(bin)
        
        
        Severity: Minor
        Found in lib/facter/custom_facts/core/execution/windows.rb - About 2 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

        Method read_interfaces has 58 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                def self.read_interfaces
                  ksize = Libc.getkerninfo(KINFO_RT_IFLIST, nil, nil, 0)
        
                  log.debug('getkerninfo call was unsuccessful') if ksize.zero?
        
        
        Severity: Major
        Found in lib/facter/resolvers/aix/ffi/ffi_helper.rb - About 2 hrs to fix

          Method read_facts has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
          Open

                    def read_facts
                      FILE_PATHS.each do |key, file|
                        @fact_list[:disks].each do |disk, value|
                          file_path = File.join(DIR, disk, file)
          
          
          Severity: Minor
          Found in lib/facter/resolvers/disks.rb - About 2 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 Log has 21 methods (exceeds 20 allowed). Consider refactoring.
          Open

            class Log
              @@logger = nil
              @@message_callback = nil
              @@has_errors = false
              @@debug_messages = []
          Severity: Minor
          Found in lib/facter/framework/logging/logger.rb - About 2 hrs to fix

            Class Collection has 21 methods (exceeds 20 allowed). Consider refactoring.
            Open

                class Collection
                  def initialize(internal_loader, external_loader)
                    @facts = {}
                    @internal_loader = internal_loader
                    @external_loader = external_loader
            Severity: Minor
            Found in lib/facter/custom_facts/util/collection.rb - About 2 hrs to fix

              Method search_dhclient_leases has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
              Open

                        def search_dhclient_leases(interface_name)
                          @log.debug("Attempt to get DHCP for interface #{interface_name}, from dhclient leases")
              
                          DIRS.each do |dir|
                            next unless File.readable?(dir)
              Severity: Minor
              Found in lib/facter/util/linux/dhcp.rb - About 1 hr 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

              Method add_flags has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
              Open

                        def add_flags
                          flags = Facter::Util::Linux::IfInet6.read_flags
                          flags.each_pair do |iface, ips|
                            next unless @fact_list[:interfaces].key?(iface)
              
              
              Severity: Minor
              Found in lib/facter/resolvers/linux/networking.rb - About 1 hr 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

              Method load_for_os has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
              Open

                  def load_for_os(operating_system)
                    # select only classes
                    classes = ClassDiscoverer.instance.discover_classes(operating_system)
                    classes.each do |class_name|
                      fact_name = class_name::FACT_NAME
              Severity: Minor
              Found in lib/facter/framework/core/fact_loaders/internal_fact_loader.rb - About 1 hr 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

              Method execute_command has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
              Open

                      def execute_command(command, on_fail = nil, logger = nil, timeout = nil)
                        timeout ||= DEFAULT_EXECUTION_TIMEOUT
                        begin
                          # Set LC_ALL and LANG to force i18n to C for the duration of this exec;
                          # this ensures that any code that parses the
              Severity: Minor
              Found in lib/facter/custom_facts/core/execution/base.rb - About 1 hr 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

              Method parse_commit has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
              Open

                def parse_commit(commit)
                  prs = client.commit_pulls('puppetlabs/facter', commit.sha, { accept: 'application/vnd.github.groot-preview+json' })
              
                  prs.each do |pr|
                    next if pr[:state] != 'closed' && pr[:merged_at].nil?
              Severity: Minor
              Found in scripts/generate_changelog.rb - About 1 hr 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

              Method find_in_interfaces has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
              Open

                          def find_in_interfaces(interfaces)
                            return if interfaces.nil?
              
                            interfaces.each do |iface_name, interface|
                              interface[:bindings]&.each do |binding|
              Severity: Minor
              Found in lib/facter/util/resolvers/networking/primary_interface.rb - About 1 hr 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

              Method execute_command has 37 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                      def execute_command(command, on_fail = nil, logger = nil, timeout = nil)
                        timeout ||= DEFAULT_EXECUTION_TIMEOUT
                        begin
                          # Set LC_ALL and LANG to force i18n to C for the duration of this exec;
                          # this ensures that any code that parses the
              Severity: Minor
              Found in lib/facter/custom_facts/core/execution/base.rb - About 1 hr to fix

                Method call_the_resolver has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                        def call_the_resolver
                          provider = case Facter::Util::Facts::Posix::VirtualDetector.platform
                                     when 'hyperv'
                                       metadata = Facter::Resolvers::Az.resolve(:metadata)
                                       'azure' unless metadata.nil? || metadata.empty?
                Severity: Minor
                Found in lib/facter/facts/linux/cloud/provider.rb - About 1 hr 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

                Method deep_merge has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                      def deep_merge(left, right, path = [])
                        ret = nil
                
                        if left.is_a?(Hash) && right.is_a?(Hash)
                          ret = left.merge(right) do |key, left_val, right_val|
                Severity: Minor
                Found in lib/facter/custom_facts/util/values.rb - About 1 hr 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

                Method retrieve_vserver has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                        def retrieve_vserver
                          proc_status_content = Facter::Util::FileHelper.safe_readlines('/proc/self/status', nil)
                          return unless proc_status_content
                
                          proc_status_content.each do |line|
                Severity: Minor
                Found in lib/facter/resolvers/virt_what.rb - About 1 hr 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

                Method search has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                    def search(json_data, searched_element, path)
                      # we hit a dead end, the os was not found on this branch
                      # and we cannot go deeper
                      return unless json_data
                
                
                Severity: Minor
                Found in lib/facter/framework/detector/os_hierarchy.rb - About 1 hr 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

                Severity
                Category
                Status
                Source
                Language