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 +4 -4
- data/.rubocop.yml +4 -0
- data/CHANGELOG.md +7 -1
- data/Gemfile +6 -0
- data/lib/rubocop_auto_corrector/cop_finder.rb +86 -49
- data/lib/rubocop_auto_corrector/version.rb +1 -1
- 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: 64e6102fe91fd3839e15fb4eb332a0b4fbeb294a5da572dbaef62fafe7743161
|
4
|
+
data.tar.gz: 53f1dbbbf0415180b4bae3db5446d787d42a08fed7c021fa8adecd05b78d2393
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09a1afa77bfbfec27f59b2a8661ac41fc320b868263e52c4721b071d0f9afefde6d9b0aff35e4bb70c19777743468d0b0cd935df4e4a952df3f9eaedab97fd59'
|
7
|
+
data.tar.gz: a05f259099b5f21bcf1f1835bdc9698518e53cd0ef43f907f0e0f36b1f489b38bfe83e60c4b11f3639d5704fc9ef1d1514bd84cfa224b1ba11adb5a450a2b4a1
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
## master
|
2
|
-
[full changelog](http://github.com/sue445/rubocop_auto_corrector/compare/v0.
|
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
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
52
|
-
|
53
|
-
|
42
|
+
# @return [Array<Hash<Symbol, String>>]
|
43
|
+
def cop_candidacies
|
54
44
|
cop_class_suffix = cop_name.gsub('/', '::')
|
55
45
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
#
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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
|
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
|
+
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-
|
11
|
+
date: 2024-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|