locomotivecms/engine

View on GitHub

Showing 91 of 169 total issues

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

    def create(email_or_account)
      _account = if email_or_account.respond_to?(:email)
        email_or_account
      else
        Locomotive::Account.find_by_email(email_or_account)
Severity: Minor
Found in app/services/locomotive/membership_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 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 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 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

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

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

            def find_layout
              return if !self.allow_layout? || self.layout_id
    
              if self.raw_template =~ EXTENDS_FULLPATH_REGEX
                # first in the current locale
    Severity: Minor
    Found in app/models/locomotive/concerns/page/layout.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 sync_relationships_order_by_for_belongs_to_fields has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

            def sync_relationships_order_by_for_belongs_to_fields
              current_class_name = self.klass_with_custom_fields(:entries).name
    
              self.entries_custom_fields.where(type: 'belongs_to').each do |field|
                target_content_type = self.class_name_to_content_type(field.class_name)
    Severity: Minor
    Found in app/models/locomotive/concerns/content_type/sync.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 persist_editable_elements! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def persist_editable_elements!(page, parsed)
          modified_pages, pages = [], { page._id => page } # group modifications by page
    
          parsed[:elements].map! do |couple|
            _page, attributes = couple
    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 signalExpandShowModal has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      signalExpandShowModal() {
        const { onExpandEvent, currentState: { link, selectionText } } = this.props;
        const { linkTargetOption } = this.state;
        onExpandEvent();
        this.setState({
    Severity: Minor
    Found in app/javascript/src/locomotive/editor/components/draft/link.jsx - 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 vignette_url has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

            def vignette_url
              if self.image?
                # In some case (like an invalid extension) the height, width can be nill
                # In that case we should directly return the url
                if self.width && self.height && self.width < 85 && self.height < 85
    Severity: Minor
    Found in app/models/locomotive/concerns/asset/vignette.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