Skip to content

Cop ideas #2

@pocke

Description

@pocke

Feel free to comment cop ideas with type.

  • Prefer find_each over each
    • We already have Rails/FindEach
  • Check method executes SQL usage in view.
    • AR::Base.where is not allowed in view
    • Detect method call that returns AR::Relation
  • Check bool type argument receives type that is always truthy or falsy.
    • e.g. after_update :foo, if: -> { 1 + 1 }
    • The if's block requires bool type, but 1 + 1 is always truthy.
  • Prefer Hash#dig over Hash#[]
  • Improve Rails/SaveBang
  • find_by with bang or conditional https://github.com/rubocop-hq/rubocop-rails/issues/167
  • Detect unreachable code with bot type
  • Rails/DynamicFindBy without false positives
  • truthy type in conditional
  • Replacement of Style/BracesAroundHashParameters
  • Method aliases
    • find vs detect, map vs collect, etc...
  • Replace String#first and comparison with String#start_with?.
  • AR::Relation#pluck vs AR::Relation#select for sub-query
    • rel.where(id: rel2.pluck(:id))
    • We may be able to reduce query with replacing pluck with select, but it depends on context.
  • send with public method name
    • foo.send(:foo_public_method) should be foo.foo_public_method
  • str[/substr/]should be str['substr']
    • Maybe typing is overkill?
  • Style/HashTransformValues with not-hash iteration
    • Model.pluck(:id, :val).map { |id, val| [id, foo(val)] }.to_h

I already search the following sources to find cop ideas.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions