DavyJonesLocker/client_side_validations

View on GitHub

Showing 13 of 17 total issues

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

      def client_side_hash(model, attribute, force = nil)
        options = self.options.dup
        hash    = options_hash(model, attribute, options)

        @@option_map.each do |option, message_type|
Severity: Minor
Found in lib/client_side_validations/active_model/numericality.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 add has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      add: ($element, settings, message) => {
        const element = $element[0]

        const form = element.form

Severity: Minor
Found in src/core.js - About 1 hr to fix

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

          def client_side_hash(model, attribute, force = nil)
            options = self.options.dup
            if options[:with].respond_to?(:call)
              return unless force
    
    
    Severity: Minor
    Found in lib/client_side_validations/active_model/format.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

    Function add has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

          add: ($element, settings, message) => {
            const element = $element[0]
    
            const form = element.form
    
    
    Severity: Minor
    Found in src/core.js - 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 client_side_hash has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

          def client_side_hash(model, attribute, _force = nil)
            options = self.options.dup
            hash    = options_hash(options)
    
            self.class::MESSAGES.each do |option, message_type|
    Severity: Minor
    Found in lib/client_side_validations/active_model/length.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 build_validation_options has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

            def build_validation_options(method, options = {})
              return unless @options[:validate]
    
              index       = @default_options[:index].present? ? "[#{@default_options[:index]}]" : ''
              child_index = @options[:child_index] ? "(\\d+|#{Regexp.escape(@options[:child_index].to_s)})" : '\\d+'
    Severity: Minor
    Found in lib/client_side_validations/action_view/form_builder.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 check_record has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

            def check_record(record, options)
              case record
              when String, Symbol
                raise ClientSideValidations::ActionView::Helpers::FormHelper::Error, 'Using form_for(:name, @resource) is not supported with ClientSideValidations. Please use form_for(@resource, as: :name) instead.'
              else
    Severity: Minor
    Found in lib/client_side_validations/action_view/form_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 2 locations. Consider refactoring.
    Open

    export const removeClass = (element, customClass) => {
      if (customClass) {
        element.classList.remove(...customClass.split(' '))
      }
    }
    Severity: Minor
    Found in src/utils.js and 1 other location - About 40 mins to fix
    src/utils.js on lines 1..5

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

    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

    export const addClass = (element, customClass) => {
      if (customClass) {
        element.classList.add(...customClass.split(' '))
      }
    }
    Severity: Minor
    Found in src/utils.js and 1 other location - About 40 mins to fix
    src/utils.js on lines 28..32

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

    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 form_tag_with_validators has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

            def form_tag_with_validators(scope, model, options, url, &block)
    Severity: Minor
    Found in lib/client_side_validations/action_view/form_with_helper.rb - About 35 mins to fix

      Method client_side_validation_hash has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

            def client_side_validation_hash(force = nil)
              _validators.inject({}) do |attr_hash, attr|
                next attr_hash if ATTRIBUTES_DENYLIST.include?(attr[0])
      
                validator_hash = validator_hash_for(attr, force)
      Severity: Minor
      Found in lib/client_side_validations/active_model.rb - About 25 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 validator_hash_for has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

            def validator_hash_for(attr, force)
              attr[1].each_with_object(Hash.new { |h, k| h[k] = [] }) do |validator, kind_hash|
                next unless can_use_for_client_side_validation?(attr[0], validator, force)
      
                client_side_hash = validator.client_side_hash(self, attr[0], extract_force_option(attr[0], force))
      Severity: Minor
      Found in lib/client_side_validations/active_model.rb - About 25 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 check_conditionals has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

            def check_conditionals(attr, validator, force)
              return true if validator.options[:if] && will_save_change?(validator.options[:if])
      
              result = can_force_validator?(attr, validator, force)
      
      
      Severity: Minor
      Found in lib/client_side_validations/active_model.rb - About 25 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