k0kubun/hamlit

View on GitHub

Showing 84 of 84 total issues

Method haml_internal_concat has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def haml_internal_concat(text = "", newline = true, indent = true)
      if haml_buffer.tabulation == 0
        haml_buffer.buffer << "#{text}#{"\n" if newline}"
      else
        haml_buffer.buffer << %[#{haml_indent if indent}#{text.to_s.gsub("\n", "\n#{haml_indent}")}#{"\n" if newline}]
Severity: Minor
Found in lib/hamlit/parser/haml_helpers.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 has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

      def build(escape_attrs, quote, format, boolean_attributes, object_ref, *hashes)
Severity: Minor
Found in lib/hamlit/attribute_builder.rb - About 45 mins to fix

    Method handle_ruby_multiline has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def handle_ruby_multiline(line)
          line.text.rstrip!
          return line unless is_ruby_multiline?(line.text)
          begin
            # Use already fetched @next_line in the first loop. Otherwise, fetch next
    Severity: Minor
    Found in lib/hamlit/parser/haml_parser.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_boolean! has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

          def build_boolean!(escape_attrs, quote, format, buf, key, value)
    Severity: Minor
    Found in lib/hamlit/attribute_builder.rb - About 45 mins to fix

      Method build_class has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

            def build_class(escape_attrs, *values)
              if values.size == 1
                value = values.first
                case
                when value.is_a?(String)
      Severity: Minor
      Found in lib/hamlit/attribute_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

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

          def compile_id!(temple, key, values)
            build_code = attribute_builder(:id, values)
            if values.all? { |type, exp| type == :static || Temple::StaticAnalyzer.static?(exp) }
              temple << [:html, :attr, key, [:static, eval(build_code).to_s]]
            else
      Severity: Minor
      Found in lib/hamlit/attribute_compiler.rb and 1 other location - About 45 mins to fix
      lib/hamlit/attribute_compiler.rb on lines 73..78

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

      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

          def compile_class!(temple, key, values)
            build_code = attribute_builder(:class, values)
            if values.all? { |type, exp| type == :static || Temple::StaticAnalyzer.static?(exp) }
              temple << [:html, :attr, key, [:static, eval(build_code).to_s]]
            else
      Severity: Minor
      Found in lib/hamlit/attribute_compiler.rb and 1 other location - About 45 mins to fix
      lib/hamlit/attribute_compiler.rb on lines 64..69

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

      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

      Consider simplifying this complex logical expression.
      Open

            unless (flat? && !closes_flat?(line) && !closes_flat?(@line)) ||
                (line_defined && @line.text[0] == ?: && line.full =~ %r[^#{@line.full[/^\s+/]}\s])
              return next_line if line.text.empty?
      
              handle_multiline(line)
      Severity: Major
      Found in lib/hamlit/parser/haml_parser.rb - About 40 mins to fix

        Method build_attributes has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

              def build_attributes(is_html, attr_wrapper, escape_attrs, hyphenate_data_attrs, attributes = {})
        Severity: Minor
        Found in lib/hamlit/parser/haml_attribute_builder.rb - About 35 mins to fix

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

                def build_data_attribute(key, escape_attrs, quote, *hashes)
                  attrs = []
                  if hashes.size > 1 && hashes.all? { |h| h.is_a?(Hash) }
                    data_value = merge_all_attrs(hashes)
                  else
          Severity: Minor
          Found in lib/hamlit/attribute_builder.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 parse_key! has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def parse_key!(tokens)
                _, type, str = tokens.shift
                case type
                when :on_sp
                  parse_key!(tokens)
          Severity: Minor
          Found in lib/hamlit/attribute_parser.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 compile has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                def compile(node, &block)
                  temple = [:multi]
                  return temple if node.children.empty?
          
                  temple << :whitespace if prepend_whitespace?(node)
          Severity: Minor
          Found in lib/hamlit/compiler/children_compiler.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 check_encoding has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def check_encoding(str)
                if str.valid_encoding?
                  # Get rid of the Unicode BOM if possible
                  # Shortcut for UTF-8 which might be the majority case
                  if str.encoding == Encoding::UTF_8
          Severity: Minor
          Found in lib/hamlit/parser/haml_util.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 plain has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def plain(line, escape_html = nil)
                if block_opened?
                  raise HamlSyntaxError.new(HamlError.message(:illegal_nesting_plain), @next_line.index)
                end
          
          
          Severity: Minor
          Found in lib/hamlit/parser/haml_parser.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 flatten_data_attributes has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                def flatten_data_attributes(data, key, join_char, seen = [])
                  return {key => data} unless data.is_a?(Hash)
          
                  return {key => nil} if seen.include? data.object_id
                  seen << data.object_id
          Severity: Minor
          Found in lib/hamlit/parser/haml_attribute_builder.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 parse_class_and_id has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def self.parse_class_and_id(list)
                attributes = {}
                return attributes if list.empty?
          
                list.scan(/([#.])([-:_a-zA-Z0-9\@]+)/) do |type, property|
          Severity: Minor
          Found in lib/hamlit/parser/haml_parser.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 try_parse_haml_emacs_magic_comment has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def try_parse_haml_emacs_magic_comment(scanner)
                pos = scanner.pos
                return unless scanner.scan(/.*?-\*-\s*/n)
                # From Ruby's parse.y
                return unless scanner.scan(/([^\s'":;]+)\s*:\s*("(?:\\.|[^"])*"|[^"\s;]+?)[\s;]*-\*-/n)
          Severity: Minor
          Found in lib/hamlit/parser/haml_util.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 comment has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def comment(text)
                if text[0..1] == '!['
                  revealed = true
                  text = text[1..-1]
                else
          Severity: Minor
          Found in lib/hamlit/parser/haml_parser.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 method.
          Open

                return name, [:static, content.first[1]] if content.size == 1
          Severity: Major
          Found in lib/hamlit/parser/haml_parser.rb - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                    return push doctype(line.text) if line.text[0, 3] == '!!!'
            Severity: Major
            Found in lib/hamlit/parser/haml_parser.rb - About 30 mins to fix
              Severity
              Category
              Status
              Source
              Language