Showing 319 of 319 total issues
OS Command Injection in Rake Open
rake (10.4.2)
- Read upRead up
- Exclude checks
Advisory: CVE-2020-8130
Criticality: High
URL: https://github.com/advisories/GHSA-jppv-gw3r-w3q8
Solution: upgrade to >= 12.3.3
json Gem for Ruby Unsafe Object Creation Vulnerability (additional fix) Open
json (2.0.3)
- Read upRead up
- Exclude checks
Advisory: CVE-2020-10663
Criticality: High
URL: https://www.ruby-lang.org/en/news/2020/03/19/json-dos-cve-2020-10663/
Solution: upgrade to >= 2.3.0
Method has too many lines. [30/10] Open
def check_links
begin
require 'anemone'
root = 'http://localhost:4000/'
- Read upRead up
- Exclude checks
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 check_links is too high. [25.4/15] Open
def check_links
begin
require 'anemone'
root = 'http://localhost:4000/'
- Read upRead up
- Exclude checks
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. [15/10] Open
def write_new_draft()
filename = get_unique_filename
full_path = File.join(@post_dir, filename)
File.open(full_path, 'w') do |f|
f.puts "---"
- Read upRead up
- Exclude checks
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 parse_date is too high. [8/6] Open
def parse_date(date)
# This looks cleaner but logic is incorrect
#if (date.nil? ||
# date.empty? ||
# date.match(/[0-9]+-[0-9]+-[0-9]+/).nil?) then
- Read upRead up
- Exclude checks
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 get_unique_filename is too high. [16.79/15] Open
def get_unique_filename()
# TODO: Global Variable
filename = @date[0..9] + "-" + JekyllRake::Utils.slugify(@title) + $post_ext
# TODO: refactor - very difficult to understand without the comment
- Read upRead up
- Exclude checks
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 parse_date is too high. [8/7] Open
def parse_date(date)
# This looks cleaner but logic is incorrect
#if (date.nil? ||
# date.empty? ||
# date.match(/[0-9]+-[0-9]+-[0-9]+/).nil?) then
- Read upRead up
- Exclude checks
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
Assignment Branch Condition size for write_new_draft is too high. [15.26/15] Open
def write_new_draft()
filename = get_unique_filename
full_path = File.join(@post_dir, filename)
File.open(full_path, 'w') do |f|
f.puts "---"
- Read upRead up
- Exclude checks
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 parse_date is too high. [15.65/15] Open
def parse_date(date)
# This looks cleaner but logic is incorrect
#if (date.nil? ||
# date.empty? ||
# date.match(/[0-9]+-[0-9]+-[0-9]+/).nil?) then
- Read upRead up
- Exclude checks
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 check_links
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def check_links
begin
require 'anemone'
root = 'http://localhost:4000/'
Block has too many lines. [26/25] Open
Gem::Specification.new do |spec|
spec.name = "jekyll_rake"
spec.version = JekyllRake::VERSION
spec.authors = ["Sebastian Carroll"]
spec.email = ["scarroll@hortonworks.com"]
- Read upRead up
- Exclude checks
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.
Method set_post_dir_and_yaml_cat
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def set_post_dir_and_yaml_cat(dir)
# Written like this to deal with category being nil
if @category and Dir.exists?(File.join(@category, dir)) then
@post_dir = File.join(@category, dir)
@yaml_cat = nil
- Read upRead up
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 check_links
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def check_links
begin
require 'anemone'
root = 'http://localhost:4000/'
- Read upRead up
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
Space between { and | missing. Open
Dir.glob("./#{cur_dir}/lib/**/*").select{|f| File.file? f}.each{|f| require f}
- Read upRead up
- Exclude checks
Checks that block braces have or don't have surrounding space inside them on configuration. For blocks taking parameters, it checks that the left brace has or doesn't have trailing space depending on configuration.
Example: EnforcedStyle: space (default)
# The `space` style enforces that block braces have
# surrounding space.
# bad
some_array.each {puts e}
# good
some_array.each { puts e }
Example: EnforcedStyle: no_space
# The `no_space` style enforces that block braces don't
# have surrounding space.
# bad
some_array.each { puts e }
# good
some_array.each {puts e}
Example: EnforcedStyleForEmptyBraces: no_space (default)
# The `no_space` EnforcedStyleForEmptyBraces style enforces that
# block braces don't have a space in between when empty.
# bad
some_array.each { }
some_array.each { }
some_array.each { }
# good
some_array.each {}
Example: EnforcedStyleForEmptyBraces: space
# The `space` EnforcedStyleForEmptyBraces style enforces that
# block braces have at least a spece in between when empty.
# bad
some_array.each {}
# good
some_array.each { }
some_array.each { }
some_array.each { }
Example: SpaceBeforeBlockParameters: true (default)
# The SpaceBeforeBlockParameters style set to `true` enforces that
# there is a space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.
# bad
[1, 2, 3].each {|n| n * 2 }
# good
[1, 2, 3].each { |n| n * 2 }
Example: SpaceBeforeBlockParameters: true
# The SpaceBeforeBlockParameters style set to `false` enforces that
# there is no space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.
# bad
[1, 2, 3].each { |n| n * 2 }
# good
[1, 2, 3].each {|n| n * 2 }
Unused block argument - t
. If it's necessary, use _
or _t
as an argument name to indicate that it won't be used. Open
task :publish, [:draft_post] do |t, args|
- Read upRead up
- Exclude checks
This cop checks for unused block arguments.
Example:
# bad
do_something do |used, unused|
puts used
end
do_something do |bar|
puts :foo
end
define_method(:foo) do |bar|
puts :baz
end
Example:
#good
do_something do |used, _unused|
puts used
end
do_something do
puts :foo
end
define_method(:foo) do |_bar|
puts :baz
end
Use the new Ruby 1.9 hash syntax. Open
task :deploy_github => :build do |t, args|
- Read upRead up
- Exclude checks
This cop checks hash literal syntax.
It can enforce either the use of the class hash rocket syntax or the use of the newer Ruby 1.9 syntax (when applicable).
A separate offense is registered for each problematic pair.
The supported styles are:
- ruby19 - forces use of the 1.9 syntax (e.g.
{a: 1}
) when hashes have all symbols for keys - hash_rockets - forces use of hash rockets for all hashes
- nomixedkeys - simply checks for hashes with mixed syntaxes
- ruby19nomixed_keys - forces use of ruby 1.9 syntax and forbids mixed syntax hashes
Example: EnforcedStyle: ruby19 (default)
# bad
{:a => 2}
{b: 1, :c => 2}
# good
{a: 2, b: 1}
{:c => 2, 'd' => 2} # acceptable since 'd' isn't a symbol
{d: 1, 'e' => 2} # technically not forbidden
Example: EnforcedStyle: hash_rockets
# bad
{a: 1, b: 2}
{c: 1, 'd' => 5}
# good
{:a => 1, :b => 2}
Example: EnforcedStyle: nomixedkeys
# bad
{:a => 1, b: 2}
{c: 1, 'd' => 2}
# good
{:a => 1, :b => 2}
{c: 1, d: 2}
Example: EnforcedStyle: ruby19nomixed_keys
# bad
{:a => 1, :b => 2}
{c: 2, 'd' => 3} # should just use hash rockets
# good
{a: 1, b: 2}
{:c => 3, 'd' => 4}
Prefer single-quoted strings when you don't need string interpolation or special symbols. Open
File.open("_last_deploy.txt", 'w') {|f| f.write(time) }
- Read upRead up
- Exclude checks
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"
Prefer single-quoted strings when you don't need string interpolation or special symbols. Open
Rake::Task["create_post"].invoke(Time.new.strftime("%Y-%m-%d %H:%M:%S"), "Recent Changes", nil, content)
- Read upRead up
- Exclude checks
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"
Do not introduce global variables. Open
$post_dir = "_posts/"
- Read upRead up
- Exclude checks
This cops looks for uses of global variables. It does not report offenses for built-in global variables. Built-in global variables are allowed by default. Additionally users can allow additional variables via the AllowedVariables option.
Note that backreferences like $1, $2, etc are not global variables.
Example:
# bad
$foo = 2
bar = $foo + 5
# good
FOO = 2
foo = 2
$stdin.read