Skip to content

Script to generate file for Rubocop to autocorrect keyword warnings

Thong Kuah requested to merge keyword_scripter into master

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)

  1. If a env var is set, we record all deprecated keyword warnings in files under the deprecations/ folder
  2. 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.

  1. Run CI pipeline with the env var set (it should be already set by default in CI)
  2. Download the files with https://gitlab.com/-/snippets/2040997, copy the resultant deprecations/ directory to the root of GitLab
  3. 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

Merge request reports