Skip to content

Instantly share code, notes, and snippets.

@Morozzzko
Created November 10, 2020 09:18
Show Gist options
  • Select an option

  • Save Morozzzko/94478156f1c14c822f5db791fc339069 to your computer and use it in GitHub Desktop.

Select an option

Save Morozzzko/94478156f1c14c822f5db791fc339069 to your computer and use it in GitHub Desktop.
Automatically apply fix for new cops
# frozen_string_literal: true
cop_regex = %r{`(.*)` cop}
# See changelog at
#
# https://raw.githubusercontent.com/rubocop-hq/rubocop/master/CHANGELOG.md
#
# Well-formatted changelog:
# https://github.com/rubocop-hq/rubocop/blob/master/CHANGELOG.md
changelog = <<~MARKDOWN
* [#7876](https://github.com/rubocop-hq/rubocop/issues/7876): Enhance `Gemspec/RequiredRubyVersion` cop with check that `required_ruby_version` is specified. ([@fatkodima][])
* [#8291](https://github.com/rubocop-hq/rubocop/pull/8291): Add new `Lint/SelfAssignment` cop. ([@fatkodima][])
* [#8389](https://github.com/rubocop-hq/rubocop/pull/8389): Add new `Lint/DuplicateRescueException` cop. ([@fatkodima][])
* [#8433](https://github.com/rubocop-hq/rubocop/pull/8433): Add new `Lint/BinaryOperatorWithIdenticalOperands` cop. ([@fatkodima][])
* [#8430](https://github.com/rubocop-hq/rubocop/pull/8430): Add new `Lint/UnreachableLoop` cop. ([@fatkodima][])
* [#8412](https://github.com/rubocop-hq/rubocop/pull/8412): Add new `Style/OptionalBooleanParameter` cop. ([@fatkodima][])
* [#8432](https://github.com/rubocop-hq/rubocop/pull/8432): Add new `Lint/FloatComparison` cop. ([@fatkodima][])
* [#8376](https://github.com/rubocop-hq/rubocop/pull/8376): Add new `Lint/MissingSuper` cop. ([@fatkodima][])
* [#8415](https://github.com/rubocop-hq/rubocop/pull/8415): Add new `Style/ExplicitBlockArgument` cop. ([@fatkodima][])
* [#5067](https://github.com/rubocop-hq/rubocop/issues/5067): Add new `Style/StringConcatenation` cop. ([@fatkodima][])
* [#7425](https://github.com/rubocop-hq/rubocop/pull/7425): Add new `Lint/TopLevelReturnWithArgument` cop. ([@iamravitejag][])
* [#8417](https://github.com/rubocop-hq/rubocop/pull/8417): Add new `Style/GlobalStdStream` cop. ([@fatkodima][])
* [#7949](https://github.com/rubocop-hq/rubocop/issues/7949): Add new `Style/SingleArgumentDig` cop. ([@volfgox][])
* [#8341](https://github.com/rubocop-hq/rubocop/pull/8341): Add new `Lint/EmptyConditionalBody` cop. ([@fatkodima][])
* [#7755](https://github.com/rubocop-hq/rubocop/issues/7755): Add new `Lint/OutOfRangeRegexpRef` cop. ([@sonalinavlakhe][])
MARKDOWN
cops = changelog.split("\n").reject(&:empty?).map do |line|
match = cop_regex.match(line)
match[1] if match
end.reject(&:nil?)
puts 'Enable those cops in rubocop.yml: '
cops.each do |cop|
puts <<~YAML
#{cop}:
Enabled: true
YAML
end
cops.each do |cop|
puts "Working with #{cop}"
system(%(bundle exec rubocop -A --only "#{cop}" lib spec app))
system('git add lib spec app')
system(%(git commit -m "[#12226] Autofix #{cop}"))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment