custom_cops_generator 0.1.1 → 0.1.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3c5ba5e401456f6e6da06b51c458ec5a016e99d83ba9d2faf989b06fba3d546
|
4
|
+
data.tar.gz: 07dffec5ad9b34571cb2f604afc437a207202323eee97ee73e3f87cedcdaa167
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 371d9ab4d526a72420e5f810f74f229039c7527bd04b475802af3b023ec1f620a8531f4ee0cffad6c10702f6d2a6d5d0f76893c63f62b4927f8ccb4fbefcc96d
|
7
|
+
data.tar.gz: fa55c8113abd1f303aef549935bf6d7d33de95a9dff802935a0e2a35dd84021ec0d792a5826cf481aefdce1bebea1a988a92341a879bfe15b22b42cd6d52e743
|
@@ -18,7 +18,7 @@ module CustomCopsGenerator
|
|
18
18
|
|
19
19
|
RuboCop::#{classname}::Inject.defaults!
|
20
20
|
|
21
|
-
require_relative '#{cops_file_name}'
|
21
|
+
require_relative '#{cops_file_name.sub(/\.rb$/, '').sub(/^lib\//, '')}'
|
22
22
|
RUBY
|
23
23
|
|
24
24
|
put "lib/#{dirname}/inject.rb", <<~RUBY
|
@@ -55,7 +55,7 @@ module CustomCopsGenerator
|
|
55
55
|
put 'spec/spec_helper.rb', <<~RUBY
|
56
56
|
# frozen_string_literal: true
|
57
57
|
|
58
|
-
require '#{
|
58
|
+
require '#{name}'
|
59
59
|
require 'rubocop/rspec/support'
|
60
60
|
|
61
61
|
RSpec.configure do |config|
|
@@ -77,6 +77,20 @@ module CustomCopsGenerator
|
|
77
77
|
--require spec_helper
|
78
78
|
TEXT
|
79
79
|
|
80
|
+
patch "lib/#{dirname}.rb", /^ end\nend/, <<~RUBY
|
81
|
+
PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
|
82
|
+
CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
|
83
|
+
CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
|
84
|
+
|
85
|
+
private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
RUBY
|
89
|
+
|
90
|
+
patch "lib/#{dirname}.rb", 'module Rubocop', 'module RuboCop'
|
91
|
+
patch "lib/#{dirname}/version.rb", 'module Rubocop', 'module RuboCop'
|
92
|
+
patch "#{name}.gemspec", 'Rubocop', 'RuboCop'
|
93
|
+
|
80
94
|
patch "#{name}.gemspec", /^end/, <<~RUBY
|
81
95
|
|
82
96
|
spec.add_runtime_dependency 'rubocop'
|
@@ -91,6 +105,7 @@ module CustomCopsGenerator
|
|
91
105
|
spec.pattern = FileList['spec/**/*_spec.rb']
|
92
106
|
end
|
93
107
|
|
108
|
+
desc 'Generate a new cop with a template'
|
94
109
|
task :new_cop, [:cop] do |_task, args|
|
95
110
|
require 'rubocop'
|
96
111
|
|
@@ -133,10 +148,12 @@ module CustomCopsGenerator
|
|
133
148
|
path.write(content)
|
134
149
|
end
|
135
150
|
|
136
|
-
private def patch(path, pattern,
|
151
|
+
private def patch(path, pattern, replacement)
|
137
152
|
puts "update #{path}"
|
138
153
|
path = root_path / path
|
139
|
-
|
154
|
+
file = path.read
|
155
|
+
raise "Cannot apply patch for #{path} because #{pattern} is missing" unless file.match?(pattern)
|
156
|
+
path.write file.sub(pattern, replacement)
|
140
157
|
end
|
141
158
|
|
142
159
|
private def root_path
|