ctran/annotate_models

View on GitHub

Showing 29 of 29 total issues

File annotate_models.rb has 713 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 add_options_to_parser has 154 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

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

      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 get_foreign_key_info has a Cognitive Complexity of 20 (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 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 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_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 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 = 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 header has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            def header(options = {})
              routes_map = app_routes_map(options)
        
              magic_comments_map, routes_map = extract_magic_comments_from_array(routes_map)
        
        
        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 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 annotate_routes has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            def annotate_routes(header, content, where_header_found, options = {})
              magic_comments_map, content = 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_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 strip_annotations has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            def strip_annotations(content)
              real_content = []
              mode = :content
              header_found_at = 0
        
        
        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 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 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 setup_options has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                def self.setup_options(options = {})
                  POSITION_OPTIONS.each do |key|
                    options[key] = fallback(ENV[key.to_s], ENV['position'], 'before')
                  end
                  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 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

              Severity
              Category
              Status
              Source
              Language