rubocop_auto_corrector 0.4.5 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 441e167174a1279880bfd7116306ee17af4a724d71081afba45e10e6eca41312
4
- data.tar.gz: e7866a2e713aa220c12ae604cb696d929f8b21e92495fcb5922a83861b318436
3
+ metadata.gz: 64e6102fe91fd3839e15fb4eb332a0b4fbeb294a5da572dbaef62fafe7743161
4
+ data.tar.gz: 53f1dbbbf0415180b4bae3db5446d787d42a08fed7c021fa8adecd05b78d2393
5
5
  SHA512:
6
- metadata.gz: 9416144dcdfb9d124bd7e0e7debb1c6e83c51ce1e4964664abbad4252cae3bc9ccf44a6745f81a57058704d93b755bd659e3a3eba3c20c7768ce36095794a1c9
7
- data.tar.gz: d1daa1c4eb297c2f78d87be36c990a653f7e9fd3264a03a8769636741c0fa271af4592f47088dd35e18991663ff2f427265f31a780b497d1045e9ca41dd8fd27
6
+ metadata.gz: '09a1afa77bfbfec27f59b2a8661ac41fc320b868263e52c4721b071d0f9afefde6d9b0aff35e4bb70c19777743468d0b0cd935df4e4a952df3f9eaedab97fd59'
7
+ data.tar.gz: a05f259099b5f21bcf1f1835bdc9698518e53cd0ef43f907f0e0f36b1f489b38bfe83e60c4b11f3639d5704fc9ef1d1514bd84cfa224b1ba11adb5a450a2b4a1
data/.rubocop.yml CHANGED
@@ -26,3 +26,7 @@ Layout/LineLength:
26
26
 
27
27
  Style/Documentation:
28
28
  Enabled: false
29
+
30
+ Style/IfUnlessModifier:
31
+ Exclude:
32
+ - Gemfile
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## master
2
- [full changelog](http://github.com/sue445/rubocop_auto_corrector/compare/v0.4.5...master)
2
+ [full changelog](http://github.com/sue445/rubocop_auto_corrector/compare/v0.5.0...master)
3
+
4
+ ## v0.5.0
5
+ [full changelog](http://github.com/sue445/rubocop_auto_corrector/compare/v0.4.5...v0.5.0)
6
+
7
+ * Support rubocop-rspec v3+
8
+ * https://github.com/sue445/rubocop_auto_corrector/pull/69
3
9
 
4
10
  ## v0.4.5
5
11
  [full changelog](http://github.com/sue445/rubocop_auto_corrector/compare/v0.4.4...v0.4.5)
data/Gemfile CHANGED
@@ -6,3 +6,9 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
6
 
7
7
  # Specify your gem's dependencies in rubocop_auto_corrector.gemspec
8
8
  gemspec
9
+
10
+ # rubocop:disable Gemspec/DevelopmentDependencies
11
+ if Gem::Version.create(RUBY_VERSION) >= Gem::Version.create('2.7.0')
12
+ gem 'rubocop-factory_bot'
13
+ end
14
+ # rubocop:enable Gemspec/DevelopmentDependencies
@@ -11,63 +11,100 @@ module RubocopAutoCorrector
11
11
 
12
12
  # Whether this cop is auto correctable
13
13
  # @return [Boolean]
14
- def auto_correctable?
15
- Object.new.instance_eval <<-RUBY, __FILE__, __LINE__ + 1
16
- # begin
17
- # require 'rubocop-rspec'
18
- # rescue LoadError
19
- # end
20
- #
21
- # return ::RuboCop::Cop::RSpec::AlignLeftLetBrace.support_autocorrect? if ::RuboCop::Cop::RSpec::AlignLeftLetBrace.respond_to?(:support_autocorrect?)
22
- # ::RuboCop::Cop::RSpec::AlignLeftLetBrace.new.respond_to?(:autocorrect)
14
+ def auto_correctable? # rubocop:disable Metrics/MethodLength
15
+ cop_candidacies.any? do |cop_candidacy|
16
+ gem_name = cop_candidacy[:gem_name]
17
+ cop_class_name = cop_candidacy[:cop_class_name]
23
18
 
24
- begin
25
- require '#{gem_name}'
26
- rescue LoadError
27
- end
19
+ Object.new.instance_eval <<-RUBY, __FILE__, __LINE__ + 1
20
+ # begin
21
+ # require 'rubocop-rspec'
22
+ # rescue LoadError
23
+ # end
24
+ #
25
+ # return ::RuboCop::Cop::RSpec::AlignLeftLetBrace.support_autocorrect? if ::RuboCop::Cop::RSpec::AlignLeftLetBrace.respond_to?(:support_autocorrect?)
26
+ # ::RuboCop::Cop::RSpec::AlignLeftLetBrace.new.respond_to?(:autocorrect)
28
27
 
29
- return #{cop_class_name}.support_autocorrect? if #{cop_class_name}.respond_to?(:support_autocorrect?)
30
- #{cop_class_name}.new.respond_to?(:autocorrect)
31
- RUBY
32
- rescue NameError
33
- false
34
- end
35
-
36
- # @return [String]
37
- def gem_name
38
- gem_name, = rubocop_cop_info
39
- gem_name
40
- end
28
+ begin
29
+ require '#{gem_name}'
30
+ rescue LoadError
31
+ end
41
32
 
42
- # @return [String]
43
- def cop_class_name
44
- _, cop_class = rubocop_cop_info
45
- cop_class
33
+ return #{cop_class_name}.support_autocorrect? if #{cop_class_name}.respond_to?(:support_autocorrect?)
34
+ #{cop_class_name}.new.respond_to?(:autocorrect)
35
+ RUBY
36
+ rescue NameError
37
+ false
38
+ end
46
39
  end
47
40
 
48
- private
49
-
50
41
  # rubocop:disable Metrics/MethodLength
51
- def rubocop_cop_info
52
- return @rubocop_cop_info if @rubocop_cop_info
53
-
42
+ # @return [Array<Hash<Symbol, String>>]
43
+ def cop_candidacies
54
44
  cop_class_suffix = cop_name.gsub('/', '::')
55
45
 
56
- @rubocop_cop_info =
57
- case cop_name
58
- when %r{^RSpec/}
59
- ['rubocop-rspec', "::RuboCop::Cop::#{cop_class_suffix}"]
60
- when %r{^(FactoryBot|Capybara)/}, 'Rails/HttpStatus'
61
- ['rubocop-rspec', "::RuboCop::Cop::RSpec::#{cop_class_suffix}"]
62
- when %r{^(Layout|Lint|Metrics|Naming|Security|Style|Bundler|Gemspec)/}
63
- # Official cops
64
- ['rubocop', "::RuboCop::Cop::#{cop_class_suffix}"]
65
- else
66
- # Unknown cops
67
- department_camel = cop_name.split('/').first
68
- department_snake = department_camel.gsub(/(?<=.)([A-Z])/) { |s| "_#{s}" }.downcase
69
- ["rubocop-#{department_snake}", "::RuboCop::Cop::#{cop_class_suffix}"]
70
- end
46
+ case cop_name
47
+ when %r{^RSpec/}
48
+ [
49
+ {
50
+ gem_name: 'rubocop-rspec',
51
+ cop_class_name: "::RuboCop::Cop::#{cop_class_suffix}"
52
+ }
53
+ ]
54
+ when 'Rails/HttpStatus'
55
+ [
56
+ # for rubocop-rspec < 2.28.0
57
+ {
58
+ gem_name: 'rubocop-rspec',
59
+ cop_class_name: "::RuboCop::Cop::RSpec::#{cop_class_suffix}"
60
+ }
61
+ ]
62
+ when %r{^FactoryBot/}
63
+ [
64
+ # for rubocop-rspec < 2.0.0
65
+ {
66
+ gem_name: 'rubocop-rspec',
67
+ cop_class_name: "::RuboCop::Cop::RSpec::#{cop_class_suffix}"
68
+ },
69
+ # for rubocop-rspec v3+
70
+ {
71
+ gem_name: 'rubocop-factory_bot',
72
+ cop_class_name: "::RuboCop::Cop::#{cop_class_suffix}"
73
+ }
74
+ ]
75
+ when %r{^Capybara/}
76
+ [
77
+ # for rubocop-rspec < 2.0.0
78
+ {
79
+ gem_name: 'rubocop-rspec',
80
+ cop_class_name: "::RuboCop::Cop::RSpec::#{cop_class_suffix}"
81
+ },
82
+ # for rubocop-rspec v3+
83
+ {
84
+ gem_name: 'rubocop-capybara',
85
+ cop_class_name: "::RuboCop::Cop::#{cop_class_suffix}"
86
+ }
87
+ ]
88
+ when %r{^(Layout|Lint|Metrics|Naming|Security|Style|Bundler|Gemspec)/}
89
+ # Official cops
90
+ [
91
+ {
92
+ gem_name: 'rubocop',
93
+ cop_class_name: "::RuboCop::Cop::#{cop_class_suffix}"
94
+ }
95
+ ]
96
+ else
97
+ # Unknown cops
98
+ department_camel = cop_name.split('/').first
99
+ department_snake = department_camel.gsub(/(?<=.)([A-Z])/) { |s| "_#{s}" }.downcase
100
+
101
+ [
102
+ {
103
+ gem_name: "rubocop-#{department_snake}",
104
+ cop_class_name: "::RuboCop::Cop::#{cop_class_suffix}"
105
+ }
106
+ ]
107
+ end
71
108
  end
72
109
  # rubocop:enable Metrics/MethodLength
73
110
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubocopAutoCorrector
4
- VERSION = '0.4.5'
4
+ VERSION = '0.5.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop_auto_corrector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sue445
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-14 00:00:00.000000000 Z
11
+ date: 2024-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop