TrestleAdmin/trestle

View on GitHub

Showing 35 of 62 total issues

Method admin_link_to has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
Open

    def admin_link_to(content, instance_or_url=nil, options={}, &block)
      # Block given - ignore content parameter and capture content from block
      if block_given?
        instance_or_url, options = content, instance_or_url || {}
        content = capture(&block)
Severity: Minor
Found in app/helpers/trestle/url_helper.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 initialize has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

      def initialize(admin, options={})
        super(options) do |instance|
          admin.default_form_attributes.each do |attribute|
            if attribute.array?
              if [:string, :text].include?(attribute.type)
Severity: Minor
Found in lib/trestle/form/automatic.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 autoformat_value has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

    def autoformat_value(value, options={})
      case value
      when Array
        content_tag(:ol, safe_join(value.map { |v|
          content_tag(:li, v.is_a?(Array) ? v : autoformat_value(v, options)) },
Severity: Minor
Found in app/helpers/trestle/format_helper.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 column_value has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

        def column_value(instance)
          if @column.block
            if block_is_legacy_haml?
              # In order for table column blocks to work properly within Haml templates,
              # the _hamlout local variable needs to be defined in the scope of the block,
Severity: Minor
Found in lib/trestle/table/column.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 initialize has 40 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def initialize(admin, options={})
        super(options) do |instance|
          admin.default_form_attributes.each do |attribute|
            if attribute.array?
              if [:string, :text].include?(attribute.type)
Severity: Minor
Found in lib/trestle/form/automatic.rb - About 1 hr to fix

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

        def admin_link_to(content, instance_or_url=nil, options={}, &block)
          # Block given - ignore content parameter and capture content from block
          if block_given?
            instance_or_url, options = content, instance_or_url || {}
            content = capture(&block)
    Severity: Minor
    Found in app/helpers/trestle/url_helper.rb - About 1 hr to fix

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

              def destroy
                success = delete_instance
      
                respond_to do |format|
                  format.html do
      Severity: Minor
      Found in app/controllers/concerns/trestle/resource/controller/actions.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 autoformat_value has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def autoformat_value(value, options={})
            case value
            when Array
              content_tag(:ol, safe_join(value.map { |v|
                content_tag(:li, v.is_a?(Array) ? v : autoformat_value(v, options)) },
      Severity: Minor
      Found in app/helpers/trestle/format_helper.rb - About 1 hr to fix

        Method table has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def table(name=nil, options={}, &block)
              if block_given?
                if name.is_a?(Hash)
                  options = name
                else
        Severity: Minor
        Found in app/helpers/trestle/table_helper.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 default_attributes has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

              def default_attributes
                model.columns.map do |column|
                  if column.name.end_with?("_id") && (name = column.name.sub(/_id$/, '')) && (reflection = model.reflections[name])
                    Attribute::Association.new(column.name, class: -> { reflection.klass }, name: name, polymorphic: reflection.polymorphic?, type_column: reflection.foreign_type)
                  elsif column.name.end_with?("_type") && (name = column.name.sub(/_type$/, '')) && (reflection = model.reflections[name])
        Severity: Minor
        Found in lib/trestle/adapters/active_record_adapter.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 render has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

                def render
                  content_tag(:div, options.except(*WRAPPER_OPTIONS)) do
                    concat label if name && options[:label] != false
                    concat template.capture(&block) if block
                    concat help_message if options[:help]
        Severity: Minor
        Found in lib/trestle/form/fields/form_group.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 input_group has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

                def input_group
                  if @prepend || @append
                    content_tag(:div, class: "input-group") do
                      concat content_tag(:div, input_group_addon(@prepend), class: "input-group-prepend") if @prepend
                      concat yield
        Severity: Minor
        Found in lib/trestle/form/fields/form_control.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 default_wrapper_class has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

                def default_wrapper_class
                  if custom?
                    [
                      "custom-control",
                      switch? ? "custom-switch" : "custom-checkbox",
        Severity: Minor
        Found in lib/trestle/form/fields/check_box_helpers.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 render? has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

                def render?
                  if options.key?(:if)
                    if options[:if].respond_to?(:call)
                      @template.instance_exec(&options[:if])
                    else
        Severity: Minor
        Found in lib/trestle/table/column.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 edit has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

                def edit
                  if admin.singular? && instance.nil?
                    respond_to do |format|
                      format.html { redirect_to action: :new }
                      format.json { head :not_found }
        Severity: Minor
        Found in app/controllers/concerns/trestle/resource/controller/actions.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 show has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

                def show
                  if admin.singular? && instance.nil?
                    respond_to do |format|
                      format.html { redirect_to action: :new }
                      format.json { head :not_found }
        Severity: Minor
        Found in app/controllers/concerns/trestle/resource/controller/actions.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 content_columns has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

              def content_columns
                admin.default_table_attributes.map.with_index do |attribute, index|
                  case attribute.type
                  when :association
                    Column.new(attribute.association_name, sort: false)
        Severity: Minor
        Found in lib/trestle/table/automatic.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 admin_url_for has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def admin_url_for(instance, options={})
              admin = Trestle.lookup(options.delete(:admin)) if options.key?(:admin)
              admin ||= admin_for(instance)
              return unless admin
        
        
        Severity: Minor
        Found in app/helpers/trestle/url_helper.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 page_entries_info has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def page_entries_info(collection, options = {})
              entry_name = options[:entry_name] || "entry"
              entry_name = entry_name.pluralize unless collection.total_count == 1
        
              if collection.total_pages < 2
        Severity: Minor
        Found in app/helpers/trestle/pagination_helper.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 tab has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def tab(name, options={})
              tabs[name] = tab = Tab.new(name, options)
        
              content_tag(:div, id: tab.id(("modal" if dialog_request?)), class: ["tab-pane", ('active' if name == tabs.keys.first)], role: "tabpanel") do
                if block_given?
        Severity: Minor
        Found in app/helpers/trestle/tab_helper.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

        Severity
        Category
        Status
        Source
        Language