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: 3f3bc426d6d4748227e4b7ee3a848832c085a97a3e1dda759af5eeb74811a27a
4
- data.tar.gz: a60d1d736bff0b4f68eedc431fd8b240f474ecdeddb77bb108dcf85299a04a11
3
+ metadata.gz: e3c5ba5e401456f6e6da06b51c458ec5a016e99d83ba9d2faf989b06fba3d546
4
+ data.tar.gz: 07dffec5ad9b34571cb2f604afc437a207202323eee97ee73e3f87cedcdaa167
5
5
  SHA512:
6
- metadata.gz: ecc0ff69468a95b66f5c7c8acc1bd0c250d14459fa29101440cffaa4bdfd3ac66d6c1ae126af5b1245bffe3ae233f30fe89854984d8c847083f2121dd33e2cb7
7
- data.tar.gz: ebead5e4d298c63c3ea89012d126717dc150ebea9a8d6ce4ae9cc447e15cebf3863a0593accd44f0cbf9aa6638363254ce1f90d070b1f8f99d1185c05709464d
6
+ metadata.gz: 371d9ab4d526a72420e5f810f74f229039c7527bd04b475802af3b023ec1f620a8531f4ee0cffad6c10702f6d2a6d5d0f76893c63f62b4927f8ccb4fbefcc96d
7
+ data.tar.gz: fa55c8113abd1f303aef549935bf6d7d33de95a9dff802935a0e2a35dd84021ec0d792a5826cf481aefdce1bebea1a988a92341a879bfe15b22b42cd6d52e743
@@ -22,13 +22,5 @@ module CustomCopsGenerator
22
22
 
23
23
  Generator.new(name).generate
24
24
  end
25
-
26
- private def to_dirname(name)
27
- name.sub('-', '/')
28
- end
29
-
30
- private def to_classname
31
-
32
- end
33
25
  end
34
26
  end
@@ -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 '#{dirname}'
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, content)
151
+ private def patch(path, pattern, replacement)
137
152
  puts "update #{path}"
138
153
  path = root_path / path
139
- path.write path.read.sub(pattern, content)
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
@@ -1,3 +1,3 @@
1
1
  module CustomCopsGenerator
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: custom_cops_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masataka Pocke Kuwabara