-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Add new Rails/RefuteMethods
cop
#5801
Conversation
In Rails applications, I think that it is often that RSpec is adopted. so I'm wondering if I should Anyway, I think that there is affect on only |
3b7cdb6
to
735e84f
Compare
config/default.yml
Outdated
@@ -1717,6 +1717,10 @@ Rails/ReadWriteAttribute: | |||
Include: | |||
- app/models/**/*.rb | |||
|
|||
Rails/RefuteMethods: | |||
Include: | |||
- '**/*_test.rb' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note that, this pattern was changed in rails/rails to '**/test/**/*'
see rails/rails#32648
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion. I was wondering whether it was appropriate as a path pattern ('**/test/**/*'
) for Rails applications because the configuration differs from Rails framework repository layout that has a test subdirectory for each components. There is only a little worry about false positives due to misidentification of test subdirectory path, but this path pattern seems that it can be applied to the Rails applications without problem.
## Summary This PR imports a custom cop from rails/rails#32441. The cop name has changed, but behavior is the same. This cop checks for use of `refute` method series. ```ruby # bad refute false refute_empty [1, 2, 3] refute_equal true, false # good assert_not false assert_not_empty [1, 2, 3] assert_not_equal true, false ``` `assert_not` methods are not minitest's memthods. It is an aliases defined in Active Support (`ActiveSupport::TestCase`). https://github.com/rails/rails/blob/v5.2.0/activesupport/lib/active_support/test_case.rb#L54-L68 So I put this cop in Rails department. I think this cop has a useful opportunity in Rails applications. ## Other Information In the near future this PR aims to replace `CustomCops/RefuteNot` cop of rails/rails repo with this `Rails/RefuseMethods` cop.
735e84f
to
2d70d56
Compare
Cool! I didn't even know Rails was making use of custom cops! |
Following the pattern of rubocop#5801, this cop imports a custom cop from rails/rails#32605. This cop checks for the use of `assert !`: ``` assert !foo assert_not foo ``` As in rubocop#5801, since `assert_not` is a method defined in ActiveSupport, this cop belongs in the Rails namespace.
Following the pattern of #5801, this cop imports a custom cop from rails/rails#32605. This cop checks for the use of `assert !`: ``` assert !foo assert_not foo ``` As in #5801, since `assert_not` is a method defined in ActiveSupport, this cop belongs in the Rails namespace.
I realise that this PR is closed now but I only saw this after updating Rubocop. There doesn't appear to be an option to configure Rubocop to prefer |
Yes. This PR imported a custom cop of Rails. It is over as an intention of import. |
Thanks. I see that it is the preferred style in the Rails project itself but I understood that in Rubocop, where there are 'either-or' things like this, there is usually an https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Rails/ActionFilter |
I just discovered this after updating our Rubocop version recently. I followed the discussion as well as I could and couldn't find any reason given for Rails preferring this, and why one is preferred over the other. If anyone has that information, would they mind sharing it with me? In the absence of any rationale, it seems reasonable to have this disabled by default and allow the Rails project and all others that follow the convention to enable it for their projects. @koic, would you mind sharing your insight and opinion? |
Not sure I can give you the full history here, but Minitest: |
That coding style convention is documented in Rails Guide.
http://guides.rubyonrails.org/contributing_to_ruby_on_rails.html#follow-the-coding-conventions |
There is info about |
Am I right that we prefer
That was 5 years ago. As |
Summary
This PR imports a custom cop from rails/rails#32441. The cop name has changed, but behavior is the same.
This cop checks for use of
refute
method series.assert_not
methods are not minitest's memthods.It is an aliases defined in Active Support (
ActiveSupport::TestCase
).https://github.com/rails/rails/blob/v5.2.0/activesupport/lib/active_support/test_case.rb#L54-L68
So I put this cop in Rails department.
I think this cop has a useful opportunity in Rails applications.
Other Information
In the near future this PR aims to replace
CustomCops/RefuteNot
cop of rails/rails repo with thisRails/RefuseMethods
cop. Thanks @y-yagi and @kamipo who suggested importing this cop, @composerinteralia is the original implementer.Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).and description in grammatically correct, complete sentences.
rake default
orrake parallel
. It executes all tests and RuboCop for itself, and generates the documentation.