tnantoka/plate

View on GitHub

Showing 11 of 15 total issues

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

          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