aadlani/nanoc-toolbox

View on GitHub

Showing 11 of 11 total issues

Method render_menu has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

    def render_menu(items, options={})
      options[:depth]            ||= 3
      options[:collection_tag]   ||= 'ol'
      options[:collection_class] ||= 'menu'
      options[:item_tag]         ||= 'li'
Severity: Minor
Found in lib/nanoc/toolbox/helpers/navigation.rb - About 2 hrs 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 run has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    def run(content, arguments={})
      require 'nokogiri'

      # Parse
      doc = Nokogiri::HTML.fragment(content)
Severity: Minor
Found in lib/nanoc/toolbox/filters/add_sections.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 run has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def run(content, arguments={})
      require 'nokogiri'

      # Parse
      doc = Nokogiri::HTML.fragment(content)
Severity: Minor
Found in lib/nanoc/toolbox/filters/add_sections.rb - About 1 hr to fix

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

        def find_toc_sections(section, section_xpath, title_level=1)
          return {} unless section.xpath(section_xpath)
    
          # For each section found call the find_toc_sections on it with an
          # increased header level (ex: h1 => h2) and then generate the hash res
    Severity: Minor
    Found in lib/nanoc/toolbox/helpers/navigation.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

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

          def clean_options(options={})
            # remove unsupported options
            options.delete_if {|key, value| !AVAILABLE_OPTIONS.include?(key) }
    
            # remove empty options
    Severity: Minor
    Found in lib/nanoc/toolbox/helpers/gravatar.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

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

    module Nanoc::Toolbox::Helpers  
      # NANOC Helper for the Google Analytics JS to add at the end of the layout.
      #
      # This module contains helper functions to generate the JS code snipet
      # used to track your site analytics by simply entering your tracking ID as 
    Severity: Minor
    Found in lib/nanoc/toolbox/helpers/google_analytics.rb and 1 other location - About 30 mins to fix
    lib/nanoc/toolbox/helpers/google_ua.rb on lines 3..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 33.

    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

    module Nanoc::Toolbox::Helpers
      # NANOC Helper for the Google Universal Analytics JS to add at the end of the
      # layout.
      #
      # This module contains helper functions to generate the JS code snipet
    Severity: Minor
    Found in lib/nanoc/toolbox/helpers/google_ua.rb and 1 other location - About 30 mins to fix
    lib/nanoc/toolbox/helpers/google_analytics.rb on lines 3..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 33.

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

        def find_breadcrumbs_trail(root)
          trail = ["/"]
          root.split('/').each { |s| trail << trail.last + "#{s}/" unless s.empty? }
          trail.map do |child_identifier|
            child = @items[child_identifier]
    Severity: Minor
    Found in lib/nanoc/toolbox/helpers/navigation.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 gist has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def gist(gist_id, filename=nil)
          raise ArgumentError, "Gist ID should be a hex number" unless (gist_id.to_s).match(/^\h+$/)
          url = "#{GIST_HOST}/#{gist_id}.#{GIST_EXT}"
    
          if filename
    Severity: Minor
    Found in lib/nanoc/toolbox/helpers/github_gist.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 tag_links_for has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def tag_links_for(item, omit_tags=[], options={})
          tags = []
          return tags unless item[:tags]
    
          options[:tag_pattern]     ||= "%%tag%%"
    Severity: Minor
    Found in lib/nanoc/toolbox/helpers/tagging_extra.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_item_tree has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def find_item_tree(root, options={})
          return nil unless root.children
    
          # filter the elements to contain only the kind requested
          children = options[:kind] ? root.children.select { |item| item[:kind] == options[:kind] } : root.children
    Severity: Minor
    Found in lib/nanoc/toolbox/helpers/navigation.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