-
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cop ideas #2
Comments
This comment is inspired by the following commit in the rails/rails repository.
# bad
receiver.first == 'str'
# good
receiver.start_with?('str') |
Thanks for your comment, @koic ! I'll add your idea to the checklist. By the way, I guess your example code does not work well because And I confirmed Thanks! |
Let me follow up rubocop/rubocop-minitest#68 (comment) here.
cc @koic |
I think values.each { |k, v| do_something(k, v) } |
It would be useful to be able to know a full qualified class name that omit the namespace as follows: module Gem
def self.foo
raise Exception
end
end
Gem.foo #=> Gem::Exception |
|
It seems possible to detect without false positive by using receiver type (AR mode or not). |
I'm wondering if warnings via ruby/ruby#4070 can be detected by RuboCop or RuboCop with type. # frozen_string_literal: true
# bad
Struct.new(:a).new(a: 1)
foo = Struct.new(:x)
foo.new(x: 1)
# good
Struct.new(:b).new({ b: 1 })
bar = Struct.new(:y)
bar.new({ y: 1 }) |
Type information is required to determine whether the receiver has |
Feel free to comment cop ideas with type.
AR::Base.where
is not allowed in viewafter_update :foo, if: -> { 1 + 1 }
bool
type, but1 + 1
is always truthy.find_by
with bang or conditional https://github.com/rubocop-hq/rubocop-rails/issues/167find
vsdetect
,map
vscollect
, etc...String#first
and comparison withString#start_with?
.String#frist
is added by ActiveSupportAR::Relation#pluck
vsAR::Relation#select
for sub-queryrel.where(id: rel2.pluck(:id))
pluck
withselect
, but it depends on context.send
with public method namefoo.send(:foo_public_method)
should befoo.foo_public_method
str[/substr/]
should bestr['substr']
Style/HashTransformValues
with not-hash iterationModel.pluck(:id, :val).map { |id, val| [id, foo(val)] }.to_h
I already search the following sources to find cop ideas.
The text was updated successfully, but these errors were encountered: