alexpeattie/nitlink

View on GitHub
lib/nitlink/parser.rb

Summary

Maintainability
A
1 hr
Test Coverage

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

    def extract_target_attributes(link_parameters)
      target_attributes = []
      link_parameters.each do |param_name, param_value|
        next if %(rel anchor).include?(param_name)
        next if %(media title title* type).include?(param_name) && first_match(target_attributes, param_name)
Severity: Minor
Found in lib/nitlink/parser.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.

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

    def extract_target_attributes(link_parameters)
      target_attributes = []
      link_parameters.each do |param_name, param_value|
        next if %(rel anchor).include?(param_name)
        next if %(media title title* type).include?(param_name) && first_match(target_attributes, param_name)
Severity: Minor
Found in lib/nitlink/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

Line is too long. [98/80]
Open

      context = (context_string && @request_uri.scheme) ? @request_uri.merge(context_string) : nil
Severity: Minor
Found in lib/nitlink/parser.rb by rubocop

Final newline missing.
Open

end
Severity: Minor
Found in lib/nitlink/parser.rb by rubocop

Line is too long. [110/80]
Open

      @request_uri, @status, link_header, @content_location_header = ResponseNormalizer.new.metadata(response)
Severity: Minor
Found in lib/nitlink/parser.rb by rubocop

Line is too long. [98/80]
Open

      if %w(GET HEAD).include?(@http_method.upcase) && [200, 203, 204, 206, 304].include?(@status)
Severity: Minor
Found in lib/nitlink/parser.rb by rubocop

%w-literals should be delimited by [ and ].
Open

      if %w(GET HEAD).include?(@http_method.upcase) && [200, 203, 204, 206, 304].include?(@status)
Severity: Minor
Found in lib/nitlink/parser.rb by rubocop

This cop enforces the consistent usage of %-literal delimiters.

Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

Example:

# Style/PercentLiteralDelimiters:
#   PreferredDelimiters:
#     default: '[]'
#     '%i':    '()'

# good
%w[alpha beta] + %i(gamma delta)

# bad
%W(alpha #{beta})

# bad
%I(alpha beta)

Line is too long. [95/80]
Open

        create_links(target_string, link_parameters).each { |link| link_collection.push(link) }
Severity: Minor
Found in lib/nitlink/parser.rb by rubocop

Missing top-level class documentation comment.
Open

  class Parser
Severity: Minor
Found in lib/nitlink/parser.rb by rubocop

This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.

The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.

Example:

# bad
class Person
  # ...
end

# good
# Description/Explanation of Person class
class Person
  # ...
end

Line is too long. [109/80]
Open

        next if %(media title title* type).include?(param_name) && first_match(target_attributes, param_name)
Severity: Minor
Found in lib/nitlink/parser.rb by rubocop

Line is too long. [106/80]
Open

      target, relation_types, context, target_attributes = link_attributes(target_string, link_parameters)
Severity: Minor
Found in lib/nitlink/parser.rb by rubocop

Space inside string interpolation detected.
Open

      MalformedLinkHeaderError.new("Malformed link header (#{ link_string })")
Severity: Minor
Found in lib/nitlink/parser.rb by rubocop

This cop checks for whitespace within string interpolations.

Example: EnforcedStyle: no_space (default)

# bad
   var = "This is the #{ space } example"

# good
   var = "This is the #{no_space} example"

Example: EnforcedStyle: space

# bad
   var = "This is the #{no_space} example"

# good
   var = "This is the #{ space } example"

Omit parentheses for ternary conditions.
Open

      context = (context_string && @request_uri.scheme) ? @request_uri.merge(context_string) : nil
Severity: Minor
Found in lib/nitlink/parser.rb by rubocop

This cop checks for the presence of parentheses around ternary conditions. It is configurable to enforce inclusion or omission of parentheses using EnforcedStyle. Omission is only enforced when removing the parentheses won't cause a different behavior.

Example: EnforcedStyle: requirenoparentheses (default)

# bad
foo = (bar?) ? a : b
foo = (bar.baz?) ? a : b
foo = (bar && baz) ? a : b

# good
foo = bar? ? a : b
foo = bar.baz? ? a : b
foo = bar && baz ? a : b

Example: EnforcedStyle: require_parentheses

# bad
foo = bar? ? a : b
foo = bar.baz? ? a : b
foo = bar && baz ? a : b

# good
foo = (bar?) ? a : b
foo = (bar.baz?) ? a : b
foo = (bar && baz) ? a : b

Example: EnforcedStyle: requireparentheseswhen_complex

# bad
foo = (bar?) ? a : b
foo = (bar.baz?) ? a : b
foo = bar && baz ? a : b

# good
foo = bar? ? a : b
foo = bar.baz? ? a : b
foo = (bar && baz) ? a : b

There are no issues that match your filters.

Category
Status