activescaffold/active_scaffold

View on GitHub

Showing 296 of 296 total issues

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

        if (event.detail && !xhr) {
          error = event.detail[0];
          status = event.detail[1];
          xhr = event.detail[2];
        }
Severity: Major
Found in app/assets/javascripts/jquery/active_scaffold.js and 4 other locations - About 1 hr to fix
app/assets/javascripts/jquery/active_scaffold.js on lines 133..137
app/assets/javascripts/jquery/active_scaffold.js on lines 172..176
app/assets/javascripts/jquery/active_scaffold.js on lines 189..193
app/assets/javascripts/jquery/active_scaffold.js on lines 222..226

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

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

        if (event.detail && !xhr) {
          error = event.detail[0];
          status = event.detail[1];
          xhr = event.detail[2];
        }
Severity: Major
Found in app/assets/javascripts/jquery/active_scaffold.js and 4 other locations - About 1 hr to fix
app/assets/javascripts/jquery/active_scaffold.js on lines 66..70
app/assets/javascripts/jquery/active_scaffold.js on lines 133..137
app/assets/javascripts/jquery/active_scaffold.js on lines 172..176
app/assets/javascripts/jquery/active_scaffold.js on lines 222..226

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

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 action_link_html_options has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def action_link_html_options(link, record, options)
        link_id = get_action_link_id(link, record)
        html_options = link.html_options.merge(class: [link.html_options[:class], link.action.to_s].compact.join(' '))
        html_options[:link] = action_link_text(link, record, options)

Severity: Minor
Found in lib/active_scaffold/helpers/action_link_helpers.rb - About 1 hr to fix

    Method query_string_for_action_links has 32 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def query_string_for_action_links(link)
            if defined?(@query_string) && link.parameters.none? { |k, _| @query_string_params.include? k }
              return [@query_string, @non_nested_query_string]
            end
    
    
    Severity: Minor
    Found in lib/active_scaffold/helpers/action_link_helpers.rb - About 1 hr to fix

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

            def override_helper_per_model(method, model, cache_keys = nil)
              cache_keys ||= [method, model.name]
              ActiveScaffold::Registry.cache(*cache_keys) do
                model_names = [model.name]
                model_names << model.base_class.name if model.respond_to?(:base_class) && model.base_class != model
      Severity: Minor
      Found in lib/active_scaffold/helpers/view_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 set_includes_for_sorting has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def set_includes_for_sorting(columns, sorting)
            sorting.each_column do |col|
              next if sorting.constraint_columns.include? col.name
              next unless col.includes.present? && columns.exclude?(col)
      
      
      Severity: Minor
      Found in lib/active_scaffold/actions/list.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 options_for_render_super has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def options_for_render_super(options)
            options ||= {}
            options[:locals] ||= {}
            if view_stack.last
              options[:locals] = view_stack.last[:locals].merge!(options[:locals]) if view_stack.last[:locals]
      Severity: Minor
      Found in lib/active_scaffold/extensions/action_view_rendering.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 show_column_value has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

            def show_column_value(record, column)
              value_record = column.delegated_association ? record.send(column.delegated_association.name) : record
              return get_column_value(record, column) unless value_record
      
              # check for an override helper
      Severity: Minor
      Found in lib/active_scaffold/helpers/show_column_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

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

              ActiveScaffold[(element.val() == 'PAST' || element.val() == 'FUTURE') ? 'show' : 'hide'](element.attr('id').replace(/_opt/, '_trend'));
      Severity: Major
      Found in app/assets/javascripts/jquery/active_scaffold.js and 1 other location - About 1 hr to fix
      app/assets/javascripts/jquery/active_scaffold.js on lines 295..295

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

      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 find_duplicate has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def find_duplicate(link)
            links = []
            @set.each do |item|
              next if item == :separator
      
      
      Severity: Minor
      Found in lib/active_scaffold/data_structures/action_links.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 parse_time_with_format has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

            def parse_time_with_format(value, format, offset)
              format.gsub!(/%-d|%-m|%_m/) { |s| s.gsub(/[-_]/, '') } # strptime fails with %-d, %-m, %_m
              en_value = I18n.locale == :en ? value : translate_days_and_months(value, format)
              time = Time.strptime(en_value, format)
              offset ? time : Time.zone.local_to_utc(time).in_time_zone
      Severity: Minor
      Found in lib/active_scaffold/finder.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 add has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def add(action, options = {})
            link =
              if action.is_a?(ActiveScaffold::DataStructures::ActionLink) || action.is_a?(ActiveScaffold::DataStructures::ActionLinks)
                action
              else
      Severity: Minor
      Found in lib/active_scaffold/data_structures/action_links.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

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

              ActiveScaffold[(element.val() == 'null' || element.val() == 'not_null') ? 'hide' : 'show'](element.attr('id').replace(/_opt/, '_numeric'));
      Severity: Major
      Found in app/assets/javascripts/jquery/active_scaffold.js and 1 other location - About 1 hr to fix
      app/assets/javascripts/jquery/active_scaffold.js on lines 302..302

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

      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 register_constraints_with_action_columns has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def register_constraints_with_action_columns(constrained_fields = nil)
            constrained_fields ||= []
            constrained_fields |= active_scaffold_constraints.flat_map { |k, v| columns_from_constraint(k, v) }.compact
            exclude_actions = []
            %i[list update].each do |action_name|
      Severity: Minor
      Found in lib/active_scaffold/constraints.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 create_record_row has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            create_record_row: function(active_scaffold_id, html, options) {
              if (typeof(active_scaffold_id) == 'string') active_scaffold_id = '#' + active_scaffold_id;
              var tbody = jQuery(active_scaffold_id).find(options.body_selector || 'tbody.records').first(), new_row;
      
              if (options.insert_at == 'top') {
      Severity: Minor
      Found in app/assets/javascripts/jquery/active_scaffold.js - About 1 hr to fix

        Method conditions_from_params has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def conditions_from_params
              @conditions_from_params ||= begin
                conditions = [{}]
                supporting_range = %i[date datetime integer decimal float bigint]
                params.except(:controller, :action, :page, :sort, :sort_direction, :format, :id).each do |key, value|
        Severity: Minor
        Found in lib/active_scaffold/actions/core.rb - About 1 hr to fix

          Function insert has 29 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                insert: function(content) {
                  this.close_previous_adapter();
          
                  if (this.position === 'replace') {
                    this.position = 'after';
          Severity: Minor
          Found in app/assets/javascripts/jquery/active_scaffold.js - About 1 hr to fix

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

                def apply_constraints_to_record(record, options = {})
                  options[:allow_autosave] = false if options[:allow_autosave].nil?
                  constraints = options[:constraints] || active_scaffold_constraints
            
                  config = record.is_a?(active_scaffold_config.model) ? active_scaffold_config : active_scaffold_config_for(record.class)
            Severity: Minor
            Found in lib/active_scaffold/constraints.rb - About 1 hr to fix

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

                    def add_to_js_app
                      original_js = File.binread(JS_APP)
                      if original_js.match?(/^import +['"]active_scaffold['"]/)
                        say_status('skipped', "append active_scaffold to #{JS_APP}", :yellow)
                      else
              Severity: Minor
              Found in lib/generators/active_scaffold/install_generator.rb - About 1 hr to fix

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

                  def self.should_render_as_list_ui(column_name, list_ui)
                    before_block = lambda do
                      @rendered_columns = []
                      @controller.view_context_class.any_instance.expects(:"active_scaffold_column_#{list_ui}").at_least_once.with do |column, _|
                        @rendered_columns << column.name
                Severity: Major
                Found in shoulda_macros/macros.rb and 1 other location - About 1 hr to fix
                shoulda_macros/macros.rb on lines 26..36

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

                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

                Severity
                Category
                Status
                Source
                Language