Showing 661 of 695 total issues
Use match?
instead of =~
when MatchData
is not used. Open
self =~ /^#{Regexp.escape joint}/ ? self : (joint + self)
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
In Ruby 2.4, String#match?
, Regexp#match?
and Symbol#match?
have been added. The methods are faster than match
.
Because the methods avoid creating a MatchData
object or saving
backref.
So, when MatchData
is not used, use match?
instead of match
.
Example:
# bad
def foo
if x =~ /re/
do_something
end
end
# bad
def foo
if x.match(/re/)
do_something
end
end
# bad
def foo
if /re/ === x
do_something
end
end
# good
def foo
if x.match?(/re/)
do_something
end
end
# good
def foo
if x =~ /re/
do_something(Regexp.last_match)
end
end
# good
def foo
if x.match(/re/)
do_something($~)
end
end
# good
def foo
if /re/ === x
do_something($~)
end
end
Method Cardname#key
is defined at both cardname/lib/cardname.rb:42 and cardname/lib/cardname.rb:74. Open
def key
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks for duplicated instance (or singleton) method definitions.
Example:
# bad
def duplicated
1
end
def duplicated
2
end
Example:
# bad
def duplicated
1
end
alias duplicated other_duplicated
Example:
# good
def duplicated
1
end
def other_duplicated
2
end
Use safe navigation (&.
) instead of checking if an object exists before calling the method. Open
return "on" if @parent && @parent.card.name == "*signin+*account" # HACK
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop transforms usages of a method call safeguarded by a non nil
check for the variable whose method is being called to
safe navigation (&.
).
Configuration option: ConvertCodeThatCanStartToReturnNil
The default for this is false
. When configured to true
, this will
check for code in the format !foo.nil? && foo.bar
. As it is written,
the return of this code is limited to false
and whatever the return
of the method is. If this is converted to safe navigation,
foo&.bar
can start returning nil
as well as what the method
returns.
Example:
# bad
foo.bar if foo
foo.bar(param1, param2) if foo
foo.bar { |e| e.something } if foo
foo.bar(param) { |e| e.something } if foo
foo.bar if !foo.nil?
foo.bar unless !foo
foo.bar unless foo.nil?
foo && foo.bar
foo && foo.bar(param1, param2)
foo && foo.bar { |e| e.something }
foo && foo.bar(param) { |e| e.something }
# good
foo&.bar
foo&.bar(param1, param2)
foo&.bar { |e| e.something }
foo&.bar(param) { |e| e.something }
foo.nil? || foo.bar
!foo || foo.bar
# Methods that `nil` will `respond_to?` should not be converted to
# use safe navigation
foo.to_i if foo
Use let
instead of an instance variable. Open
expect(@account.email).to eq("wolf@decko.org")
- Create a ticketCreate a ticket
- Exclude checks
Use let
instead of an instance variable. Open
expect(@card.errors[:signin].first).to match(/Wrong password/)
- Create a ticketCreate a ticket
- Exclude checks
Use let
instead of an instance variable. Open
@format = @card.format
- Create a ticketCreate a ticket
- Exclude checks
Start context description with 'when', 'with', or 'without'. Open
context "valid user" do
- Create a ticketCreate a ticket
- Exclude checks
Use let
instead of an instance variable. Open
raw_source = @mail.parts[0].body.raw_source
- Create a ticketCreate a ticket
- Exclude checks
Use let
instead of an instance variable. Open
assert_equal @account, authenticated
- Create a ticketCreate a ticket
- Exclude checks
Use let
instead of an instance variable. Open
Card::Env.params[:token] = Card::Auth::Token.encode @account.left_id, extra_payload
- Create a ticketCreate a ticket
- Exclude checks
Name your test subject if you need to reference it explicitly. Open
.to eq "~#{subject.id}/#{subject.last_action_id}.txt"
- Create a ticketCreate a ticket
- Exclude checks
Name your test subject if you need to reference it explicitly. Open
subject
- Create a ticketCreate a ticket
- Exclude checks
Name your test subject if you need to reference it explicitly. Open
expect(subject.image.url)
- Create a ticketCreate a ticket
- Exclude checks
Freeze mutable objects assigned to constants. Open
RECAPTCHA_ERROR_CODES = { # LOCALIZE
"missing-input-secret" => "secret parameter is missing",
"invalid-input-secret" => "secret parameter is invalid or malformed",
"missing-input-response" => "response parameter is missing",
"invalid-input-response" => "response parameter is invalid or malformed",
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
This cop checks whether some constant value isn't a mutable literal (e.g. array or hash).
Example:
# bad
CONST = [1, 2, 3]
# good
CONST = [1, 2, 3].freeze
Script file start_follow_link.rb doesn't have execute permission. Open
#! no set module
- Create a ticketCreate a ticket
- Exclude checks
Missing top-level class documentation comment. Open
class FollowLink
- Read upRead up
- Create a ticketCreate a ticket
- 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, 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
Missing top-level module documentation comment. Open
module SelectedAction
- Read upRead up
- Create a ticketCreate a ticket
- 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, 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
Start context description with 'when', 'with', or 'without'. Open
context "creating" do
- Create a ticketCreate a ticket
- Exclude checks
Start context description with 'when', 'with', or 'without'. Open
context "unprotected" do
- Create a ticketCreate a ticket
- Exclude checks
Name your test subject if you need to reference it explicitly. Open
expect(subject.original_filename).to eq "file2.txt"
- Create a ticketCreate a ticket
- Exclude checks