Script to generate file for Rubocop to autocorrect keyword warnings
What does this MR do?
Experiment in using https://github.com/jeremyevans/ruby-warning
Use https://github.com/shopify/deprecation_toolkit, and Rubocop to script a solution for #257438 (closed)
- If a env var is set, we record all deprecated keyword warnings in files under the
deprecations/
folder - We then use the
deprecations/
files in our cop to autocorrect. This is relatively safe (but not 100% safe) as the cop only adds an offense if:
- The source matches the file path, line number, and method name
- The last arg does not have the keyword splat (
**
) applied
Examples
CI
We can mass generate a file using CI.
- Run CI pipeline with the env var set (it should be already set by default in CI)
- Download the files with https://gitlab.com/-/snippets/2040997, copy the resultant
deprecations/
directory to the root of GitLab - Run the cop with:
bundle exec rubocop --only Lint/LastKeywordArgument
The cop is marked unsafe, to autocorrect you need to use -A
If this MR is accepted, I plan to run a mass auto-correction for spec
and ee/spec
(about 100 offenses)
Note the inefficiency if the tmp/keyword_warn.txt
is above 500K (rubocop was CPU bound when the tmp/keyword_warn.txt
was 2.2MB), hence the snippet will de-duplicate occurences.
Edited by Thong Kuah