sferik/rails_admin

View on GitHub

Showing 107 of 107 total issues

File filtering-select.js has 260 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import jQuery from "jquery";
import "jquery-ui/ui/widget.js";
import "jquery-ui/ui/widgets/autocomplete.js";
import I18n from "./i18n";

Severity: Minor
Found in src/rails_admin/filtering-select.js - About 2 hrs to fix

    Function _initAutocomplete has 56 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        _initAutocomplete: function () {
          var self = this;
    
          return this.input.autocomplete({
            delay: this.options.searchDelay,
    Severity: Major
    Found in src/rails_admin/filtering-select.js - About 2 hrs to fix

      Class AbstractModel has 21 methods (exceeds 20 allowed). Consider refactoring.
      Open

        class AbstractModel
          cattr_accessor :all
          attr_reader :adapter, :model_name
      
          class << self
      Severity: Minor
      Found in lib/rails_admin/abstract_model.rb - About 2 hrs to fix

        File mongoid.rb has 256 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        require 'mongoid'
        require 'rails_admin/config/sections/list'
        require 'rails_admin/adapters/mongoid/association'
        require 'rails_admin/adapters/mongoid/object_extension'
        require 'rails_admin/adapters/mongoid/property'
        Severity: Minor
        Found in lib/rails_admin/adapters/mongoid.rb - About 2 hrs to fix

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

              field = RailsAdmin::Config::Fields::Types.load(:dragonfly).new(parent, attachment_name, properties)
              children_fields = []
              extensions.each do |ext|
                children_column_name = :"#{attachment_name}_#{ext}"
                child_properties = parent.abstract_model.properties.detect { |p| p.name.to_s == children_column_name.to_s }
          Severity: Major
          Found in lib/rails_admin/config/fields/factories/dragonfly.rb and 1 other location - About 1 hr to fix
          lib/rails_admin/config/fields/factories/paperclip.rb on lines 11..25

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

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

              field = RailsAdmin::Config::Fields::Types.load(:paperclip).new(parent, attachment_name, properties)
              children_fields = []
              extensions.each do |ext|
                children_column_name = :"#{attachment_name}_#{ext}"
                child_properties = parent.abstract_model.properties.detect { |p| p.name.to_s == children_column_name.to_s }
          Severity: Major
          Found in lib/rails_admin/config/fields/factories/paperclip.rb and 1 other location - About 1 hr to fix
          lib/rails_admin/config/fields/factories/dragonfly.rb on lines 10..24

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

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

                  this.removeAll.click(function (e) {
                    widget._deSelect($("option", widget.selection));
                    e.preventDefault();
                    widget.selection.trigger("change");
                  });
          Severity: Major
          Found in src/rails_admin/filtering-multiselect.js and 1 other location - About 1 hr to fix
          src/rails_admin/filtering-multiselect.js on lines 152..156

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

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

                this.addAll.click(function (e) {
                  widget._select($("option:not(:disabled)", widget.collection));
                  e.preventDefault();
                  widget.selection.trigger("change");
                });
          Severity: Major
          Found in src/rails_admin/filtering-multiselect.js and 1 other location - About 1 hr to fix
          src/rails_admin/filtering-multiselect.js on lines 168..172

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

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

                if ($(this).has("i.fa-chevron-down").length) {
                  $(this)
                    .removeClass("active")
                    .children("i")
                    .toggleClass("fa-chevron-down fa-chevron-right");
          Severity: Major
          Found in src/rails_admin/ui.js and 1 other location - About 1 hr to fix
          src/rails_admin/ui.js on lines 47..53

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

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

                  if ($(this).has("i.fa-chevron-right").length) {
                    $(this)
                      .addClass("active")
                      .children("i")
                      .toggleClass("fa-chevron-down fa-chevron-right");
          Severity: Major
          Found in src/rails_admin/ui.js and 1 other location - About 1 hr to fix
          src/rails_admin/ui.js on lines 40..54

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

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

                def new(m)
                  m = m.constantize unless m.is_a?(Class)
                  (am = old_new(m)).model && am.adapter ? am : nil
                rescue *([LoadError, NameError] + (defined?(ActiveRecord) ? ['ActiveRecord::NoDatabaseError'.constantize, 'ActiveRecord::ConnectionNotEstablished'.constantize] : []))
                  puts "[RailsAdmin] Could not load model #{m}, assuming model is non existing. (#{$ERROR_INFO})" unless Rails.env.test?
          Severity: Minor
          Found in lib/rails_admin/abstract_model.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 _bindEvents has 42 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              _bindEvents: function () {
                var widget = this;
          
                /* Add all to selection */
                this.addAll.click(function (e) {
          Severity: Minor
          Found in src/rails_admin/filtering-multiselect.js - About 1 hr to fix

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

                  this.add.click(function (e) {
                    widget._select($(":selected", widget.collection));
            
                    e.preventDefault();
                    widget.selection.trigger("change");
            Severity: Major
            Found in src/rails_admin/filtering-multiselect.js and 1 other location - About 1 hr to fix
            src/rails_admin/filtering-multiselect.js on lines 175..179

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

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

                    this.remove.click(function (e) {
                      widget._deSelect($(":selected", widget.selection));
                      e.preventDefault();
                      widget.selection.trigger("change");
                    });
            Severity: Major
            Found in src/rails_admin/filtering-multiselect.js and 1 other location - About 1 hr to fix
            src/rails_admin/filtering-multiselect.js on lines 159..164

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

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

                def ordered_filters
                  return @ordered_filters if @ordered_filters.present?
            
                  @index = 0
                  @ordered_filters = (params[:f].try(:permit!).try(:to_h) || @model_config.list.filters).inject({}) do |memo, filter|
            Severity: Minor
            Found in app/helpers/rails_admin/main_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 generic_help has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                      def generic_help
                        text = "#{required? ? I18n.translate('admin.form.required') : I18n.translate('admin.form.optional')}. "
                        if valid_length.present? && valid_length[:is].present?
                          text += "#{I18n.translate('admin.form.char_length_of').capitalize} #{valid_length[:is]}."
                        else
            Severity: Minor
            Found in lib/rails_admin/config/fields/types/string.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 register_instance_option has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                    def register_instance_option(option_name, scope = self, &default)
                      options = scope.instance_variable_get('@config_options') ||
                                scope.instance_variable_set('@config_options', {})
            
                      option_name = option_name.to_s
            Severity: Minor
            Found in lib/rails_admin/config/configurable.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 listing_for_model_or_object has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                    def listing_for_model_or_object(model, object, query, sort, sort_reverse, all, page, per_page)
                      sort =
                        if sort.present?
                          {COLUMN_MAPPING[sort.to_sym] => sort_reverse ? :desc : :asc}
                        else
            Severity: Minor
            Found in lib/rails_admin/extensions/paper_trail/auditing_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 field has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                  def field(name, type = nil, add_to_section = true, &block)
                    field = _fields.detect { |f| name == f.name }
            
                    # some fields are hidden by default (belongs_to keys, has_many associations in list views.)
                    # unhide them if config specifically defines them
            Severity: Minor
            Found in lib/rails_admin/config/has_fields.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 symbolize has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                def self.symbolize(obj)
                  case obj
                  when Array
                    obj.each_with_object([]) do |val, res|
                      res << case val
            Severity: Minor
            Found in lib/rails_admin/support/hash_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

            Severity
            Category
            Status
            Source
            Language