TrestleAdmin/trestle

View on GitHub

Showing 54 of 69 total issues

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

module Trestle
  class Form
    module Fields
      class TimeSelect < Field
        attr_reader :html_options
Severity: Major
Found in lib/trestle/form/fields/time_select.rb and 2 other locations - About 1 hr to fix
lib/trestle/form/fields/date_select.rb on lines 1..20
lib/trestle/form/fields/datetime_select.rb on lines 1..20

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

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

Method autoformat_value has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def autoformat_value(value, **options)
      case value
      when Array
        tag.ol(safe_join(value.map { |v|
          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 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
              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

    Function _rgbToHsl has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      _rgbToHsl (r, g, b) {
        r /= 255
        g /= 255
        b /= 255
    
    

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

          def table(name=nil, collection: nil, **options, &block)
            if block_given?
              table = Table::Builder.build(**options, &block)
            else
              if name.is_a?(Trestle::Table)
      Severity: Minor
      Found in app/helpers/trestle/table_helper.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 input_group has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

              def input_group
                if @prepend || @append
                  tag.div(class: "input-group") do
                    concat input_group_addon(@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 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 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 initialize has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

              def initialize(builder, template, name, value=nil, options={}, &block)
      Severity: Minor
      Found in lib/trestle/form/fields/static_field.rb - About 45 mins to fix

        Method method_missing has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

              def method_missing(name, *args, &block)
                target = @form.respond_to?(name) ? @form : @template
        
                if block_given? && !RAW_BLOCK_HELPERS.include?(name)
                  result = target.send(name, *args) do |*blockargs|
        Severity: Minor
        Found in lib/trestle/form/renderer.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 admin_url_for has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def admin_url_for(instance=nil, admin: nil, action: nil, raise: false, **params)
              target = lookup_admin_from_options(
                instance: instance,
                admin: admin,
                fallback: self&.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 lookup_admin_from_options has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def lookup_admin_from_options(instance: nil, admin: nil, fallback: nil, raise: true)
              if admin
                result = Trestle.lookup(admin)
              elsif instance
                result = Trestle.lookup_model(instance.class) || fallback
        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 update has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

                def update
                  if update_instance
                    respond_to do |format|
                      flash[:message] = flash_message("update.success", title: "Success!", message: "The %{lowercase_model_name} was successfully updated.")
        
        
        Severity: Minor
        Found in app/controllers/concerns/trestle/resource/controller/actions.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)
        
              tag.div(id: tab.id(("modal" if modal_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

        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

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

          add () {
            this.itemTargets.forEach((item) => {
              item.classList.add(this.classValue)
            })
          }
        Severity: Minor
        Found in frontend/js/controllers/toggle_class_controller.js and 2 other locations - About 40 mins to fix
        frontend/js/controllers/toggle_class_controller.js on lines 10..14
        frontend/js/controllers/toggle_class_controller.js on lines 22..26

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

        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 3 locations. Consider refactoring.
        Open

          remove () {
            this.itemTargets.forEach((item) => {
              item.classList.remove(this.classValue)
            })
          }
        Severity: Minor
        Found in frontend/js/controllers/toggle_class_controller.js and 2 other locations - About 40 mins to fix
        frontend/js/controllers/toggle_class_controller.js on lines 10..14
        frontend/js/controllers/toggle_class_controller.js on lines 16..20

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

        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 3 locations. Consider refactoring.
        Open

          toggle () {
            this.itemTargets.forEach((item) => {
              item.classList.toggle(this.classValue)
            })
          }
        Severity: Minor
        Found in frontend/js/controllers/toggle_class_controller.js and 2 other locations - About 40 mins to fix
        frontend/js/controllers/toggle_class_controller.js on lines 16..20
        frontend/js/controllers/toggle_class_controller.js on lines 22..26

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

        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

        Method initialize has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

              def initialize(template, label, instance_or_url=nil, **options, &block)
        Severity: Minor
        Found in lib/trestle/toolbar/item.rb - About 35 mins to fix
          Severity
          Category
          Status
          Source
          Language