tnantoka/plate

View on GitHub

Showing 15 of 15 total issues

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

racc_action_table = [
    20,    22,    18,    19,    21,    29,    48,    63,    26,    27,
    28,    30,    31,    32,    43,    23,    18,    19,    43,    24,
    25,    67,    74,    20,    22,    18,    19,    21,    29,    18,
    19,    26,    27,    28,    30,    31,    32,    43,    23,    61,
Severity: Major
Found in lib/plate/parser.rb and 1 other location - About 1 day to fix
lib/plate/parser.rb on lines 56..83

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

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

racc_action_check = [
    72,    72,    56,    56,    72,    72,    33,    56,    72,    72,
    72,    72,    72,    72,    27,    72,    64,    64,    26,    72,
    72,    64,    72,    54,    54,    66,    66,    54,    54,    68,
    68,    54,    54,    54,    54,    54,    54,    50,    54,    52,
Severity: Major
Found in lib/plate/parser.rb and 1 other location - About 1 day to fix
lib/plate/parser.rb on lines 27..54

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

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

File parser.rb has 470 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'racc/parser.rb'

require 'plate/lexer'
require 'plate/nodes'

Severity: Minor
Found in lib/plate/parser.rb - About 7 hrs to fix

    Method tokenize has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
    Open

        def tokenize(code)
          code.chomp!
          code.gsub!(/^\s*\/\/.*\n/, '')
          self.tokens = []
    
    
    Severity: Minor
    Found in lib/plate/lexer.rb - About 6 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 test_parse has 102 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def test_parse
          nodes = Nodes.new([
            FrontMatterNode.new(front_matter),
            HeaderNode.new(
              1,
    Severity: Major
    Found in test/parser_test.rb - About 4 hrs to fix

      Method tokenize has 95 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def tokenize(code)
            code.chomp!
            code.gsub!(/^\s*\/\/.*\n/, '')
            self.tokens = []
      
      
      Severity: Major
      Found in lib/plate/lexer.rb - About 3 hrs to fix

        Method test_tokenize has 72 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def test_tokenize
              tokens = [
                [:FRONT_MATTER, front_matter], [:NEWLINE, "\n"],
                [:HEADER, '#'], [:STRING, 'Main'],
                  [:INDENT, 2],
        Severity: Major
        Found in test/lexer_test.rb - About 2 hrs to fix

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

          racc_goto_check = [
               4,     2,     1,     3,     3,    20,    20,    18,    18,    18,
              19,    21,   nil,   nil,   nil,     3,     3,    18,   nil,     3,
             nil,   nil,     4,     4,   nil,   nil,   nil,     3,     3,   nil,
             nil,    18,   nil,   nil,   nil,     3,   nil,   nil,   nil,   nil,
          Severity: Major
          Found in lib/plate/parser.rb and 1 other location - About 1 hr to fix
          lib/plate/parser.rb on lines 105..112

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

          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

          racc_goto_table = [
               4,     2,     1,    36,    39,    71,    73,    42,    44,    45,
              37,    75,   nil,   nil,   nil,    49,    50,    51,   nil,    53,
             nil,   nil,    35,    38,   nil,   nil,   nil,    58,    59,   nil,
             nil,    60,   nil,   nil,   nil,    62,   nil,   nil,   nil,   nil,
          Severity: Major
          Found in lib/plate/parser.rb and 1 other location - About 1 hr to fix
          lib/plate/parser.rb on lines 114..121

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

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

              def compile_value
                case value
                when 'blank'
                  'target="_blank"'
                when /\Abtn/
          Severity: Minor
          Found in lib/plate/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 compile has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

              def compile(compiler, parent = nil)
                if parent && parent.is_a?(StyleNode)
                  compiler.meta[name].nil? ? name : compiler.meta[name]
                elsif parent && parent.is_a?(ScriptNode)
                  name
          Severity: Minor
          Found in lib/plate/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 code has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          def code
            c = <<-EOD.strip_heredoc
              # Main
                @font-weight: normal
              ## sub
          Severity: Minor
          Found in test/test_helper.rb - About 1 hr to fix

            Method test_compile has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def test_compile
                  compiled = <<-EOD.strip_heredoc
                    <h1 style="font-weight: normal">Main</h1>
                    <h2>{{sub}}</h2>
                    <p>(Powered by <a href="https://github.com/tnantoka/plate" target="_blank" class="btn btn-default">link</a> gem.)</p>
            Severity: Minor
            Found in test/compiler_test.rb - About 1 hr to fix

              Avoid deeply nested control flow statements.
              Open

                      elsif header = chunk[/\A(#+\s*)/, 1]
                        tokens << [:HEADER, header.strip]
                        i += header.size
              
                      elsif highlight = chunk[/\A(```.+?```)/m, 1]
              Severity: Major
              Found in lib/plate/lexer.rb - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                            unless i.zero?
                              tokens << [",", ","]
                            end
                Severity: Major
                Found in lib/plate/lexer.rb - About 45 mins to fix
                  Severity
                  Category
                  Status
                  Source
                  Language