ctran/annotate_models

View on GitHub
lib/annotate/annotate_models.rb

Summary

Maintainability
F
6 days
Test Coverage

File annotate_models.rb has 717 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'bigdecimal'

require 'annotate/constants'

module AnnotateModels
Severity: Major
Found in lib/annotate/annotate_models.rb - About 1 day to fix

    Method get_schema_info has a Cognitive Complexity of 64 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_schema_info(klass, header, options = {})
          info = "# #{header}\n"
          info << get_schema_header_text(klass, options)
    
          max_size = max_schema_info_width(klass, options)
    Severity: Minor
    Found in lib/annotate/annotate_models.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 get_foreign_key_info has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_foreign_key_info(klass, options = {})
          fk_info = if options[:format_markdown]
                      "#\n# ### Foreign Keys\n#\n"
                    else
                      "#\n# Foreign Keys\n#\n"
    Severity: Minor
    Found in lib/annotate/annotate_models.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 get_schema_info has 75 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def get_schema_info(klass, header, options = {})
          info = "# #{header}\n"
          info << get_schema_header_text(klass, options)
    
          max_size = max_schema_info_width(klass, options)
    Severity: Major
    Found in lib/annotate/annotate_models.rb - About 3 hrs to fix

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

          def remove_annotations(options = {})
            parse_options(options)
      
            deannotated = []
            deannotated_klass = false
      Severity: Minor
      Found in lib/annotate/annotate_models.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 annotate_model_file has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          def annotate_model_file(annotated, file, header, options)
            begin
              return false if /#{SKIP_ANNOTATION_PREFIX}.*/ =~ (File.exist?(file) ? File.read(file) : '')
              klass = get_model_class(file)
              do_annotate = klass &&
      Severity: Minor
      Found in lib/annotate/annotate_models.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 annotate_one_file has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          def annotate_one_file(file_name, info_block, position, options = {})
            return false unless File.exist?(file_name)
            old_content = File.read(file_name)
            return false if old_content =~ /#{SKIP_ANNOTATION_PREFIX}.*\n/
      
      
      Severity: Minor
      Found in lib/annotate/annotate_models.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 annotate has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def annotate(klass, file, header, options = {})
            begin
              klass.reset_column_information
              info = get_schema_info(klass, header, options)
              model_name = klass.name.underscore
      Severity: Minor
      Found in lib/annotate/annotate_models.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 get_model_files has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_model_files(options)
            model_files = []
      
            model_files = list_model_files_from_argument unless options[:is_rake]
      
      
      Severity: Minor
      Found in lib/annotate/annotate_models.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 annotate_one_file has 33 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def annotate_one_file(file_name, info_block, position, options = {})
            return false unless File.exist?(file_name)
            old_content = File.read(file_name)
            return false if old_content =~ /#{SKIP_ANNOTATION_PREFIX}.*\n/
      
      
      Severity: Minor
      Found in lib/annotate/annotate_models.rb - About 1 hr to fix

        Method annotate has 33 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def annotate(klass, file, header, options = {})
              begin
                klass.reset_column_information
                info = get_schema_info(klass, header, options)
                model_name = klass.name.underscore
        Severity: Minor
        Found in lib/annotate/annotate_models.rb - About 1 hr to fix

          Method remove_annotations has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def remove_annotations(options = {})
                parse_options(options)
          
                deannotated = []
                deannotated_klass = false
          Severity: Minor
          Found in lib/annotate/annotate_models.rb - About 1 hr to fix

            Method get_foreign_key_info has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def get_foreign_key_info(klass, options = {})
                  fk_info = if options[:format_markdown]
                              "#\n# ### Foreign Keys\n#\n"
                            else
                              "#\n# Foreign Keys\n#\n"
            Severity: Minor
            Found in lib/annotate/annotate_models.rb - About 1 hr to fix

              Method max_schema_info_width has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  def max_schema_info_width(klass, options)
                    if with_comments?(klass, options)
                      max_size = klass.columns.map do |column|
                        column.name.size + (column.comment ? width(column.comment) : 0)
                      end.max || 0
              Severity: Minor
              Found in lib/annotate/annotate_models.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 get_model_class has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  def get_model_class(file)
                    model_path = file.gsub(/\.rb$/, '')
                    model_dir.each { |dir| model_path = model_path.gsub(/^#{dir}/, '').gsub(/^\//, '') }
                    begin
                      get_loaded_model(model_path, file) || raise(BadModelFileError.new)
              Severity: Minor
              Found in lib/annotate/annotate_models.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 format_default has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def format_default(col_name, max_size, col_type, bare_type_allowance, attrs)
              Severity: Minor
              Found in lib/annotate/annotate_models.rb - About 35 mins to fix

                Method do_annotations has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    def do_annotations(options = {})
                      parse_options(options)
                
                      header = options[:format_markdown] ? PREFIX_MD.dup : PREFIX.dup
                      version = ActiveRecord::Migrator.current_version rescue 0
                Severity: Minor
                Found in lib/annotate/annotate_models.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 remove_annotation_of_file has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    def remove_annotation_of_file(file_name, options = {})
                      if File.exist?(file_name)
                        content = File.read(file_name)
                        return false if content =~ /#{SKIP_ANNOTATION_PREFIX}.*\n/
                
                
                Severity: Minor
                Found in lib/annotate/annotate_models.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 get_index_info has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    def get_index_info(klass, options = {})
                      index_info = if options[:format_markdown]
                                     "#\n# ### Indexes\n#\n"
                                   else
                                     "#\n# Indexes\n#\n"
                Severity: Minor
                Found in lib/annotate/annotate_models.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 classified_sort has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    def classified_sort(cols)
                      rest_cols = []
                      timestamps = []
                      associations = []
                      id = nil
                Severity: Minor
                Found in lib/annotate/annotate_models.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

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

                      rescue StandardError => e
                        $stderr.puts "Unable to annotate #{file}: #{e.message}"
                        $stderr.puts "\t" + e.backtrace.join("\n\t") if options[:trace]
                      end
                Severity: Minor
                Found in lib/annotate/annotate_models.rb and 1 other location - About 15 mins to fix
                lib/annotate/annotate_models.rb on lines 658..661

                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 26.

                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

                      rescue StandardError => e
                        $stderr.puts "Unable to annotate #{file}: #{e.message}"
                        $stderr.puts "\t" + e.backtrace.join("\n\t") if options[:trace]
                      end
                Severity: Minor
                Found in lib/annotate/annotate_models.rb and 1 other location - About 15 mins to fix
                lib/annotate/annotate_models.rb on lines 829..832

                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 26.

                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