-
-
Notifications
You must be signed in to change notification settings - Fork 263
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
Fix false-positives when constant is used with receiver on Rails/DurationArithmetic
, Rails/IndexBy
, Rails/IndexWIth
, and Rails/RequireDependency
#866
Conversation
@@ -0,0 +1 @@ | |||
* [#866](https://github.com/rubocop/rubocop-rails/pull/866): Fix some false-positives by replacing `const _` with `const {nil? cbase}`. ([@r7kamura][]) |
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.
Can you tweak it? e.g.:
* [#866](https://github.com/rubocop/rubocop-rails/pull/866): Fix some false-positives by replacing `const _` with `const {nil? cbase}`. ([@r7kamura][]) | |
* [#866](https://github.com/rubocop/rubocop-rails/pull/866): Make `Rails/DurationArithmetic`, `Rails/IndexBy`, `Rails/IndexWIth`, and `Rails/RequireDependency` cops aware of const starts with `::`. ([@r7kamura][]) |
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.
Thank you, the recommended example is more user-friendly and easier to understand 👍
Can you add test cases for each cop? |
I am a little hesitant as to whether we should write tests this time because the other places where Do you think even we should write tests only for these 4 cops just because we happen to be changing them this time? I asked this question because I think it is related to the overall testing policy. |
A basic policy is that patches to production code changes should add tests. There is no need to extend to existing working code. |
I see, thanks. So I'll add tests for them 👌 |
9a506a9
to
96e5cf3
Compare
const _
with const {nil? cbase}
::
On second thought, the changes include the eliminations of some false-positives (e.g.
is not quite accurate, is it? In this case, |
@@ -0,0 +1 @@ | |||
* [#866](https://github.com/rubocop/rubocop-rails/pull/866): Make `Rails/DurationArithmetic`, `Rails/IndexBy`, `Rails/IndexWIth`, and `Rails/RequireDependency` cops aware of const that starts with `::`. ([@r7kamura][]) |
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.
How about like this?
* [#866](https://github.com/rubocop/rubocop-rails/pull/866): Make `Rails/DurationArithmetic`, `Rails/IndexBy`, `Rails/IndexWIth`, and `Rails/RequireDependency` cops aware of const that starts with `::`. ([@r7kamura][]) | |
* [#866](https://github.com/rubocop/rubocop-rails/pull/866): Fix false-positives on `Rails/DurationArithmetic`, `Rails/IndexBy`, `Rails/IndexWIth`, and `Rails/RequireDependency` cops. ([@r7kamura][]) |
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.
Sure. It would be even better if there were additional explanations of what false positives were fixed.
new(match, node.children.last, 'Hash['.length, ']'.length) | ||
new(match, node.children.last, "#{node.receiver.source}[".length, ']'.length) |
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.
This is a change that was not originally envisioned for the purpose of "Fix false-positives", but after adding tests, I discovered that there is an autocorrection bug where ::Hash[...]
is used.
Should I separate a Pull Request to fix this bug?
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.
Yeah, you could do it separately because the automatic correction mistake is unclear in the PR's aim to the context.
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, I created the following Pull Request for this autocorrection bug:
96e5cf3
to
ea4a9fb
Compare
::
ea4a9fb
to
e89a53f
Compare
Rails/DurationArithmetic
, Rails/IndexBy
, Rails/IndexWIth
, and Rails/RequireDependency
Rails/DurationArithmetic
, Rails/IndexBy
, Rails/IndexWIth
, and Rails/RequireDependency
Rails/DurationArithmetic
, Rails/IndexBy
, Rails/IndexWIth
, and Rails/RequireDependency
e89a53f
to
ba588dc
Compare
@r7kamura Looks good to me. Can you resolve the conflicting files? |
ba588dc
to
3191081
Compare
In response to the following comment, I reviewed the use of
const _
and found several similar mistakes in the existing code.::Rails
and::File
onRails/FilePath
cop #865 (comment)cc: @koic
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.