rapid7/metasploit-framework

View on GitHub
tools/dev/msftidy.rb

Summary

Maintainability
F
1 wk
Test Coverage

File msftidy.rb has 680 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'fileutils'
require 'find'
require 'time'
require 'rubocop'
require 'open3'
Severity: Major
Found in tools/dev/msftidy.rb - About 1 day to fix

    Method check_lines has a Cognitive Complexity of 73 (exceeds 5 allowed). Consider refactoring.
    Open

      def check_lines
        url_ok     = true
        no_stdio   = true
        in_comment = false
        in_literal = false
    Severity: Minor
    Found in tools/dev/msftidy.rb - About 1 day 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 check_ref_identifiers has a Cognitive Complexity of 60 (exceeds 5 allowed). Consider refactoring.
    Open

      def check_ref_identifiers
        in_super     = false
        in_refs      = false
        in_notes     = false
        cve_assigned = false
    Severity: Minor
    Found in tools/dev/msftidy.rb - About 1 day 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 MsftidyRunner has 43 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class MsftidyRunner
    
      # Status codes
      OK       = 0
      WARNING  = 1
    Severity: Minor
    Found in tools/dev/msftidy.rb - About 5 hrs to fix

      Method check_badchars has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
      Open

        def check_badchars
          badchars = %Q|&<=>|
      
          in_super   = false
          in_author  = false
      Severity: Minor
      Found in tools/dev/msftidy.rb - About 5 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 run has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
      Open

        def run(dirs, options = {})
          @exit_status = 0
      
          rubocop_runner = RuboCopRunner.new
          dirs.each do |dir|
      Severity: Minor
      Found in tools/dev/msftidy.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

      Method check_lines has 76 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def check_lines
          url_ok     = true
          no_stdio   = true
          in_comment = false
          in_literal = false
      Severity: Major
      Found in tools/dev/msftidy.rb - About 3 hrs to fix

        Method check_ref_identifiers has 71 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def check_ref_identifiers
            in_super     = false
            in_refs      = false
            in_notes     = false
            cve_assigned = false
        Severity: Major
        Found in tools/dev/msftidy.rb - About 2 hrs to fix

          Method check_badchars has 44 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def check_badchars
              badchars = %Q|&<=>|
          
              in_super   = false
              in_author  = false
          Severity: Minor
          Found in tools/dev/msftidy.rb - About 1 hr to fix

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

              def check_disclosure_date
                return if @source =~ /Generic Payload Handler/
            
                # Check disclosure date format
                if @source =~ /["']DisclosureDate["'].*\=\>[\x0d\x20]*['\"](.+?)['\"]/
            Severity: Minor
            Found in tools/dev/msftidy.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 run_checks has 33 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def run_checks
                check_shebang
                check_nokogiri
                check_rubygems
                check_msf_core
            Severity: Minor
            Found in tools/dev/msftidy.rb - About 1 hr to fix

              Method is_exploit_module? has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                def is_exploit_module?
                  ret = false
                  if @source =~ REGEX_MSF_EXPLOIT
                    # having Msf::Exploit is good indicator, but will false positive on
                    # specs and other files containing the string, but not really acting
              Severity: Minor
              Found in tools/dev/msftidy.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 check_old_keywords has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                def check_old_keywords
                  max_count = 10
                  counter   = 0
                  if @source =~ /^##/
                    @lines.each do |line|
              Severity: Minor
              Found in tools/dev/msftidy.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 check_nokogiri has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                def check_nokogiri
                  msg = "Using Nokogiri in modules can be risky, use REXML instead."
                  has_nokogiri = false
                  has_nokogiri_xml_parser = false
                  @lines.each do |line|
              Severity: Minor
              Found in tools/dev/msftidy.rb - About 55 mins 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 check_bad_super_class has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                def check_bad_super_class
                  # skip payloads, as they don't have a super class
                  return if @module_type == 'payloads'
              
                  # get the super class in an ugly way
              Severity: Minor
              Found in tools/dev/msftidy.rb - About 45 mins 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 check_self_class has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                def check_self_class
                  in_register = false
                  @lines.each do |line|
                    (in_register = true) if line =~ /^\s*register_(?:advanced_)?options/
                    (in_register = false) if line =~ /^\s*end/
              Severity: Minor
              Found in tools/dev/msftidy.rb - About 45 mins 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 check_ranking has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                def check_ranking
                  return unless is_exploit_module?
              
                  available_ranks = [
                    'ManualRanking',
              Severity: Minor
              Found in tools/dev/msftidy.rb - About 35 mins 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 check_old_rubies has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                def check_old_rubies
                  return true unless CHECK_OLD_RUBIES
                  return true unless Object.const_defined? :RVM
                  puts "Checking syntax for #{@name}."
                  rubies ||= RVM.list_strings
              Severity: Minor
              Found in tools/dev/msftidy.rb - About 25 mins 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 new_modules_for has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                def new_modules_for(commit)
                  # Example output:
                  #   M       modules/exploits/osx/local/vmware_bash_function_root.rb
                  #   A       modules/exploits/osx/local/vmware_fusion_lpe.rb
                  raw_diff_summary, status = ::Open3.capture2("git diff -b --name-status -l0 --summary #{commit}")
              Severity: Minor
              Found in tools/dev/msftidy.rb - About 25 mins 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

              Similar blocks of code found in 4 locations. Consider refactoring.
              Open

                def warn(txt, line=0) line_msg = (line>0) ? ":#{line}" : ''
                  puts "#{@full_filepath}#{line_msg} - [#{'WARNING'.yellow}] #{cleanup_text(txt)}"
                  @status = WARNING if @status < WARNING
              Severity: Major
              Found in tools/dev/msftidy.rb and 3 other locations - About 30 mins to fix
              tools/dev/msftidy.rb on lines 171..174
              tools/dev/msftidy_docs.rb on lines 66..68
              tools/dev/msftidy_docs.rb on lines 77..80

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 33.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 4 locations. Consider refactoring.
              Open

                def error(txt, line=0)
                  line_msg = (line>0) ? ":#{line}" : ''
                  puts "#{@full_filepath}#{line_msg} - [#{'ERROR'.red}] #{cleanup_text(txt)}"
                  @status = ERROR if @status < ERROR
              Severity: Major
              Found in tools/dev/msftidy.rb and 3 other locations - About 30 mins to fix
              tools/dev/msftidy.rb on lines 160..162
              tools/dev/msftidy_docs.rb on lines 66..68
              tools/dev/msftidy_docs.rb on lines 77..80

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 33.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Identical blocks of code found in 2 locations. Consider refactoring.
              Open

                def info(txt, line=0)
                  return if SUPPRESS_INFO_MESSAGES
                  line_msg = (line>0) ? ":#{line}" : ''
                  puts "#{@full_filepath}#{line_msg} - [#{'INFO'.cyan}] #{cleanup_text(txt)}"
              Severity: Minor
              Found in tools/dev/msftidy.rb and 1 other location - About 25 mins to fix
              tools/dev/msftidy_docs.rb on lines 92..95

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 30.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Identical blocks of code found in 2 locations. Consider refactoring.
              Open

                def fixed(txt, line=0)
                  line_msg = (line>0) ? ":#{line}" : ''
                  puts "#{@full_filepath}#{line_msg} - [#{'FIXED'.green}] #{cleanup_text(txt)}"
              Severity: Minor
              Found in tools/dev/msftidy.rb and 1 other location - About 20 mins to fix
              tools/dev/msftidy_docs.rb on lines 84..86

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 27.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Identical blocks of code found in 4 locations. Consider refactoring.
              Open

              class String
                def red
                  "\e[1;31;40m#{self}\e[0m"
                end
              
              
              Severity: Minor
              Found in tools/dev/msftidy.rb and 3 other locations - About 15 mins to fix
              tools/dev/check_external_scripts.rb on lines 30..44
              tools/dev/msftidy_docs.rb on lines 17..31
              tools/dev/update_wordpress_vulnerabilities.rb on lines 25..39

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 25.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Identical blocks of code found in 2 locations. Consider refactoring.
              Open

                def initialize(source_file)
                  @full_filepath = source_file
                  @module_type = File.dirname(File.expand_path(@full_filepath))[/\/modules\/([^\/]+)/, 1]
                  @source  = load_file(source_file)
                  @lines   = @source.lines # returns an enumerator
              Severity: Minor
              Found in tools/dev/msftidy.rb and 1 other location - About 15 mins to fix
              tools/dev/msftidy_docs.rb on lines 48..54

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 25.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              There are no issues that match your filters.

              Category
              Status