xiaohui-zhangxh/editor_js

View on GitHub

Showing 104 of 110 total issues

Assignment Branch Condition size for process_ast is too high. [34.07/15]
Open

    def process_ast(ast, cmr_options)
      ast.walk do |node|
        if node.type == :code_block
          next if node.fence_info == ''

Severity: Minor
Found in lib/common_marker/rouge.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Assignment Branch Condition size for render is too high. [34.26/15]
Open

      def render(_options = {})
        file_info = data['file']
        title = data['title']
        extension = file_info['name']&.split('.')&.last
        extension = '' unless EXTENSIONS.key?(extension)

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method has too many lines. [28/10]
Open

    def process_ast(ast, cmr_options)
      ast.walk do |node|
        if node.type == :code_block
          next if node.fence_info == ''

Severity: Minor
Found in lib/common_marker/rouge.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Assignment Branch Condition size for render is too high. [26.59/15]
Open

      def render(_options = {})
        content_tag :div, class: css_name do
          url = data['url']
          caption = data['caption']
          withBorder = data['withBorder']
Severity: Minor
Found in lib/editor_js/blocks/image_block.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method has too many lines. [19/10]
Open

      def render(_options = {})
        file_info = data['file']
        title = data['title']
        extension = file_info['name']&.split('.')&.last
        extension = '' unless EXTENSIONS.key?(extension)

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [15/10]
Open

      def render(_options = {})
        content_tag :div, class: css_name do
          url = data['url']
          caption = data['caption']
          withBorder = data['withBorder']
Severity: Minor
Found in lib/editor_js/blocks/image_block.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Cyclomatic complexity for process_ast is too high. [7/6]
Open

    def process_ast(ast, cmr_options)
      ast.walk do |node|
        if node.type == :code_block
          next if node.fence_info == ''

Severity: Minor
Found in lib/common_marker/rouge.rb by rubocop

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Assignment Branch Condition size for render is too high. [16/15]
Open

      def render(options = {})
        content_tag :div, class: css_name do
          concat content_tag(:iframe, '',
                             src: data['embed'],
                             width: data['width'],
Severity: Minor
Found in lib/editor_js/blocks/embed_block.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Perceived complexity for process_ast is too high. [8/7]
Open

    def process_ast(ast, cmr_options)
      ast.walk do |node|
        if node.type == :code_block
          next if node.fence_info == ''

Severity: Minor
Found in lib/common_marker/rouge.rb by rubocop

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

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

    def process_ast(ast, cmr_options)
      ast.walk do |node|
        if node.type == :code_block
          next if node.fence_info == ''

Severity: Minor
Found in lib/common_marker/rouge.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_ast has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def process_ast(ast, cmr_options)
      ast.walk do |node|
        if node.type == :code_block
          next if node.fence_info == ''

Severity: Minor
Found in lib/common_marker/rouge.rb - About 1 hr to fix

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

        def render_html(text, cmark_options = :DEFAULT, render_options = :UNSAFE, extensions = [], **cmr_options)
    Severity: Minor
    Found in lib/common_marker/rouge.rb - About 35 mins to fix

      Method valid? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def valid?
            return @valid if instance_variable_defined?(:@valid)
      
            @valid = JSON::Validator.validate(SCHEMA, @content)
            return false unless @valid
      Severity: Minor
      Found in lib/editor_js/document.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 render has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

            def render(_options = {})
              file_info = data['file']
              title = data['title']
              extension = file_info['name']&.split('.')&.last
              extension = '' unless EXTENSIONS.key?(extension)
      Severity: Minor
      Found in lib/editor_js/blocks/attaches_block.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

      Block has too many lines. [26/25]
      Open

            ast.walk do |node|
              if node.type == :code_block
                next if node.fence_info == ''
      
                source = node.string_content
      Severity: Minor
      Found in lib/common_marker/rouge.rb by rubocop

      This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

      Prefer single-quoted strings when you don't need string interpolation or special symbols.
      Open

        spec.metadata["homepage_uri"] = spec.homepage
      Severity: Minor
      Found in editor_js.gemspec by rubocop

      Checks if uses of quotes match the configured preference.

      Example: EnforcedStyle: single_quotes (default)

      # bad
      "No special symbols"
      "No string interpolation"
      "Just text"
      
      # good
      'No special symbols'
      'No string interpolation'
      'Just text'
      "Wait! What's #{this}!"

      Example: EnforcedStyle: double_quotes

      # bad
      'Just some text'
      'No special chars or interpolation'
      
      # good
      "Just some text"
      "No special chars or interpolation"
      "Every string in #{project} uses double_quotes"

      Line is too long. [85/80]
      Open

                                   allowfullscreen: options.fetch('allowfullscreen', true))
      Severity: Minor
      Found in lib/editor_js/blocks/embed_block.rb by rubocop

      end at 42, 22 is not aligned with html_str = content_tag :div, class: html_class do at 40, 10.
      Open

                            end
      Severity: Minor
      Found in lib/editor_js/blocks/image_block.rb by rubocop

      This cop checks whether the end keywords are aligned properly for do end blocks.

      Three modes are supported through the EnforcedStyleAlignWith configuration parameter:

      start_of_block : the end shall be aligned with the start of the line where the do appeared.

      start_of_line : the end shall be aligned with the start of the line where the expression started.

      either (which is the default) : the end is allowed to be in either location. The autofixer will default to start_of_line.

      Example: EnforcedStyleAlignWith: either (default)

      # bad
      
      foo.bar
         .each do
           baz
             end
      
      # good
      
      variable = lambda do |i|
        i
      end

      Example: EnforcedStyleAlignWith: startofblock

      # bad
      
      foo.bar
         .each do
           baz
             end
      
      # good
      
      foo.bar
        .each do
           baz
         end

      Example: EnforcedStyleAlignWith: startofline

      # bad
      
      foo.bar
         .each do
           baz
             end
      
      # good
      
      foo.bar
        .each do
           baz
      end

      Missing magic comment # frozen_string_literal: true.
      Open

      lib = File.expand_path("lib", __dir__)
      Severity: Minor
      Found in editor_js.gemspec by rubocop

      This cop is designed to help upgrade to Ruby 3.0. It will add the comment # frozen_string_literal: true to the top of files to enable frozen string literals. Frozen string literals may be default in Ruby 3.0. The comment will be added below a shebang and encoding comment. The frozen string literal comment is only valid in Ruby 2.3+.

      Example: EnforcedStyle: when_needed (default)

      # The `when_needed` style will add the frozen string literal comment
      # to files only when the `TargetRubyVersion` is set to 2.3+.
      # bad
      module Foo
        # ...
      end
      
      # good
      # frozen_string_literal: true
      
      module Foo
        # ...
      end

      Example: EnforcedStyle: always

      # The `always` style will always add the frozen string literal comment
      # to a file, regardless of the Ruby version or if `freeze` or `<<` are
      # called on a string literal.
      # bad
      module Bar
        # ...
      end
      
      # good
      # frozen_string_literal: true
      
      module Bar
        # ...
      end

      Example: EnforcedStyle: never

      # The `never` will enforce that the frozen string literal comment does
      # not exist in a file.
      # bad
      # frozen_string_literal: true
      
      module Baz
        # ...
      end
      
      # good
      module Baz
        # ...
      end

      Prefer single-quoted strings when you don't need string interpolation or special symbols.
      Open

      require "editor_js/version"
      Severity: Minor
      Found in editor_js.gemspec by rubocop

      Checks if uses of quotes match the configured preference.

      Example: EnforcedStyle: single_quotes (default)

      # bad
      "No special symbols"
      "No string interpolation"
      "Just text"
      
      # good
      'No special symbols'
      'No string interpolation'
      'Just text'
      "Wait! What's #{this}!"

      Example: EnforcedStyle: double_quotes

      # bad
      'Just some text'
      'No special chars or interpolation'
      
      # good
      "Just some text"
      "No special chars or interpolation"
      "Every string in #{project} uses double_quotes"
      Severity
      Category
      Status
      Source
      Language