ctran/annotate_models

View on GitHub

Showing 32 of 32 total issues

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

require 'bigdecimal'

require 'annotate/constants'
require_relative 'annotate_models/file_patterns'

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

    Method add_options_to_parser has 208 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def add_options_to_parser(option_parser) # rubocop:disable Metrics/MethodLength
          has_set_position = {}
    
          option_parser.banner = 'Usage: annotate [options] [model_file]*'
    
    
    Severity: Major
    Found in lib/annotate/parser.rb - About 1 day to fix

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

          def get_attributes(column, column_type, klass, options)
            attrs = []
            attrs << "default(#{schema_default(klass, column)})" unless column.default.nil? || hide_default?(column_type, options)
            attrs << 'unsigned' if column.respond_to?(:unsigned?) && column.unsigned?
            attrs << 'not null' unless column.null
      Severity: Minor
      Found in lib/annotate/annotate_models.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 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 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.is_a?(Class) &&
      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 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 get_schema_info has a Cognitive Complexity of 16 (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 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_routes has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def annotate_routes(header, content, header_position, options = {})
            magic_comments_map, content = Helpers.extract_magic_comments_from_array(content)
            if %w(before top).include?(options[:position_in_routes])
              header = header << '' if content.first != ''
              magic_comments_map << '' if magic_comments_map.any?
      Severity: Minor
      Found in lib/annotate/annotate_routes.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_schema_info has 40 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: Minor
      Found in lib/annotate/annotate_models.rb - About 1 hr to fix

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

          def self.set_defaults(options = {})
            return if @has_set_defaults
            @has_set_defaults = true
        
            options = ActiveSupport::HashWithIndifferentAccess.new(options)
        Severity: Minor
        Found in lib/annotate.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 strip_annotations has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

              def strip_annotations(content)
                real_content = []
                mode = :content
                header_position = 0
        
        
        Severity: Minor
        Found in lib/annotate/annotate_routes/helpers.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 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 get_attributes has 33 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def get_attributes(column, column_type, klass, options)
              attrs = []
              attrs << "default(#{schema_default(klass, column)})" unless column.default.nil? || hide_default?(column_type, options)
              attrs << 'unsigned' if column.respond_to?(:unsigned?) && column.unsigned?
              attrs << 'not null' unless column.null
        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 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 setup_options has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                def self.setup_options(options = {})
                  Constants::POSITION_OPTIONS.each do |key|
                    options[key] = Annotate::Helpers.fallback(ENV[key.to_s], ENV['position'], 'before')
                  end
                  Constants::FLAG_OPTIONS.each do |key|
              Severity: Minor
              Found in lib/annotate.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 generate has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                  def generate
                    magic_comments_map, contents_without_magic_comments = Helpers.extract_magic_comments_from_array(routes_map)
              
                    out = []
              
              
              Severity: Minor
              Found in lib/annotate/annotate_routes/header_generator.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 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
                Severity
                Category
                Status
                Source
                Language