Showing 122 of 122 total issues
Line is too long. [215/120] Open
if AnnouncementView.where(user_id: send(Starburst.current_user_method).id, announcement_id: announcement.id).first_or_create(user_id: send(Starburst.current_user_method).id, announcement_id: announcement.id)
render :json => :ok
- Read upRead up
- Exclude checks
This cop checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/IndentationStyle
cop.
It also ignores a shebang line by default.
This cop has some autocorrection capabilities. It can programmatically shorten certain long lines by inserting line breaks into expressions that can be safely split across lines. These include arrays, hashes, and method calls with argument lists.
If autocorrection is enabled, the following Layout cops are recommended to further format the broken lines. (Many of these are enabled by default.)
- ArgumentAlignment
- BlockAlignment
- BlockDelimiters
- BlockEndNewline
- ClosingParenthesisIndentation
- FirstArgumentIndentation
- FirstArrayElementIndentation
- FirstHashElementIndentation
- FirstParameterIndentation
- HashAlignment
- IndentationWidth
- MultilineArrayLineBreaks
- MultilineBlockLayout
- MultilineHashBraceLayout
- MultilineHashKeyLineBreaks
- MultilineMethodArgumentLineBreaks
- ParameterAlignment
Together, these cops will pretty print hashes, arrays, method calls, etc. For example, let's say the max columns is 25:
Example:
# bad
{foo: "0000000000", bar: "0000000000", baz: "0000000000"}
# good
{foo: "0000000000",
bar: "0000000000", baz: "0000000000"}
# good (with recommended cops enabled)
{
foo: "0000000000",
bar: "0000000000",
baz: "0000000000",
}
Line is too long. [124/120] Open
# This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.
- Read upRead up
- Exclude checks
This cop checks the length of lines in the source code.
The maximum length is configurable.
The tab size is configured in the IndentationWidth
of the Layout/IndentationStyle
cop.
It also ignores a shebang line by default.
This cop has some autocorrection capabilities. It can programmatically shorten certain long lines by inserting line breaks into expressions that can be safely split across lines. These include arrays, hashes, and method calls with argument lists.
If autocorrection is enabled, the following Layout cops are recommended to further format the broken lines. (Many of these are enabled by default.)
- ArgumentAlignment
- BlockAlignment
- BlockDelimiters
- BlockEndNewline
- ClosingParenthesisIndentation
- FirstArgumentIndentation
- FirstArrayElementIndentation
- FirstHashElementIndentation
- FirstParameterIndentation
- HashAlignment
- IndentationWidth
- MultilineArrayLineBreaks
- MultilineBlockLayout
- MultilineHashBraceLayout
- MultilineHashKeyLineBreaks
- MultilineMethodArgumentLineBreaks
- ParameterAlignment
Together, these cops will pretty print hashes, arrays, method calls, etc. For example, let's say the max columns is 25:
Example:
# bad
{foo: "0000000000", bar: "0000000000", baz: "0000000000"}
# good
{foo: "0000000000",
bar: "0000000000", baz: "0000000000"}
# good (with recommended cops enabled)
{
foo: "0000000000",
bar: "0000000000",
baz: "0000000000",
}
Method mark_as_read
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def mark_as_read
announcement = Announcement.find(params[:id].to_i)
if respond_to?(Starburst.current_user_method, true) && send(Starburst.current_user_method) && announcement
if AnnouncementView.where(user_id: send(Starburst.current_user_method).id, announcement_id: announcement.id).first_or_create(user_id: send(Starburst.current_user_method).id, announcement_id: announcement.id)
render :json => :ok
- 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
Tab detected in indentation. Open
end
- Read upRead up
- Exclude checks
This cop checks that the indentation method is consistent. Either tabs only or spaces only are used for indentation.
Example: EnforcedStyle: spaces (default)
# bad
# This example uses a tab to indent bar.
def foo
bar
end
# good
# This example uses spaces to indent bar.
def foo
bar
end
Example: EnforcedStyle: tabs
# bad
# This example uses spaces to indent bar.
def foo
bar
end
# good
# This example uses a tab to indent bar.
def foo
bar
end
Tab detected in indentation. Open
end
- Read upRead up
- Exclude checks
This cop checks that the indentation method is consistent. Either tabs only or spaces only are used for indentation.
Example: EnforcedStyle: spaces (default)
# bad
# This example uses a tab to indent bar.
def foo
bar
end
# good
# This example uses spaces to indent bar.
def foo
bar
end
Example: EnforcedStyle: tabs
# bad
# This example uses spaces to indent bar.
def foo
bar
end
# good
# This example uses a tab to indent bar.
def foo
bar
end
Use 2 (not 1) spaces for indentation. Open
def self.current(current_user)
- Read upRead up
- Exclude checks
This cop checks for indentation that doesn't use the specified number of spaces.
See also the IndentationConsistency cop which is the companion to this one.
Example:
# bad
class A
def test
puts 'hello'
end
end
# good
class A
def test
puts 'hello'
end
end
Example: IgnoredPatterns: ['^\s*module']
# bad
module A
class B
def test
puts 'hello'
end
end
end
# good
module A
class B
def test
puts 'hello'
end
end
end
Use 2 (not 1) spaces for indentation. Open
return false
- Read upRead up
- Exclude checks
This cop checks for indentation that doesn't use the specified number of spaces.
See also the IndentationConsistency cop which is the companion to this one.
Example:
# bad
class A
def test
puts 'hello'
end
end
# good
class A
def test
puts 'hello'
end
end
Example: IgnoredPatterns: ['^\s*module']
# bad
module A
class B
def test
puts 'hello'
end
end
end
# good
module A
class B
def test
puts 'hello'
end
end
end
Use 2 (not 0) spaces for indenting an expression spanning multiple lines. Open
.where("starburst_announcement_views.announcement_id IS NULL AND starburst_announcement_views.user_id IS NULL")
- Read upRead up
- Exclude checks
This cop checks the indentation of the method name part in method calls that span more than one line.
Example: EnforcedStyle: aligned (default)
# bad
while myvariable
.b
# do something
end
# good
while myvariable
.b
# do something
end
# good
Thing.a
.b
.c
Example: EnforcedStyle: indented
# good
while myvariable
.b
# do something
end
Example: EnforcedStyle: indentedrelativeto_receiver
# good
while myvariable
.a
.b
# do something
end
# good
myvariable = Thing
.a
.b
.c
Missing frozen string literal comment. Open
module Starburst
- Read upRead up
- Exclude checks
This cop is designed to help you transition from mutable string literals
to frozen string literals.
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 future Ruby. The comment will be added below a shebang and
encoding comment. The frozen string literal comment is only valid in
Ruby 2.3+.
Note that the cop will ignore files where the comment exists but is set
to false
instead of true
.
Example: EnforcedStyle: always (default)
# 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
# good
# frozen_string_literal: false
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
Example: EnforcedStyle: always_true
# The `always_true` style enforces that the frozen string literal
# comment is set to `true`. This is a stricter option than `always`
# and forces projects to use frozen string literals.
# bad
# frozen_string_literal: false
module Baz
# ...
end
# bad
module Baz
# ...
end
# good
# frozen_string_literal: true
module Bar
# ...
end
Prefer single-quoted strings when you don't need string interpolation or special symbols. Open
scope :in_delivery_order, lambda { order("start_delivering_at ASC")}
- 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"
Tab detected in indentation. Open
validates :user_id, presence: true
- Read upRead up
- Exclude checks
This cop checks that the indentation method is consistent. Either tabs only or spaces only are used for indentation.
Example: EnforcedStyle: spaces (default)
# bad
# This example uses a tab to indent bar.
def foo
bar
end
# good
# This example uses spaces to indent bar.
def foo
bar
end
Example: EnforcedStyle: tabs
# bad
# This example uses spaces to indent bar.
def foo
bar
end
# good
# This example uses a tab to indent bar.
def foo
bar
end
Tab detected in indentation. Open
class Announcement < ActiveRecord::Base
- Read upRead up
- Exclude checks
This cop checks that the indentation method is consistent. Either tabs only or spaces only are used for indentation.
Example: EnforcedStyle: spaces (default)
# bad
# This example uses a tab to indent bar.
def foo
bar
end
# good
# This example uses spaces to indent bar.
def foo
bar
end
Example: EnforcedStyle: tabs
# bad
# This example uses spaces to indent bar.
def foo
bar
end
# good
# This example uses a tab to indent bar.
def foo
bar
end
Tab detected in indentation. Open
conditions.each do |condition|
- Read upRead up
- Exclude checks
This cop checks that the indentation method is consistent. Either tabs only or spaces only are used for indentation.
Example: EnforcedStyle: spaces (default)
# bad
# This example uses a tab to indent bar.
def foo
bar
end
# good
# This example uses spaces to indent bar.
def foo
bar
end
Example: EnforcedStyle: tabs
# bad
# This example uses spaces to indent bar.
def foo
bar
end
# good
# This example uses a tab to indent bar.
def foo
bar
end
Tab detected in indentation. Open
return true
- Read upRead up
- Exclude checks
This cop checks that the indentation method is consistent. Either tabs only or spaces only are used for indentation.
Example: EnforcedStyle: spaces (default)
# bad
# This example uses a tab to indent bar.
def foo
bar
end
# good
# This example uses spaces to indent bar.
def foo
bar
end
Example: EnforcedStyle: tabs
# bad
# This example uses spaces to indent bar.
def foo
bar
end
# good
# This example uses a tab to indent bar.
def foo
bar
end
Use the -> { ... }
lambda literal syntax for single line lambdas. Open
scope :in_delivery_order, lambda { order("start_delivering_at ASC")}
- Read upRead up
- Exclude checks
This cop (by default) checks for uses of the lambda literal syntax for single line lambdas, and the method call syntax for multiline lambdas. It is configurable to enforce one of the styles for both single line and multiline lambdas as well.
Example: EnforcedStyle: linecountdependent (default)
# bad
f = lambda { |x| x }
f = ->(x) do
x
end
# good
f = ->(x) { x }
f = lambda do |x|
x
end
Example: EnforcedStyle: lambda
# bad
f = ->(x) { x }
f = ->(x) do
x
end
# good
f = lambda { |x| x }
f = lambda do |x|
x
end
Example: EnforcedStyle: literal
# bad
f = lambda { |x| x }
f = lambda do |x|
x
end
# good
f = ->(x) { x }
f = ->(x) do
x
end
Missing top-level class documentation comment. Open
class AnnouncementView < ActiveRecord::Base
- Read upRead up
- Exclude checks
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, constant definitions or constant visibility declarations.
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
module Math
end
# good
# Description/Explanation of Person class
class Person
# ...
end
# allowed
# Class without body
class Person
end
# Namespace - A namespace can be a class or a module
# Containing a class
module Namespace
# Description/Explanation of Person class
class Person
# ...
end
end
# Containing constant visibility declaration
module Namespace
class Private
end
private_constant :Private
end
# Containing constant definition
module Namespace
Public = Class.new
end
Missing frozen string literal comment. Open
#!/usr/bin/env ruby
- Read upRead up
- Exclude checks
This cop is designed to help you transition from mutable string literals
to frozen string literals.
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 future Ruby. The comment will be added below a shebang and
encoding comment. The frozen string literal comment is only valid in
Ruby 2.3+.
Note that the cop will ignore files where the comment exists but is set
to false
instead of true
.
Example: EnforcedStyle: always (default)
# 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
# good
# frozen_string_literal: false
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
Example: EnforcedStyle: always_true
# The `always_true` style enforces that the frozen string literal
# comment is set to `true`. This is a stricter option than `always`
# and forces projects to use frozen string literals.
# bad
# frozen_string_literal: false
module Baz
# ...
end
# bad
module Baz
# ...
end
# good
# frozen_string_literal: true
module Bar
# ...
end
Use 2 (not 1) spaces for indentation. Open
class AnnouncementsController < Starburst.base_controller.constantize
- Read upRead up
- Exclude checks
This cop checks for indentation that doesn't use the specified number of spaces.
See also the IndentationConsistency cop which is the companion to this one.
Example:
# bad
class A
def test
puts 'hello'
end
end
# good
class A
def test
puts 'hello'
end
end
Example: IgnoredPatterns: ['^\s*module']
# bad
module A
class B
def test
puts 'hello'
end
end
end
# good
module A
class B
def test
puts 'hello'
end
end
end
Extra empty line detected at module body end. Open
end
- Read upRead up
- Exclude checks
This cop checks if empty lines around the bodies of modules match the configuration.
Example: EnforcedStyle: empty_lines
# good
module Foo
def bar
# ...
end
end
Example: EnforcedStyle: emptylinesexcept_namespace
# good
module Foo
module Bar
# ...
end
end
Example: EnforcedStyle: emptylinesspecial
# good
module Foo
def bar; end
end
Example: EnforcedStyle: noemptylines (default)
# good
module Foo
def bar
# ...
end
end
Tab detected in indentation. Open
def self.current(current_user)
- Read upRead up
- Exclude checks
This cop checks that the indentation method is consistent. Either tabs only or spaces only are used for indentation.
Example: EnforcedStyle: spaces (default)
# bad
# This example uses a tab to indent bar.
def foo
bar
end
# good
# This example uses spaces to indent bar.
def foo
bar
end
Example: EnforcedStyle: tabs
# bad
# This example uses spaces to indent bar.
def foo
bar
end
# good
# This example uses a tab to indent bar.
def foo
bar
end