KEMBAR78
[Fix #5887] Remove `Lint/SplatKeywordArguments` cop by koic · Pull Request #5892 · rubocop/rubocop · GitHub
Skip to content

Conversation

@koic
Copy link
Member

@koic koic commented May 16, 2018

Closes #5887.

This PR removes Lint/SplatKeywordArguments cop.

The following is an example from #5887.

options = { opt1: 1, opt2: 2 }
def method1(kw_args); end

def method2(**kw_args); end

method1(**options) # This will warn in ruby 2.6 and currently warns in rubocop.

method2(**options) # This does not warn in ruby 2.6 and should not warn in rubocop.

This cop will occur a false positive in method2 case.
However, it seems that there is still no way to know the method signature of receiver object by static analysis mechanism (I might just don't know it) .

What this cop was trying to realize is emulating experimental warnings for Ruby 2.6. And that is something of the future. So this PR will remove this cop until the prospect of existing problem solving.

I thought about setting the default to disabled, but it seemed that it was not good to be in a condition that it could be used with reported false positives.


Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Run rake default or rake parallel. It executes all tests and RuboCop for itself, and generates the documentation.

@koic koic force-pushed the remove_splat_keyword_arguments branch from 5fccf37 to 75a885c Compare May 16, 2018 13:18
CHANGELOG.md Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be under master.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! I fixed it 💦

Closes rubocop#5887.

This PR removes `Lint/SplatKeywordArguments` cop.

The following is an example from rubocop#5887.

```ruby
options = { opt1: 1, opt2: 2 }
def method1(kw_args); end

def method2(**kw_args); end

method1(**options) # This will warn in ruby 2.6 and currently warns in rubocop.

method2(**options) # This does not warn in ruby 2.6 and should not warn in rubocop.
```

This cop will occur a false positive in `method2` case.
However, it seems that there is still no way to know
the method signature of receiver object by static analysis
mechanism (I might just don't know it) .

What this cop was trying to realize is emulating experimental
warnings for Ruby 2.6. And that is something of the future.
So this PR will remove this cop until the prospect of existing
problem solving.

I thought about setting the default to disabled, but it seemed that it
was not good to be in a condition that it could be used with reported
false positives.
@koic koic force-pushed the remove_splat_keyword_arguments branch from 75a885c to 4b91183 Compare May 16, 2018 13:49
@bbatsov bbatsov merged commit 9f976de into rubocop:master May 17, 2018
@koic koic deleted the remove_splat_keyword_arguments branch May 17, 2018 07:59
albertchae added a commit to hackclub/hcb that referenced this pull request May 6, 2023
## TL;DR
I ran the spec suite with `RUBYOPT='-W:deprecated'` and fixed all the
issues that seemed like true positives. I propose we set this
environment variable in prod for a few days and then grep the logs to
find additional cases to fix, since our spec suite is not comprehensive.

## Full details
Ruby 3 introduced new rules around keyword arguments.
-
https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/
- https://github.com/ruby/ruby/blob/v3_0_0/NEWS.md
-
https://www.fastruby.io/blog/ruby/upgrades/upgrade-ruby-from-2.7-to-3.0.html

Originally in Ruby 2.7, we would see deprecation warnings for these such
as `warning: Using the last argument as keyword parameters is
deprecated; maybe ** should be added to the call`

However, it turns out they got turned off in 2.7.2 because people
complained they were too noisy
- https://www.ruby-lang.org/en/news/2020/10/02/ruby-2-7-2-released/
- https://bugs.ruby-lang.org/issues/17000
-
https://discuss.rubyonrails.org/t/new-2-7-3-0-keyword-argument-pain-point/74980

To get the previous deprecation warning behavior, we have to run with
`RUBYOPT='-W:deprecated'`. So I ran the spec suite with that environment
variable and fixed all the issues (except for a few involving
ActiveRecord::Enum which I'm still investigating whether they are false
positives). Many of these changes were in spec only but some were in app
code too.

Because the spec suite isn't comprehensive, I propose we turn on the
environment variable in production as well and examine logs after. We
could try to intelligently log deprecation warnings to airbrake in the
same vein as https://gitlab.com/gitlab-org/gitlab/-/merge_requests/66815
and https://www.bugsnag.com/blog/managing-warnings-in-ruby, but I think
these approaches might be overkill for bank.

P.S. I thought there might be a rubocop rule that could help us, but
apparently it was disabled for too many false positives
- rubocop/rubocop#5871
- rubocop/rubocop#5887
- rubocop/rubocop#5892

Gitlab wrote a custom rubocop to fix warnings in their codebase, which I
also think is overkill for bank


https://about.gitlab.com/blog/2021/02/03/how-we-automatically-fixed-hundreds-of-ruby-2-7-deprecation-warnings/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants