Missing magic comment # frozen_string_literal: true
. Open
load 'Rakefile'
- Read upRead up
- Exclude checks
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
Use ((success + failure) % 50).zero?
instead of (success + failure) % 50 == 0
. Open
if (success + failure) % 50 == 0
- Read upRead up
- Exclude checks
This cop checks for usage of comparison operators (==
,
>
, <
) to test numbers as zero, positive, or negative.
These can be replaced by their respective predicate methods.
The cop can also be configured to do the reverse.
The cop disregards #nonzero?
as it its value is truthy or falsey,
but not true
and false
, and thus not always interchangeable with
!= 0
.
The cop ignores comparisons to global variables, since they are often
populated with objects which can be compared with integers, but are
not themselves Interger
polymorphic.
Example: EnforcedStyle: predicate (default)
# bad
foo == 0
0 > foo
bar.baz > 0
# good
foo.zero?
foo.negative?
bar.baz.positive?
Example: EnforcedStyle: comparison
# bad
foo.zero?
foo.negative?
bar.baz.positive?
# good
foo == 0
0 > foo
bar.baz > 0
Line is too long. [118/80] Open
updates << "- <a href='https://storebot.me/bot/lycantulul_bot'>Klik sini kalo mau ngasih rating/review (storebot)</a>"
- Exclude checks
Line is too long. [133/80] Open
bot.api.send_message(chat_id: g, text: updates, parse_mode: 'HTML', disable_web_page_preview: true, disable_notification: true)
- Exclude checks
Line is too long. [122/80] Open
updates << 'Ditinggal berbulan-bulan tanpa pengembangan apapun, tak disangka masih banyak pemain aktif, bahkan bertambah!'
- Exclude checks
Line is too long. [88/80] Open
updates << 'Coming soon: Logo Baru Lycantulul! (...setelah ditinggal hampir tiga bulan)'
- Exclude checks
Line is too long. [124/80] Open
updates << "- <a href='https://telegram.me/lycantulul_board'>Klik sini untuk join channel berisi update dari Lycantulul</a>"
- Exclude checks
Line is too long. [100/80] Open
Lycantulul::RegisteredPlayer.find_by(user_id: g).update_attribute(:blocked, true) rescue nil
- Exclude checks
Prefer Date or Time over DateTime. Open
updates << "Terhitung sejak 17 Mei 2016, ada #{Lycantulul::Group.where(:created_at.gte => DateTime.new(2016, 5, 17)).count} grup baru, #{Lycantulul::RegisteredPlayer.where(:created_at.gte => DateTime.new(2016, 5, 17)).count} pemain baru, dan #{Lycantulul::Game.where(:created_at.gte => DateTime.new(2016, 5, 17)).count} permainan yang dilakukan!"
- Read upRead up
- Exclude checks
This cop checks for uses of DateTime
that should be replaced by
Date
or Time
.
Example:
# bad - uses `DateTime` for current time
DateTime.now
# good - uses `Time` for current time
Time.now
# bad - uses `DateTime` for modern date
DateTime.iso8601('2016-06-29')
# good - uses `Date` for modern date
Date.iso8601('2016-06-29')
# good - uses `DateTime` with start argument for historical date
DateTime.iso8601('1751-04-23', Date::ENGLAND)
Favor modifier if
usage when having a single-line body. Another good alternative is the usage of control flow &&
/||
. Open
if (success + failure) % 50 == 0
- Read upRead up
- Exclude checks
Checks for if and unless statements that would fit on one line
if written as a modifier if/unless. The maximum line length is
configured in the Metrics/LineLength
cop.
Example:
# bad
if condition
do_stuff(bar)
end
unless qux.empty?
Foo.do_something
end
# good
do_stuff(bar) if condition
Foo.do_something unless qux.empty?
Do not introduce global variables. Open
Telegram::Bot::Client.run($token) do |bot|
- 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
Avoid using rescue
in its modifier form. Open
Lycantulul::RegisteredPlayer.find_by(user_id: g).update_attribute(:blocked, true) rescue nil
- Read upRead up
- Exclude checks
This cop checks for uses of rescue in its modifier form.
Example:
# bad
some_method rescue handle_error
# good
begin
some_method
rescue
handle_error
end
Line is too long. [346/80] Open
updates << "Terhitung sejak 17 Mei 2016, ada #{Lycantulul::Group.where(:created_at.gte => DateTime.new(2016, 5, 17)).count} grup baru, #{Lycantulul::RegisteredPlayer.where(:created_at.gte => DateTime.new(2016, 5, 17)).count} pemain baru, dan #{Lycantulul::Game.where(:created_at.gte => DateTime.new(2016, 5, 17)).count} permainan yang dilakukan!"
- Exclude checks
Line is too long. [182/80] Open
updates << "<b>Meanwhile, join channel berisi update dari Lycantulul di </b><a href='https://telegram.me/lycantulul_board'>sini</a><b> ya~ Biar ndak kasih info via PM/group lagi</b>"
- Exclude checks
Line is too long. [127/80] Open
updates << "- <a href='https://github.com/tulul/lycantulul_bot'>Klik sini kalo mau saran/lapor bug/kontribusi/dll (github)</a>"
- Exclude checks
Prefer Date or Time over DateTime. Open
updates << "Terhitung sejak 17 Mei 2016, ada #{Lycantulul::Group.where(:created_at.gte => DateTime.new(2016, 5, 17)).count} grup baru, #{Lycantulul::RegisteredPlayer.where(:created_at.gte => DateTime.new(2016, 5, 17)).count} pemain baru, dan #{Lycantulul::Game.where(:created_at.gte => DateTime.new(2016, 5, 17)).count} permainan yang dilakukan!"
- Read upRead up
- Exclude checks
This cop checks for uses of DateTime
that should be replaced by
Date
or Time
.
Example:
# bad - uses `DateTime` for current time
DateTime.now
# good - uses `Time` for current time
Time.now
# bad - uses `DateTime` for modern date
DateTime.iso8601('2016-06-29')
# good - uses `Date` for modern date
Date.iso8601('2016-06-29')
# good - uses `DateTime` with start argument for historical date
DateTime.iso8601('1751-04-23', Date::ENGLAND)
Line is too long. [129/80] Open
updates << "- <a href='https://telegram.me/lycantulul'>Klik sini kalo grup kalian sepi dan pengen main bareng di grup publik</a>"
- Exclude checks
Prefer Date or Time over DateTime. Open
updates << "Terhitung sejak 17 Mei 2016, ada #{Lycantulul::Group.where(:created_at.gte => DateTime.new(2016, 5, 17)).count} grup baru, #{Lycantulul::RegisteredPlayer.where(:created_at.gte => DateTime.new(2016, 5, 17)).count} pemain baru, dan #{Lycantulul::Game.where(:created_at.gte => DateTime.new(2016, 5, 17)).count} permainan yang dilakukan!"
- Read upRead up
- Exclude checks
This cop checks for uses of DateTime
that should be replaced by
Date
or Time
.
Example:
# bad - uses `DateTime` for current time
DateTime.now
# good - uses `Time` for current time
Time.now
# bad - uses `DateTime` for modern date
DateTime.iso8601('2016-06-29')
# good - uses `Date` for modern date
Date.iso8601('2016-06-29')
# good - uses `DateTime` with start argument for historical date
DateTime.iso8601('1751-04-23', Date::ENGLAND)