lib/rdoc/parser/ripper_state_lex.rb

Summary

Maintainability
F
4 days
Test Coverage

File ripper_state_lex.rb has 533 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'ripper'

##
# Wrapper for Ripper lex states

Severity: Major
Found in lib/rdoc/parser/ripper_state_lex.rb - About 1 day to fix

    Class InnerStateLex has 35 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class InnerStateLex < Ripper::Filter
        attr_accessor :lex_state
    
        def initialize(code)
          @lex_state = EXPR_BEG
    Severity: Minor
    Found in lib/rdoc/parser/ripper_state_lex.rb - About 4 hrs to fix

      Method get_squashed_tk has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
      Open

        def get_squashed_tk
          if @buf.empty?
            tk = @tokens.shift
          else
            tk = @buf.shift
      Severity: Minor
      Found in lib/rdoc/parser/ripper_state_lex.rb - About 3 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 get_squashed_tk has 48 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def get_squashed_tk
          if @buf.empty?
            tk = @tokens.shift
          else
            tk = @buf.shift
      Severity: Minor
      Found in lib/rdoc/parser/ripper_state_lex.rb - About 1 hr to fix

        Method get_string_tk has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

          private def get_string_tk(tk)
            string = tk[:text]
            state = nil
            kind = :on_tstring
            loop do
        Severity: Minor
        Found in lib/rdoc/parser/ripper_state_lex.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 get_symbol_tk has 44 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          private def get_symbol_tk(tk)
            is_symbol = true
            symbol_tk = Token.new(tk.line_no, tk.char_no, :on_symbol)
            if ":'" == tk[:text] or ':"' == tk[:text] or tk[:text].start_with?('%s')
              tk1 = get_string_tk(tk)
        Severity: Minor
        Found in lib/rdoc/parser/ripper_state_lex.rb - About 1 hr to fix

          Method on_op has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

              def on_op(tok, data)
                case tok
                when '&', '|', '!', '!=', '!~'
                  case @lex_state
                  when EXPR_FNAME, EXPR_DOT
          Severity: Minor
          Found in lib/rdoc/parser/ripper_state_lex.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 get_words_tk has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
          Open

            private def get_words_tk(tk)
              string = ''
              start_token = tk[:text]
              start_quote = tk[:text].rstrip[-1]
              line_no = tk[:line_no]
          Severity: Minor
          Found in lib/rdoc/parser/ripper_state_lex.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_op has 38 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def on_op(tok, data)
                case tok
                when '&', '|', '!', '!=', '!~'
                  case @lex_state
                  when EXPR_FNAME, EXPR_DOT
          Severity: Minor
          Found in lib/rdoc/parser/ripper_state_lex.rb - About 1 hr to fix

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

              private def get_heredoc_tk(heredoc_name, indent)
                string = ''
                start_tk = nil
                prev_tk = nil
                until heredoc_end?(heredoc_name, indent, tk = @tokens.shift) do
            Severity: Minor
            Found in lib/rdoc/parser/ripper_state_lex.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 get_words_tk has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              private def get_words_tk(tk)
                string = ''
                start_token = tk[:text]
                start_quote = tk[:text].rstrip[-1]
                line_no = tk[:line_no]
            Severity: Minor
            Found in lib/rdoc/parser/ripper_state_lex.rb - About 1 hr to fix

              Method get_op_tk has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                private def get_op_tk(tk)
                  redefinable_operators = %w[! != !~ % & * ** + +@ - -@ / < << <= <=> == === =~ > >= >> [] []= ^ ` | ~]
                  if redefinable_operators.include?(tk[:text]) and tk[:state] == EXPR_ARG then
                    @inner_lex.lex_state = EXPR_ARG unless RIPPER_HAS_LEX_STATE
                    tk[:state] = Ripper::Lexer.const_defined?(:State) ? Ripper::Lexer::State.new(EXPR_ARG) : EXPR_ARG
              Severity: Minor
              Found in lib/rdoc/parser/ripper_state_lex.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_kw has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                  def on_kw(tok, data)
                    case tok
                    when 'class'
                      @lex_state = EXPR_CLASS
                      @in_fname = true
              Severity: Minor
              Found in lib/rdoc/parser/ripper_state_lex.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_kw has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def on_kw(tok, data)
                    case tok
                    when 'class'
                      @lex_state = EXPR_CLASS
                      @in_fname = true
              Severity: Minor
              Found in lib/rdoc/parser/ripper_state_lex.rb - About 1 hr to fix

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

                    private def on_variables(event, tok, data)
                      if @in_fname
                        @lex_state = EXPR_ENDFN
                        @in_fname = false
                        @continue = false
                Severity: Minor
                Found in lib/rdoc/parser/ripper_state_lex.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 get_regexp_tk has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                  private def get_regexp_tk(tk)
                    string = tk[:text]
                    state = nil
                    loop do
                      inner_str_tk = get_squashed_tk
                Severity: Minor
                Found in lib/rdoc/parser/ripper_state_lex.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 on_nl has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    def on_nl(tok, data)
                      case @lex_state
                      when EXPR_FNAME, EXPR_DOT
                        @continue = true
                      else
                Severity: Minor
                Found in lib/rdoc/parser/ripper_state_lex.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 on_ignored_nl has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    def on_ignored_nl(tok, data)
                      case @lex_state
                      when EXPR_FNAME, EXPR_DOT
                        @continue = true
                      else
                Severity: Minor
                Found in lib/rdoc/parser/ripper_state_lex.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 get_symbol_tk has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                  private def get_symbol_tk(tk)
                    is_symbol = true
                    symbol_tk = Token.new(tk.line_no, tk.char_no, :on_symbol)
                    if ":'" == tk[:text] or ':"' == tk[:text] or tk[:text].start_with?('%s')
                      tk1 = get_string_tk(tk)
                Severity: Minor
                Found in lib/rdoc/parser/ripper_state_lex.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

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

                    def on_ignored_nl(tok, data)
                      case @lex_state
                      when EXPR_FNAME, EXPR_DOT
                        @continue = true
                      else
                Severity: Minor
                Found in lib/rdoc/parser/ripper_state_lex.rb and 1 other location - About 25 mins to fix
                lib/rdoc/parser/ripper_state_lex.rb on lines 50..58

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

                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 on_nl(tok, data)
                      case @lex_state
                      when EXPR_FNAME, EXPR_DOT
                        @continue = true
                      else
                Severity: Minor
                Found in lib/rdoc/parser/ripper_state_lex.rb and 1 other location - About 25 mins to fix
                lib/rdoc/parser/ripper_state_lex.rb on lines 61..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 30.

                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

                There are no issues that match your filters.

                Category
                Status