rubocop_challenger 2.0.0.pre10 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,12 +21,15 @@ module RubocopChallenger
21
21
  # A target project ID. If does not supplied, this method will find a
22
22
  # project which associated the repository. When the repository has
23
23
  # multiple projects, you should supply this.
24
- def initialize(user_name:, user_email:, **options)
24
+ # @option verbose [Boolean]
25
+ # Displays executing command.
26
+ def initialize(user_name:, user_email:, **options) # rubocop:disable Metrics/MethodLength
25
27
  @pr_comet = PrComet.new(
26
28
  base: options[:base_branch],
27
29
  branch: "rubocop-challenge/#{timestamp}",
28
30
  user_name: user_name,
29
- user_email: user_email
31
+ user_email: user_email,
32
+ verbose: options[:verbose]
30
33
  )
31
34
  @labels = options[:labels]
32
35
  @dry_run = options[:dry_run]
@@ -90,7 +93,7 @@ module RubocopChallenger
90
93
  project_id: project_id
91
94
  }.merge(pr_comet_options)
92
95
 
93
- pr_comet.create!(options) unless dry_run
96
+ pr_comet.create!(**options) unless dry_run
94
97
  end
95
98
 
96
99
  # @param before_version [String]
@@ -4,16 +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).send(:exec)
7
+ def self.exec(file_path:, mode:, only_safe_auto_correct:)
8
+ new(file_path, mode, only_safe_auto_correct).send(:exec)
9
9
  end
10
10
 
11
11
  private
12
12
 
13
- attr_reader :mode, :command, :todo_reader, :todo_writer
13
+ attr_reader :mode, :only_safe_auto_correct, :command, :todo_reader, :todo_writer
14
14
 
15
- def initialize(file_path, mode)
15
+ def initialize(file_path, mode, only_safe_auto_correct)
16
16
  @mode = mode
17
+ @only_safe_auto_correct = only_safe_auto_correct
17
18
  @command = Rubocop::Command.new
18
19
  @todo_reader = Rubocop::TodoReader.new(file_path)
19
20
  @todo_writer = Rubocop::TodoWriter.new(file_path)
@@ -23,7 +24,7 @@ module RubocopChallenger
23
24
  def exec
24
25
  verify_target_rule
25
26
  todo_writer.delete_rule(target_rule)
26
- command.auto_correct
27
+ command.auto_correct(only_safe_auto_correct: only_safe_auto_correct)
27
28
  target_rule
28
29
  end
29
30
 
@@ -7,8 +7,12 @@ module RubocopChallenger
7
7
  include PrComet::CommandLine
8
8
 
9
9
  # Executes auto correction
10
- def auto_correct
11
- run('--auto-correct')
10
+ def auto_correct(only_safe_auto_correct:)
11
+ if only_safe_auto_correct
12
+ run('--auto-correct')
13
+ else
14
+ run('--auto-correct-all')
15
+ end
12
16
  end
13
17
 
14
18
  # Generates `.rubocop_todo.yml`
@@ -27,7 +27,7 @@ module RubocopChallenger
27
27
  end
28
28
 
29
29
  def auto_correctable?
30
- contents =~ /# Cop supports --auto-correct/
30
+ contents.include?('# Cop supports --auto-correct')
31
31
  end
32
32
 
33
33
  def rubydoc_url
@@ -4,12 +4,10 @@ module RubocopChallenger
4
4
  module Rubocop
5
5
  # To read YARD style documentation from rubocop gem source code
6
6
  class Yardoc
7
- def initialize(title)
7
+ def initialize(cop)
8
8
  load_rspec_gems!
9
- @cop_class = find_cop_class(title)
10
- YARD.parse(source_file_path)
11
- @yardoc = YARD::Registry.all(:class).first
12
- YARD::Registry.clear
9
+ @cop_class = find_cop_class(cop)
10
+ load_yardoc!
13
11
  end
14
12
 
15
13
  def description
@@ -20,6 +18,15 @@ module RubocopChallenger
20
18
  yardoc.tags('example').map { |tag| [tag.name, tag.text] }
21
19
  end
22
20
 
21
+ # Indicates whether the auto-correct a cop does is safe (equivalent) by design.
22
+ # If a cop is unsafe its auto-correct automatically becomes unsafe as well.
23
+ #
24
+ # @return [Boolean]
25
+ def safe_autocorrect?
26
+ config = RuboCop::ConfigLoader.default_configuration
27
+ cop_class.new(config).safe_autocorrect?
28
+ end
29
+
23
30
  private
24
31
 
25
32
  attr_reader :cop_class, :yardoc
@@ -27,23 +34,28 @@ module RubocopChallenger
27
34
  # Loads gems for YARDoc creation
28
35
  def load_rspec_gems!
29
36
  RSPEC_GEMS.each do |dependency|
30
- begin
31
- require dependency
32
- rescue LoadError
33
- nil
34
- end
37
+ require dependency
38
+ rescue LoadError
39
+ nil
35
40
  end
36
41
  end
37
42
 
38
43
  # Find a RuboCop class by cop name. It find from rubocop/rspec if cannot
39
44
  # find any class from rubocop gem.
40
45
  #
41
- # @param cop_name [String] The target cop name
42
- # @return [Class] Found RuboCop class
43
- def find_cop_class(cop_name)
44
- Object.const_get("RuboCop::Cop::#{cop_name.sub('/', '::')}")
46
+ # @param cop [String] The target cop name (e.g. "Performance/Size")
47
+ # @return [RuboCop::Cop] Found a RuboCop::Cop class
48
+ def find_cop_class(cop)
49
+ Object.const_get("RuboCop::Cop::#{cop.sub('/', '::')}")
45
50
  rescue NameError
46
- Object.const_get("RuboCop::Cop::RSpec::#{cop_name.sub('/', '::')}")
51
+ Object.const_get("RuboCop::Cop::RSpec::#{cop.sub('/', '::')}")
52
+ end
53
+
54
+ # Loads yardoc from the RuboCop::Cop class file
55
+ def load_yardoc!
56
+ YARD.parse(source_file_path)
57
+ @yardoc = YARD::Registry.all(:class).first
58
+ YARD::Registry.clear
47
59
  end
48
60
 
49
61
  def instance_methods
@@ -54,11 +66,15 @@ module RubocopChallenger
54
66
  end
55
67
 
56
68
  def source_file_path
57
- instance_methods
58
- .map { |m| cop_class.instance_method(m).source_location }
59
- .reject(&:nil?)
60
- .map(&:first)
61
- .first
69
+ if Object.respond_to?(:const_source_location)
70
+ Object.const_source_location(cop_class.name).first
71
+ else
72
+ instance_methods
73
+ .map { |m| cop_class.instance_method(m).source_location }
74
+ .reject(&:nil?)
75
+ .map(&:first)
76
+ .first
77
+ end
62
78
  end
63
79
  end
64
80
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubocopChallenger
4
- VERSION = '2.0.0.pre10'
4
+ VERSION = '2.3.0'
5
5
  end
@@ -2,6 +2,14 @@
2
2
 
3
3
  [<%= title %>](<%= rubydoc_url %>)
4
4
 
5
+ <% if safe_autocorrect? -%>
6
+ **Safe autocorrect: true**
7
+ :white_check_mark: The auto-correct a cop does is safe (equivalent) by design.
8
+ <% else -%>
9
+ **Safe autocorrect: false**
10
+ :warning: The auto-correct a cop can yield false positives by design.
11
+ <% end -%>
12
+
5
13
  ## Description
6
14
 
7
15
  > ### Overview
@@ -2,6 +2,14 @@
2
2
 
3
3
  [<%= title %>](<%= rubydoc_url %>)
4
4
 
5
+ <% if safe_autocorrect? -%>
6
+ **Safe autocorrect: true**
7
+ :white_check_mark: The auto-correct a cop does is safe (equivalent) by design.
8
+ <% else -%>
9
+ **Safe autocorrect: false**
10
+ :warning: The auto-correct a cop can yield false positives by design.
11
+ <% end -%>
12
+
5
13
  ## Description
6
14
 
7
15
  > ### Overview
@@ -4,7 +4,7 @@
4
4
 
5
5
  ## Description
6
6
 
7
- Sorry! Something went wrong! :bow:
7
+ Failed to create the cop description.
8
8
  Please report bugs [here](https://github.com/ryz310/rubocop_challenger/issues/new?assignees=ryz310&labels=bug&template=bug_report.md) with following error information.
9
9
 
10
10
  ```
metadata CHANGED
@@ -1,37 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop_challenger
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre10
4
+ version: 2.3.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: 2019-10-18 00:00:00.000000000 Z
11
+ date: 2021-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pr_comet
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.2'
20
- - - "<"
19
+ version: 0.5.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
21
25
  - !ruby/object:Gem::Version
22
- version: '0.4'
26
+ version: 0.5.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rainbow
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
23
34
  type: :runtime
24
35
  prerelease: false
25
36
  version_requirements: !ruby/object:Gem::Requirement
26
37
  requirements:
27
38
  - - ">="
28
39
  - !ruby/object:Gem::Version
29
- version: '0.2'
30
- - - "<"
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
31
46
  - !ruby/object:Gem::Version
32
- version: '0.4'
47
+ version: '0.87'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0.87'
33
55
  - !ruby/object:Gem::Dependency
34
- name: rainbow
56
+ name: rubocop-performance
35
57
  requirement: !ruby/object:Gem::Requirement
36
58
  requirements:
37
59
  - - ">="
@@ -45,7 +67,7 @@ dependencies:
45
67
  - !ruby/object:Gem::Version
46
68
  version: '0'
47
69
  - !ruby/object:Gem::Dependency
48
- name: rubocop
70
+ name: rubocop-rails
49
71
  requirement: !ruby/object:Gem::Requirement
50
72
  requirements:
51
73
  - - ">="
@@ -59,7 +81,7 @@ dependencies:
59
81
  - !ruby/object:Gem::Version
60
82
  version: '0'
61
83
  - !ruby/object:Gem::Dependency
62
- name: rubocop-performance
84
+ name: rubocop-rake
63
85
  requirement: !ruby/object:Gem::Requirement
64
86
  requirements:
65
87
  - - ">="
@@ -118,16 +140,16 @@ dependencies:
118
140
  name: bundler
119
141
  requirement: !ruby/object:Gem::Requirement
120
142
  requirements:
121
- - - "~>"
143
+ - - ">="
122
144
  - !ruby/object:Gem::Version
123
- version: '1.16'
145
+ version: '2.0'
124
146
  type: :development
125
147
  prerelease: false
126
148
  version_requirements: !ruby/object:Gem::Requirement
127
149
  requirements:
128
- - - "~>"
150
+ - - ">="
129
151
  - !ruby/object:Gem::Version
130
- version: '1.16'
152
+ version: '2.0'
131
153
  - !ruby/object:Gem::Dependency
132
154
  name: pry-byebug
133
155
  requirement: !ruby/object:Gem::Requirement
@@ -188,16 +210,16 @@ dependencies:
188
210
  name: simplecov
189
211
  requirement: !ruby/object:Gem::Requirement
190
212
  requirements:
191
- - - ">="
213
+ - - '='
192
214
  - !ruby/object:Gem::Version
193
- version: '0'
215
+ version: 0.21.2
194
216
  type: :development
195
217
  prerelease: false
196
218
  version_requirements: !ruby/object:Gem::Requirement
197
219
  requirements:
198
- - - ">="
220
+ - - '='
199
221
  - !ruby/object:Gem::Version
200
- version: '0'
222
+ version: 0.21.2
201
223
  description: Make a clean your rubocop_todo.yml with CI
202
224
  email:
203
225
  - r-sato@feedforce.jp
@@ -207,12 +229,14 @@ extensions: []
207
229
  extra_rdoc_files: []
208
230
  files:
209
231
  - ".circleci/config.yml"
232
+ - ".dependabot/config.yml"
210
233
  - ".envrc.skeleton"
211
234
  - ".gem_comet.yml"
212
235
  - ".github/ISSUE_TEMPLATE/bug_report.md"
213
236
  - ".gitignore"
214
237
  - ".rspec"
215
238
  - ".rubocop.yml"
239
+ - ".rubocop_challenge.yml"
216
240
  - ".rubocop_todo.yml"
217
241
  - CHANGELOG.md
218
242
  - CODE_OF_CONDUCT.md
@@ -261,14 +285,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
261
285
  requirements:
262
286
  - - ">="
263
287
  - !ruby/object:Gem::Version
264
- version: '0'
288
+ version: '2.5'
265
289
  required_rubygems_version: !ruby/object:Gem::Requirement
266
290
  requirements:
267
- - - ">"
291
+ - - ">="
268
292
  - !ruby/object:Gem::Version
269
- version: 1.3.1
293
+ version: '0'
270
294
  requirements: []
271
- rubygems_version: 3.0.3
295
+ rubygems_version: 3.2.3
272
296
  signing_key:
273
297
  specification_version: 4
274
298
  summary: Make a clean your rubocop_todo.yml with CI