rubocop_challenger 2.8.0 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.circleci/config.yml +1 -0
- data/CHANGELOG.md +11 -1
- data/Gemfile.lock +2 -2
- data/README.md +7 -7
- data/lib/rubocop_challenger/cli.rb +3 -3
- data/lib/rubocop_challenger/errors.rb +2 -2
- data/lib/rubocop_challenger/go.rb +6 -6
- data/lib/rubocop_challenger/rubocop/challenge.rb +6 -6
- data/lib/rubocop_challenger/rubocop/command.rb +4 -4
- data/lib/rubocop_challenger/rubocop/rule.rb +4 -3
- data/lib/rubocop_challenger/rubocop/todo_reader.rb +5 -5
- data/lib/rubocop_challenger/rubocop/yardoc.rb +2 -2
- data/lib/rubocop_challenger/version.rb +1 -1
- data/lib/templates/checklist.md.erb +2 -2
- data/lib/templates/default.md.erb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5a129ffbdfa720d2d61386e268ccfbff06005cd0f59f04ff5e4fbc843a82b0c
|
4
|
+
data.tar.gz: 7a6a2de90d5077852ab9c8ae16a9cb409b4319136a776bf1f82fc614c44b1011
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 046a667891ec84c62ae768b3ba3ef28ab906c2e4e4df94bbb74950ab6db66c0157290975d223a0d1fe1d49d1d026ab88a8870195a1d0c6c09d866aaa80f1cd55
|
7
|
+
data.tar.gz: cc60705e93e82bd5d482ddc7a7b493f636e60286cf83527cf6dbddc1538a47dac18d7f014ea0935c9c5ec3725faff9f15154275330ac570fbe0b84df85140dbd
|
data/.circleci/config.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,15 +1,25 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## v2.9.0 (Jun 02, 2022)
|
4
|
+
|
5
|
+
### Feature
|
6
|
+
|
7
|
+
- [#628](https://github.com/ryz310/rubocop_challenger/pull/628) Change `auto-correct` to `autocorrect` ([@ryz310](https://github.com/ryz310))
|
8
|
+
|
9
|
+
### Dependabot
|
10
|
+
|
11
|
+
- [#629](https://github.com/ryz310/rubocop_challenger/pull/629) Bump yard from 0.9.27 to 0.9.28 ([@ryz310](https://github.com/ryz310))
|
12
|
+
|
3
13
|
## v2.8.0 (May 30, 2022)
|
4
14
|
|
5
15
|
### Feature
|
6
16
|
|
7
17
|
- [#616](https://github.com/ryz310/rubocop_challenger/pull/616) Support `--no-offense-counts` option ([@ryz310](https://github.com/ryz310))
|
18
|
+
- [#625](https://github.com/ryz310/rubocop_challenger/pull/625) Use `--conservative` option on `bundle update` ([@ryz310](https://github.com/ryz310))
|
8
19
|
|
9
20
|
### Bugfix
|
10
21
|
|
11
22
|
- [#612](https://github.com/ryz310/rubocop_challenger/pull/612) Fix wrong usage of `Array#reject!`: this might return nil ([@r7kamura](https://github.com/r7kamura))
|
12
|
-
- [#625](https://github.com/ryz310/rubocop_challenger/pull/625) Use `--conservative` option on `bundle update` ([@ryz310](https://github.com/ryz310))
|
13
23
|
|
14
24
|
### Breaking Change
|
15
25
|
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rubocop_challenger (2.
|
4
|
+
rubocop_challenger (2.9.0)
|
5
5
|
pr_comet (>= 0.5.1, < 0.7.0)
|
6
6
|
rainbow
|
7
7
|
rubocop (>= 0.87)
|
@@ -113,7 +113,7 @@ GEM
|
|
113
113
|
concurrent-ruby (~> 1.0)
|
114
114
|
unicode-display_width (2.1.0)
|
115
115
|
webrick (1.7.0)
|
116
|
-
yard (0.9.
|
116
|
+
yard (0.9.28)
|
117
117
|
webrick (~> 1.7.0)
|
118
118
|
|
119
119
|
PLATFORMS
|
data/README.md
CHANGED
@@ -3,14 +3,14 @@
|
|
3
3
|
[](https://circleci.com/gh/ryz310/rubocop_challenger/tree/master) [](https://badge.fury.io/rb/rubocop_challenger) [](https://codeclimate.com/github/ryz310/rubocop_challenger/maintainability) [](https://codeclimate.com/github/ryz310/rubocop_challenger/test_coverage)
|
4
4
|
|
5
5
|
If you introduce [`rubocop`](https://github.com/rubocop-hq/rubocop) to an existing Rails project later, you will use [`$ rubocop --auto-gen-config`](https://github.com/rubocop-hq/rubocop/blob/master/manual/configuration.md#automatically-generated-configuration). But it will make a huge `.rubocop_todo.yml` and make you despair.
|
6
|
-
On the other hand, `rubocop` has [`--
|
6
|
+
On the other hand, `rubocop` has [`--autocorrect`](https://github.com/rubocop-hq/rubocop/blob/master/manual/basic_usage.md#other-useful-command-line-flags) option, it is possible to automatically repair the writing which does not conform to the rule. But since it occasionally destroys your code, it is quite dangerous to apply all at once.
|
7
7
|
It is ideal that to remove a disabled rule from `.rubocop_todo.yml` every day, to check whether it passes test, and can be obtained consent from the team. But it requires strong persistence and time.
|
8
8
|
I call such work _Rubocop Challenge_. And the _RubocopChallenger_ is a gem to support this challenge!
|
9
9
|
|
10
10
|
## The history of RubocopChallenger with decrease of offense codes
|
11
11
|
|
12
|
-
The following chart shows the history of RubocopChallenger and decrease of offense codes at a `.rubocop_todo.yml`. The project was released at 5 years ago, and then it was introduced the RuboCop gem for huge source code including a lots of offense codes. Before using the RubocopChallenger, it was not maintain to reduce offense codes. One day, I felt a crisis and started maintain with manual. I made a lots of Pull Requests to reduce them but it's a load for me and reviewers. So I created a script for automation the flow, which is the predecessor of Rubocop Challenger gem. It brought reducing the offense codes continuously. After 8 months, finally it has done. There is no
|
13
|
-
But there are many offenses which is un-
|
12
|
+
The following chart shows the history of RubocopChallenger and decrease of offense codes at a `.rubocop_todo.yml`. The project was released at 5 years ago, and then it was introduced the RuboCop gem for huge source code including a lots of offense codes. Before using the RubocopChallenger, it was not maintain to reduce offense codes. One day, I felt a crisis and started maintain with manual. I made a lots of Pull Requests to reduce them but it's a load for me and reviewers. So I created a script for automation the flow, which is the predecessor of Rubocop Challenger gem. It brought reducing the offense codes continuously. After 8 months, finally it has done. There is no autocorrectable offense codes.
|
13
|
+
But there are many offenses which is un-autocorrectable yet. I will try to reduce it with the RubocopChallenger. The RubocopChallenger will
|
14
14
|
be continued to evolve.
|
15
15
|
|
16
16
|

|
@@ -18,7 +18,7 @@ be continued to evolve.
|
|
18
18
|
## Rubocop Challenge Flow
|
19
19
|
|
20
20
|
1. Run _RubocopChallenger_ periodically from CI tool etc.
|
21
|
-
1. When _RubocopChallenger_ starts, delete a disabled rule from `.rubocop_todo.yml` existing in your project, execute `$ rubocop --
|
21
|
+
1. When _RubocopChallenger_ starts, delete a disabled rule from `.rubocop_todo.yml` existing in your project, execute `$ rubocop --autocorrect` and create a PR which include modified results
|
22
22
|
1. You confirm the PR passes testing and then merge it if there is no problem
|
23
23
|
|
24
24
|
[](https://github.com/ryz310/rubocop_challenger/pull/97)
|
@@ -88,7 +88,7 @@ See: [RuboCop Challenger を GitHub Actions で動かす](https://zenn.dev/yamat
|
|
88
88
|
$ rubocop_challenger help
|
89
89
|
|
90
90
|
Commands:
|
91
|
-
rubocop_challenger go --email=EMAIL --name=NAME # Run `$ rubocop --
|
91
|
+
rubocop_challenger go --email=EMAIL --name=NAME # Run `$ rubocop --autocorrect` and create a PR to GitHub repo
|
92
92
|
rubocop_challenger help [COMMAND] # Describe available commands or one specific command
|
93
93
|
rubocop_challenger version # Show current version
|
94
94
|
```
|
@@ -122,10 +122,10 @@ Options:
|
|
122
122
|
# Default: true
|
123
123
|
[--offense-counts], [--no-offense-counts] # Include offense counts in .rubocop_todo.yml
|
124
124
|
# Default: true
|
125
|
-
[--only-safe-
|
125
|
+
[--only-safe-autocorrect], [--no-only-safe-autocorrect] # If given `true`, it executes `rubocop --autocorrect`,it means to correct safe cops only.
|
126
126
|
[--verbose], [--no-verbose] # Displays executing command.
|
127
127
|
|
128
|
-
Run `$ rubocop --
|
128
|
+
Run `$ rubocop --autocorrect` and create a PR to GitHub repo
|
129
129
|
```
|
130
130
|
|
131
131
|
## Requirement
|
@@ -5,7 +5,7 @@ require 'thor'
|
|
5
5
|
module RubocopChallenger
|
6
6
|
# To define CLI commands
|
7
7
|
class CLI < Thor
|
8
|
-
desc 'go', 'Run `$ rubocop --
|
8
|
+
desc 'go', 'Run `$ rubocop --autocorrect` and create a PR to GitHub repo'
|
9
9
|
option :email,
|
10
10
|
required: true,
|
11
11
|
type: :string,
|
@@ -65,10 +65,10 @@ module RubocopChallenger
|
|
65
65
|
type: :boolean,
|
66
66
|
default: true,
|
67
67
|
desc: 'Include offense counts in .rubocop_todo.yml'
|
68
|
-
option :
|
68
|
+
option :only_safe_autocorrect,
|
69
69
|
type: :boolean,
|
70
70
|
default: false,
|
71
|
-
desc: 'If given `true`, it executes `rubocop --
|
71
|
+
desc: 'If given `true`, it executes `rubocop --autocorrect`,' \
|
72
72
|
'it means to correct safe cops only.'
|
73
73
|
option :verbose,
|
74
74
|
type: :boolean,
|
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
module RubocopChallenger
|
4
4
|
module Errors
|
5
|
-
# Raise if no
|
5
|
+
# Raise if no autocorrectable rule in the `.rubocop_todo.yml`.
|
6
6
|
class NoAutoCorrectableRule < StandardError
|
7
7
|
def initialize
|
8
|
-
super 'There is no
|
8
|
+
super 'There is no autocorrectable rule'
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -11,8 +11,8 @@ module RubocopChallenger
|
|
11
11
|
# Include the date and time in .rubocop_todo.yml
|
12
12
|
# @option offense_counts [Boolean]
|
13
13
|
# Include offense counts in .rubocop_todo.yml'
|
14
|
-
# @option only-safe-
|
15
|
-
# If given `true`, it executes `rubocop --
|
14
|
+
# @option only-safe-autocorrect [Boolean]
|
15
|
+
# If given `true`, it executes `rubocop --autocorrect`,
|
16
16
|
# it means to correct safe cops only.
|
17
17
|
# @option name [String]
|
18
18
|
# The author name which use at the git commit
|
@@ -131,7 +131,7 @@ module RubocopChallenger
|
|
131
131
|
end
|
132
132
|
|
133
133
|
DESCRIPTION_THAT_CHALLENGE_IS_INCOMPLETE = <<~MSG
|
134
|
-
Rubocop Challenger has executed
|
134
|
+
Rubocop Challenger has executed autocorrecting but it is incomplete.
|
135
135
|
Therefore the rule add to ignore list.
|
136
136
|
MSG
|
137
137
|
|
@@ -141,7 +141,7 @@ module RubocopChallenger
|
|
141
141
|
#
|
142
142
|
# @param rule [Rubocop::Rule] The corrected rule
|
143
143
|
def add_to_ignore_list_if_challenge_is_incomplete(rule)
|
144
|
-
return unless
|
144
|
+
return unless autocorrect_incomplete?(rule)
|
145
145
|
|
146
146
|
pull_request.commit! ':police_car: add the rule to the ignore list' do
|
147
147
|
config_editor = Rubocop::ConfigEditor.new
|
@@ -156,7 +156,7 @@ module RubocopChallenger
|
|
156
156
|
#
|
157
157
|
# @param rule [Rubocop::Rule] The corrected rule
|
158
158
|
# @return [Boolean] Return true if the challenge successed
|
159
|
-
def
|
159
|
+
def autocorrect_incomplete?(rule)
|
160
160
|
todo_reader = Rubocop::TodoReader.new(options[:file_path])
|
161
161
|
todo_reader.all_rules.include?(rule)
|
162
162
|
end
|
@@ -165,7 +165,7 @@ module RubocopChallenger
|
|
165
165
|
{
|
166
166
|
file_path: options[:file_path],
|
167
167
|
mode: mode,
|
168
|
-
|
168
|
+
only_safe_autocorrect: options[:only_safe_autocorrect]
|
169
169
|
}
|
170
170
|
end
|
171
171
|
|
@@ -4,17 +4,17 @@ module RubocopChallenger
|
|
4
4
|
module Rubocop
|
5
5
|
# To execute Rubocop Challenge flow
|
6
6
|
class Challenge
|
7
|
-
def self.exec(file_path:, mode:,
|
8
|
-
new(file_path, mode,
|
7
|
+
def self.exec(file_path:, mode:, only_safe_autocorrect:)
|
8
|
+
new(file_path, mode, only_safe_autocorrect).send(:exec)
|
9
9
|
end
|
10
10
|
|
11
11
|
private
|
12
12
|
|
13
|
-
attr_reader :mode, :
|
13
|
+
attr_reader :mode, :only_safe_autocorrect, :command, :todo_reader, :todo_writer
|
14
14
|
|
15
|
-
def initialize(file_path, mode,
|
15
|
+
def initialize(file_path, mode, only_safe_autocorrect)
|
16
16
|
@mode = mode
|
17
|
-
@
|
17
|
+
@only_safe_autocorrect = only_safe_autocorrect
|
18
18
|
@command = Rubocop::Command.new
|
19
19
|
@todo_reader = Rubocop::TodoReader.new(file_path)
|
20
20
|
@todo_writer = Rubocop::TodoWriter.new(file_path)
|
@@ -24,7 +24,7 @@ module RubocopChallenger
|
|
24
24
|
def exec
|
25
25
|
verify_target_rule
|
26
26
|
todo_writer.delete_rule(target_rule)
|
27
|
-
command.
|
27
|
+
command.autocorrect(only_safe_autocorrect: only_safe_autocorrect)
|
28
28
|
target_rule
|
29
29
|
end
|
30
30
|
|
@@ -7,11 +7,11 @@ module RubocopChallenger
|
|
7
7
|
include PrComet::CommandLine
|
8
8
|
|
9
9
|
# Executes auto correction
|
10
|
-
def
|
11
|
-
if
|
12
|
-
run('
|
10
|
+
def autocorrect(only_safe_autocorrect:)
|
11
|
+
if only_safe_autocorrect
|
12
|
+
run('-a') # --autocorrect Autocorrect offenses (only when it's safe).
|
13
13
|
else
|
14
|
-
run('--
|
14
|
+
run('-A') # --autocorrect-all Autocorrect offenses (safe and unsafe).
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -26,9 +26,10 @@ module RubocopChallenger
|
|
26
26
|
offense_count <=> other.offense_count
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
30
|
-
contents.
|
31
|
-
contents.match?(/# This cop supports (un)?safe auto-correction/) # for rubocop >= v1.26.0
|
29
|
+
def autocorrectable?
|
30
|
+
contents.match?('# This cop supports (un)?safe autocorrection') || # for rubocop >= v1.30.0
|
31
|
+
contents.match?(/# This cop supports (un)?safe auto-correction/) || # for rubocop >= v1.26.0
|
32
|
+
contents.include?('# Cop supports --auto-correct') # for rubocop < v1.26.0
|
32
33
|
end
|
33
34
|
|
34
35
|
def rubydoc_url
|
@@ -29,23 +29,23 @@ module RubocopChallenger
|
|
29
29
|
end
|
30
30
|
|
31
31
|
# @return [Array<Rule>]
|
32
|
-
def
|
33
|
-
all_rules.select(&:
|
32
|
+
def autocorrectable_rules
|
33
|
+
all_rules.select(&:autocorrectable?)
|
34
34
|
end
|
35
35
|
|
36
36
|
# @return [Rule]
|
37
37
|
def least_occurrence_rule
|
38
|
-
|
38
|
+
autocorrectable_rules.first
|
39
39
|
end
|
40
40
|
|
41
41
|
# @return [Rule]
|
42
42
|
def most_occurrence_rule
|
43
|
-
|
43
|
+
autocorrectable_rules.last
|
44
44
|
end
|
45
45
|
|
46
46
|
# @return [Rule]
|
47
47
|
def any_rule
|
48
|
-
|
48
|
+
autocorrectable_rules.sample
|
49
49
|
end
|
50
50
|
|
51
51
|
private
|
@@ -18,8 +18,8 @@ module RubocopChallenger
|
|
18
18
|
yardoc.tags('example').map { |tag| [tag.name, tag.text] }
|
19
19
|
end
|
20
20
|
|
21
|
-
# Indicates whether the
|
22
|
-
# If a cop is unsafe its
|
21
|
+
# Indicates whether the autocorrect a cop does is safe (equivalent) by design.
|
22
|
+
# If a cop is unsafe its autocorrect automatically becomes unsafe as well.
|
23
23
|
#
|
24
24
|
# @return [Boolean]
|
25
25
|
def safe_autocorrect?
|
@@ -4,10 +4,10 @@
|
|
4
4
|
|
5
5
|
<% if safe_autocorrect? -%>
|
6
6
|
**Safe autocorrect: Yes**
|
7
|
-
:white_check_mark: The
|
7
|
+
:white_check_mark: The autocorrect a cop does is safe (equivalent) by design.
|
8
8
|
<% else -%>
|
9
9
|
**Safe autocorrect: No**
|
10
|
-
:warning: The
|
10
|
+
:warning: The autocorrect a cop can yield false positives by design.
|
11
11
|
<% end -%>
|
12
12
|
|
13
13
|
## Description
|
@@ -4,10 +4,10 @@
|
|
4
4
|
|
5
5
|
<% if safe_autocorrect? -%>
|
6
6
|
**Safe autocorrect: Yes**
|
7
|
-
:white_check_mark: The
|
7
|
+
:white_check_mark: The autocorrect a cop does is safe (equivalent) by design.
|
8
8
|
<% else -%>
|
9
9
|
**Safe autocorrect: No**
|
10
|
-
:warning: The
|
10
|
+
:warning: The autocorrect a cop can yield false positives by design.
|
11
11
|
<% end -%>
|
12
12
|
|
13
13
|
## Description
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop_challenger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ryosuke_sato
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pr_comet
|