locomotivecms/engine

View on GitHub

Showing 91 of 169 total issues

Method set_raw_template has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

        def set_raw_template
          return unless site

          site.with_default_locale do
            if layout_id == 'parent'
Severity: Minor
Found in app/models/locomotive/concerns/page/layout.rb - About 35 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 bubble_fields_errors_up has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def bubble_fields_errors_up
      return if self.errors[:entries_custom_fields].empty?

      self.entries_custom_fields.each do |field|
        next if field.errors.blank?
Severity: Minor
Found in app/models/locomotive/content_type.rb - About 35 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_index has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def render_index
      if @editable_elements
        @editable_elements_by_block = parsing_service.group_and_sort_editable_elements(@editable_elements)
        @blocks = parsing_service.blocks_from_grouped_editable_elements(@editable_elements_by_block)
      end
Severity: Minor
Found in app/controllers/locomotive/editable_elements_controller.rb - About 35 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 order_by_definition has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

        def order_by_definition(reverse_order = false)
          direction = self.order_manually? ? 'asc' : self.order_direction || 'asc'

          if reverse_order
            direction = (direction == 'asc' ? 'desc' : 'asc')
Severity: Minor
Found in app/models/locomotive/concerns/content_type/order_by.rb - About 35 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 sanitize_attributes! has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def sanitize_attributes!(attributes)
      # needed to get the custom fields
      _entry = content_type.entries.build

      # if the user deletes all the entries of a many_to_many field,
Severity: Minor
Found in app/services/locomotive/content_entry_service.rb - About 35 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 cast_metafields has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

        def cast_metafields(namespace)
          return nil if namespace.blank? || !has_metafields?

          schema = self.metafields_schema.find { |s| s['name'] == namespace }
          values = self.metafields[namespace]
Severity: Minor
Found in app/models/locomotive/concerns/site/metafields.rb - About 35 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 7 (exceeds 5 allowed). Consider refactoring.
Open

    def update(site, attributes, raise_if_not_valid = false)
      site.attributes = attributes

      new_locales = site.locales_changed? ? site.locales - site.locales_was : nil
      previous_default_locale = site.default_locale_was
Severity: Minor
Found in app/services/locomotive/site_service.rb - About 35 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_tree has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    def build_tree
      pages, page_not_found = pages_with_minimun_attributes, nil

      [].tap do |tree|
        while page = pages.shift
Severity: Minor
Found in app/services/locomotive/page_tree_service.rb - About 35 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

Avoid too many return statements within this function.
Open

    return null;
Severity: Major
Found in app/javascript/src/locomotive/editor/hoc/with_editing_section.js - About 30 mins to fix

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

            def method_missing(name, *args, &block)
              if field = find_field(name)
                if respond_to?(:"set_#{field.type}")
                  public_send(:"set_#{field.type}", field, args.first)
                else
    Severity: Minor
    Found in app/api/locomotive/api/forms/content_entry_form.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 filename_or_image has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def filename_or_image
          if object.persisted? && persisted_file?
            css = "current-file #{persisted_file.image? ? 'image' : ''}"
            template.content_tag :span, (image_html + filename_html).html_safe, class: css
          else
    Severity: Minor
    Found in app/inputs/locomotive/file_input.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 create has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def create(attributes, raise_if_not_valid = false)
          if attributes[:handle].blank?
            attributes[:handle] = unique_handle
          end
    
    
    Severity: Minor
    Found in app/services/locomotive/site_service.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 encoded? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

            def encoded?(hash)
              return false if hash.empty?
              if hash.keys.size > 1
                keys = hash.keys.map{|i| i.to_i if i.respond_to?(:to_i)}.sort
                keys == hash.keys.size.times.to_a
    Severity: Minor
    Found in app/api/locomotive/api/middlewares/params_decoder_middleware.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

    Function buildSectionOptions has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

    const buildSectionOptions = (findSectionDefinition, sections) => {
      return compact((sections || []).map(section => {
        // unknown section type, can happen if the data are messed up (first deployment)
        if (section.type === null) return null;
    
    
    Severity: Minor
    Found in app/javascript/src/locomotive/editor/views/pickers/urls/main.js - 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 next_or_previous has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

            def next_or_previous(matcher = :gt)
              # the matchers is supposed to be fine for the default direction, meaning 'asc'
              # if the direction is not ascending, we need to reverse the matcher
              matcher = matcher == :gt ? :lt : :gt if self.content_type.order_direction != 'asc'
    
    
    Severity: Minor
    Found in app/models/locomotive/concerns/content_entry/next_previous.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 normalize_slug has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

            def normalize_slug(field)
              value = self.send(field)
    
              if self.slug.blank? && value.present?
                self.slug = value.clone
    Severity: Minor
    Found in app/models/locomotive/concerns/shared/slug.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

    Function findBetterImageAndText has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

    export function findBetterImageAndText(sectionContent, definition) {
      var image = null, text = null;
    
      if (!definition.keep_icon) {
        image = findFirstSettingValueOf('image_picker', sectionContent, definition);
    Severity: Minor
    Found in app/javascript/src/locomotive/editor/services/sections_service.js - 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 ensure_class_name_security has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

            def ensure_class_name_security(field)
              if field.class_name =~ /^Locomotive::ContentEntry([a-z0-9]+)$/
                # if the content type does not exist (anymore), bypass the security checking
                content_type = Locomotive::ContentType.find($1) rescue return
    
    
    Severity: Minor
    Found in app/models/locomotive/concerns/content_type/class_helpers.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 subscribe_to_sections has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def subscribe_to_sections(sections)
          ActiveSupport::Notifications.subscribe('steam.parse.section') do |name, start, finish, id, payload|
            page, block, attributes = payload[:page], payload[:block], payload[:attributes]
    
            if attributes[:is_dropzone]
    Severity: Minor
    Found in app/services/locomotive/page_parsing_service.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

    Function _build has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

    const _build = (tree, prefix, routes) => {
      return transform(tree, (result, value, key) => {
        const path = `${prefix}${key}`;
    
        if (typeof(value) === 'object') {
    Severity: Minor
    Found in app/javascript/src/locomotive/editor/utils/routes_builder.js - 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