rubocop-rails icon indicating copy to clipboard operation
rubocop-rails copied to clipboard

Specs for new CallbackOptionsUniqueness cop

Open olliebennett opened this issue 3 years ago • 0 comments

This is an (as-yet) unimplemented cop that I propose for detecting duplicate entries in the only and except options of a controller action's callback.

# @example
#   # bad
#   before_action :my_method, only: %i[index index show]
#
#   # good
#   before_action :my_method, only: %i[index show]

This is a clear user error (not a style preference) and goes undetected. We found an instance of this (although more contrived and subtle than the above example).

This may be too niche to warrant implementing, in which case please do close the PR. :) If useful though, I'm happy to take a stab at implementation or else for anyone else to take it on if they are keen. I'm sure the latter would be faster! I thought some specs would help kick things off anyway.

I'm open to any other naming suggestions, or broader scope if we think of other scenarios where duplication is guaranteed to be redundant.

Thanks!


Before submitting the PR make sure the following are checked:

  • [x] The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • [x] Wrote good commit messages.
  • [x] Commit message starts with [Fix #issue-number] (if the related issue exists).
    • N/A
  • [ ] Feature branch is up-to-date with master (if not - rebase it).
  • [ ] Squashed related commits together.
  • [x] Added tests.
  • [x] Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • [x] Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.
    • NOTE: There is no changelog directory so added to CHANGELOG.md directly.
  • [x] If this is a new cop, consider making a corresponding update to the Rails Style Guide.
    • NOTE Not necessary since this is almost certainly a user omission, not a 'style' to follow.

olliebennett avatar Jun 17 '22 22:06 olliebennett