k0kubun/hamlit

View on GitHub

Showing 84 of 84 total issues

Method handle_multiline has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    def handle_multiline(line)
      return unless is_multiline?(line.text)
      line.text.slice!(-1)
      loop do
        new_line = @template.first
Severity: Minor
Found in lib/hamlit/parser/haml_parser.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 each_attr has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    def each_attr(tokens)
      attr_tokens = []
      open_tokens = Hash.new { |h, k| h[k] = 0 }

      tokens.each do |token|
Severity: Minor
Found in lib/hamlit/attribute_parser.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 compile_contents has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

      def compile_contents(node, &block)
        case
        when !node.children.empty?
          yield(node)
        when node.value[:value].nil? && self_closing?(node)
Severity: Minor
Found in lib/hamlit/compiler/tag_compiler.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 process_line has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def process_line(line)
      case line.text[0]
      when DIV_CLASS; push div(line)
      when DIV_ID
        return push plain(line) if %w[{ @ $].include?(line.text[1])
Severity: Minor
Found in lib/hamlit/parser/haml_parser.rb - About 1 hr to fix

    Method parse_new_attributes has 33 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def parse_new_attributes(text)
          scanner = StringScanner.new(text)
          last_line = @line.index + 1
          attributes = {}
    
    
    Severity: Minor
    Found in lib/hamlit/parser/haml_parser.rb - About 1 hr to fix

      Method each_attr has 33 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def each_attr(tokens)
            attr_tokens = []
            open_tokens = Hash.new { |h, k| h[k] = 0 }
      
            tokens.each do |token|
      Severity: Minor
      Found in lib/hamlit/attribute_parser.rb - About 1 hr to fix

        Method build_attributes has 33 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def build_attributes(is_html, attr_wrapper, escape_attrs, hyphenate_data_attrs, attributes = {})
                # @TODO this is an absolutely ridiculous amount of arguments. At least
                # some of this needs to be moved into an instance method.
                join_char = hyphenate_data_attrs ? '-' : '_'
        
        
        Severity: Minor
        Found in lib/hamlit/parser/haml_attribute_builder.rb - About 1 hr to fix

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

            class Filters
              class Css < TextBase
                def compile(node)
                  case @format
                  when :xhtml
          Severity: Major
          Found in lib/hamlit/filters/css.rb and 1 other location - About 1 hr to fix
          lib/hamlit/filters/javascript.rb on lines 3..29

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

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

              def compile_boolean!(temple, key, values)
                exp = literal_for(values.last)
          
                if Temple::StaticAnalyzer.static?(exp)
                  value = eval(exp)
          Severity: Minor
          Found in lib/hamlit/attribute_compiler.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

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

            class Filters
              class Javascript < TextBase
                def compile(node)
                  case @format
                  when :xhtml
          Severity: Major
          Found in lib/hamlit/filters/javascript.rb and 1 other location - About 1 hr to fix
          lib/hamlit/filters/css.rb on lines 3..29

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

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

              def next_line
                line = @template.shift || raise(StopIteration)
          
                # `flat?' here is a little outdated,
                # so we have to manually check if either the previous or current line
          Severity: Minor
          Found in lib/hamlit/parser/haml_parser.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 on_multi has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              def on_multi(*exps)
                exps = exps.dup
                result = [:multi]
                buffer = []
          
          
          Severity: Minor
          Found in lib/hamlit/dynamic_merger.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 parse_object_ref has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              def parse_object_ref(ref)
                prefix = ref[1]
                ref = ref[0]
                # Let's make sure the value isn't nil. If it is, return the default Hash.
                return {} if ref.nil?
          Severity: Minor
          Found in lib/hamlit/parser/haml_buffer.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 compute_tabs has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              def compute_tabs(line)
                return 0 if line.text.empty? || !line.whitespace
          
                if @indentation.nil?
                  @indentation = line.whitespace
          Severity: Minor
          Found in lib/hamlit/parser/haml_parser.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 balance has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              def balance(scanner, start, finish, count = 0)
                str = ''.dup
                scanner = StringScanner.new(scanner) unless scanner.is_a? StringScanner
                regexp = Regexp.new("(.*?)[\\#{start.chr}\\#{finish.chr}]", Regexp::MULTILINE)
                while scanner.scan(regexp)
          Severity: Minor
          Found in lib/hamlit/parser/haml_util.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 count_lines has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              def self.count_lines(exp)
                type, *args = exp
                case type
                when :multi
                  args.map { |a| count_lines(a) }.reduce(:+) || 0
          Severity: Minor
          Found in lib/hamlit/temple_line_counter.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 close_silent_script has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              def close_silent_script(node)
                @script_level_stack.pop if ["if", "case", "unless"].include? node.value[:keyword]
          
                # Post-process case statements to normalize the nesting of "when" clauses
                return unless node.value[:keyword] == "case"
          Severity: Minor
          Found in lib/hamlit/parser/haml_parser.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

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

                def compile_interpolated_plain(node)
                  temple = [:multi]
                  StringSplitter.compile(node.value[:value]).each do |type, value|
                    case type
                    when :static
          Severity: Minor
          Found in lib/hamlit/compiler/tag_compiler.rb and 1 other location - About 50 mins to fix
          lib/hamlit/compiler/script_compiler.rb on lines 36..46

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

          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_interpolated_plain(node)
                  temple = [:multi]
                  StringSplitter.compile(node.value[:text]).each do |type, value|
                    case type
                    when :static
          Severity: Minor
          Found in lib/hamlit/compiler/script_compiler.rb and 1 other location - About 50 mins to fix
          lib/hamlit/compiler/tag_compiler.rb on lines 57..67

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

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

              def capture_haml(*args, &block)
                buffer = eval('if defined? _hamlout then _hamlout else nil end', block.binding) || haml_buffer
                with_haml_buffer(buffer) do
                  position = haml_buffer.buffer.length
          
          
          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

          Severity
          Category
          Status
          Source
          Language