manageiq-style 1.1.3 → 1.2.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: aeb8ff9f981225899057f8a511f60c117540819d36aac865bf49819588d2489f
4
- data.tar.gz: 9d926d19f291ccb28e5f1a1cc0fd73b090544a049613244340470b672268ca29
3
+ metadata.gz: 8840f6c593105a9a76b6b2f765e2789a9448d623c5cf67737fa0bb032ba7106f
4
+ data.tar.gz: b593378d58deaf202a70bad993bf9316b671d7eda9519400eeb2ad0f86158591
5
5
  SHA512:
6
- metadata.gz: 2ced6243a6718309e99fd31ab36ec6d331458d171a1e83f2aeeae37b7e1638f6529a8ddc040d389c67a7b0b67b6e84e78cd39d5265a8a84fccdb5bdd7d5a64f7
7
- data.tar.gz: 2151ebe77138ecc1cb35169265ae88fdda3ad6ea700e57496b172a56f12fcb38c74b836a459b0c70ab6ab4332f315d23b835d0706d9a9c218fb6478a0ec2acce
6
+ metadata.gz: f7fbd6bbbc966d1caf340007040012503dcfa83ae4ee4b4394d6ad589953cb4bff8f7639506b5473227897e0ff4ed7018eafa0eaf0f6fbe6bfc131e5eb1909df
7
+ data.tar.gz: 7d13f41a40b884feca8310d68ffc735f037ccf0cda87d9d752ca85f9b02e6cddf204cf8f77fbb2852ebceddeebd6bb6f556eed9a95589063e964f3366e404cce
@@ -4,6 +4,10 @@ prepare:
4
4
  path: ".rubocop_base.yml"
5
5
  - url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/.rubocop_cc_base.yml
6
6
  path: ".rubocop_cc_base.yml"
7
+ - url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/styles/base.yml
8
+ path: styles/base.yml
9
+ - url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/styles/cc_base.yml
10
+ path: styles/cc_base.yml
7
11
  plugins:
8
12
  rubocop:
9
13
  enabled: true
@@ -1,4 +1,4 @@
1
1
  inherit_from:
2
- - .rubocop_base.yml
3
- # put all local rubocop config into .rubocop_local.yml as it will be loaded by .rubocop_cc.yml as well
4
- - .rubocop_local.yml
2
+ - ".rubocop_local.yml"
3
+ inherit_gem:
4
+ manageiq-style: ".rubocop_base.yml"
@@ -35,6 +35,7 @@ module ManageIQ
35
35
  ensure_rubocop_local_yml_exists
36
36
  update_codeclimate_yml
37
37
  update_generator
38
+ update_gem_source
38
39
  end
39
40
 
40
41
  private
@@ -121,6 +122,105 @@ module ManageIQ
121
122
  File.write(".codeclimate.yml", data.to_yaml.sub("---\n", ""))
122
123
  end
123
124
 
125
+ def update_gem_source
126
+ if (gemspec = Dir.glob("*.gemspec").first)
127
+ update_gemspec(gemspec)
128
+ elsif File.exist?("Gemfile")
129
+ update_gemfile
130
+ end
131
+ end
132
+
133
+ def update_gemspec(gemspec)
134
+ contents = File.read(gemspec)
135
+ return if contents.include?("manageiq-style")
136
+
137
+ lines = contents.lines
138
+
139
+ obj = $1 if lines.detect { |l| l =~ /^\s+(\w+)\.name\s+=/ }
140
+ raise "couldn't find spec object name" if obj.nil?
141
+
142
+ new_line = "#{obj}.add_development_dependency \"manageiq-style\"\n"
143
+
144
+ dev_lines = lines.select { |l| l.include?("add_development_dependency") }
145
+ if dev_lines.any?
146
+ # Add manageiq-style and remove all direct rubocop references
147
+ dev_lines << new_line
148
+ dev_lines.reject! { |l| l.include?("rubocop") }
149
+
150
+ # Prepare the lines in a nice format
151
+ format_gem_source_lines!(dev_lines)
152
+ dev_lines.sort_by!(&:downcase)
153
+
154
+ # Remove the old dev lines and add the new ones
155
+ insert_at = lines.index { |l| l.include?("add_development_dependency") }
156
+ lines.delete_if { |l| l.include?("add_development_dependency") }
157
+ lines.insert(insert_at, dev_lines)
158
+ else
159
+ insert_at = -1
160
+ insert_at -= 1 until lines[insert_at].strip != "end"
161
+ lines.insert(insert_at, new_line)
162
+ end
163
+
164
+ File.write(gemspec, lines.join)
165
+ end
166
+
167
+ def update_gemfile
168
+ contents = File.read("Gemfile")
169
+ return if contents.include?("manageiq-style")
170
+
171
+ lines = contents.lines
172
+
173
+ new_line = "gem \"manageiq-style\", :require => false\n"
174
+
175
+ group_index = lines.index { |l| l.match?(/group\(?\s*:development/) }
176
+ if group_index
177
+ # Determine the group range
178
+ group_index += 1
179
+ group_end = group_index
180
+ group_end += 1 until lines[group_end].strip == "end"
181
+ group_range = (group_index..group_end - 1)
182
+
183
+ # Split lines into "gem" units including their preceding comments or blank lines
184
+ gem_units = lines[group_range].slice_after { |l| l.match?(/^\s*gem/) }.to_a
185
+
186
+ # Add manageiq-style and remove all direct rubocop references
187
+ gem_units << [new_line]
188
+ gem_units.reject! { |u| u.last.include?("rubocop") }
189
+
190
+ # Prepare the lines in a nice format
191
+ gem_lines = gem_units.map(&:last)
192
+ format_gem_source_lines!(gem_lines)
193
+ gem_units.each_with_index { |u, i| u[-1] = gem_lines[i] }
194
+ gem_units.sort_by! { |u| u.last.downcase }
195
+ gem_units.flatten!
196
+
197
+ # Remove the old group lines and add the new ones
198
+ lines.slice!(group_range)
199
+ lines.insert(group_index, gem_units)
200
+ else
201
+ lines << <<~RUBY
202
+
203
+ group :development do
204
+ #{new_line}
205
+ end
206
+ RUBY
207
+ end
208
+
209
+ File.write("Gemfile", lines.join)
210
+ end
211
+
212
+ def format_gem_source_lines!(lines)
213
+ indent = lines.first.match(/^\s+/).to_s
214
+
215
+ lines.map! { |l| l.strip.gsub(/[()]/, " ").split(" ", 3) } # Split to [prefix, gem, versions]
216
+ lines.each { |parts| parts[1].tr!("'", "\"")} # Ensure double quoted gem name
217
+ max_width = lines.map { |parts| parts[1].size }.max # Determine the widest gem name
218
+ lines.each { |parts| parts[1] = parts[1].ljust(max_width, " ") } # Apply the width
219
+ lines.map! { |parts| parts.join(" ").strip.insert(0, indent) << "\n" } # Back to strings
220
+
221
+ lines
222
+ end
223
+
124
224
  def update_generator
125
225
  plugin_dir = "lib/generators/manageiq/plugin/templates"
126
226
 
@@ -1,5 +1,5 @@
1
1
  module ManageIQ
2
2
  module Style
3
- VERSION = "1.1.3"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: manageiq-style
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ManageIQ Authors
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-05 00:00:00.000000000 Z
11
+ date: 2021-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: more_core_extensions