nucop 0.13.3 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4752865b765d3873a9add4d5e88d9e41f0d1dd3df76806e6f3e0c4b41a161fa0
4
- data.tar.gz: '076051098218b7584ef87da0ddcbfa318280bcb60ade7957dec0dfd7e6e71166'
3
+ metadata.gz: 60a43ae26698ed539fb77fc3933d3ff662cd505608faa6199e9da620304a18a2
4
+ data.tar.gz: a255fad7d36bb62863b591c701ecfb42c975ed8415acf3347bdbe7b4d5477ef0
5
5
  SHA512:
6
- metadata.gz: 236708bf2169162b4cd4f5f56026e2928bde7a2e58146c0b9b5fa7d505d565fb6aae34fc4a724ac44fc33ff94b699406094dc473e60090ae3623969c80b3ae55
7
- data.tar.gz: 6359926411218b12f6e895d70bd334d837e876557a62d48ba1f2f811f698ace933bfefd7c76e02303b1482eb9a91dab3eeb9ce5572d218342b97c0604bf738c6
6
+ metadata.gz: 27f596c10a11e943dc0255751cf08c099593bb3b0bfd84c7bf64bb6ed7c2018ada52283088e5fefe495f27c3e1757b88f2e513a3fdb05c9546076936a9370817
7
+ data.tar.gz: a5c607cea7e35b761bec9c787be76e3384542d6315d45082b39a9ad4c3a6eff4b344cfbfb46e1c30d492e2f1034e095958ef8d4dce62e47c2b7586ea6f93b55f
data/lib/nucop/cli.rb CHANGED
@@ -22,17 +22,13 @@ module Nucop
22
22
 
23
23
  def default_configuration
24
24
  {
25
- enforced_cops_file: ".rubocop.enforced.yml",
26
25
  rubocop_todo_file: ".rubocop_todo.yml",
27
- rubocop_todo_config_file: ".rubocop.backlog.yml",
28
26
  diffignore_file: ".nucop_diffignore"
29
27
  }
30
28
  end
31
29
  end
32
30
 
33
31
  class_option :diffignore_file, default: load_custom_options[:diffignore_file]
34
- class_option :enforced_cops_file, default: load_custom_options[:enforced_cops_file]
35
- class_option :rubocop_todo_config_file, default: load_custom_options[:rubocop_todo_config_file]
36
32
  class_option :rubocop_todo_file, default: load_custom_options[:rubocop_todo_file]
37
33
 
38
34
  desc "diff_enforced", "run RuboCop on the current diff using only the enforced cops"
@@ -44,7 +40,7 @@ module Nucop
44
40
  method_option "json", type: :string, default: nil, desc: "Output results as JSON format to the provided file"
45
41
 
46
42
  def diff_enforced
47
- invoke :diff, nil, options.merge(only: cops_to_enforce.join(","))
43
+ invoke :diff, nil, options
48
44
  end
49
45
 
50
46
  desc "diff_enforced_github", "run RuboCop on the current diff using only the enforced cops (using GitHub to find the files changed)"
@@ -57,7 +53,7 @@ module Nucop
57
53
  method_option "json", type: :string, default: nil, desc: "Output results as JSON format to the provided file"
58
54
 
59
55
  def diff_enforced_github
60
- invoke :diff_github, nil, options.merge(only: cops_to_enforce.join(","))
56
+ invoke :diff_github, nil, options
61
57
  end
62
58
 
63
59
  desc "diff", "run RuboCop on the current diff"
@@ -186,11 +182,10 @@ module Nucop
186
182
  method_option "auto-correct", type: :boolean, default: false, desc: "runs RuboCop with auto-correct option (deprecated)"
187
183
  method_option "autocorrect", type: :boolean, default: false, desc: "runs RuboCop with autocorrect option"
188
184
  method_option "autocorrect-all", type: :boolean, default: false, desc: "runs RuboCop with autocorrect-all option"
189
- method_option "exclude-backlog", type: :boolean, default: false, desc: "when true, uses config which excludes violations in the RuboCop backlog"
190
185
 
191
186
  def rubocop(files = nil)
192
- print_cops_being_run(options[:only])
193
- config_file = options[:"exclude-backlog"] ? RUBOCOP_DEFAULT_CONFIG_FILE : options[:rubocop_todo_config_file]
187
+ puts "Running all cops..."
188
+ config_file = RUBOCOP_DEFAULT_CONFIG_FILE
194
189
 
195
190
  formatters = []
196
191
  formatters << "--format Nucop::Formatters::JUnitFormatter --out #{options[:junit_report]}" if options[:junit_report]
@@ -220,13 +215,11 @@ module Nucop
220
215
 
221
216
  def regen_backlog
222
217
  regenerate_rubocop_todos
223
- update_enforced_cops
224
218
  end
225
219
 
226
220
  desc "update_enforced", "update the enforced cops list with file with cops that no longer have violations"
227
-
228
221
  def update_enforced
229
- update_enforced_cops
222
+ puts "This is a no-op. Enforced cops are not currently supported."
230
223
  end
231
224
 
232
225
  desc "modified_lines", "display RuboCop violations for ONLY modified lines"
@@ -242,7 +235,7 @@ module Nucop
242
235
  "--parallel",
243
236
  "--no-server",
244
237
  "--format Nucop::Formatters::GitDiffFormatter",
245
- "--config #{options[:rubocop_todo_config_file]}",
238
+ "--config #{RUBOCOP_DEFAULT_CONFIG_FILE}",
246
239
  multi_line_to_single_line(diff_files).to_s
247
240
  ].join(" ")
248
241
 
@@ -254,41 +247,11 @@ module Nucop
254
247
  method_option "n", type: :numeric, default: 1, desc: "number of cops to display"
255
248
 
256
249
  def ready_for_promotion
257
- finder = Helpers::NextCopForPromotion.new(options[:rubocop_todo_file])
258
- todo_config = YAML.load_file(options[:rubocop_todo_file])
259
-
260
- puts "The following cop(s) are ready to be promoted to enforced. Good luck!"
261
- puts "Remember to run `nucop:regen_backlog` to capture your hard work."
262
- puts
263
- finder.find(options["n"].to_i).each do |todo|
264
- puts "#{todo.name} with #{todo.offenses} offenses:"
265
- puts
266
-
267
- files = todo_config.fetch(todo.name, {}).fetch("Exclude", [])
268
-
269
- system("bundle exec rubocop --no-server --parallel --config #{options[:rubocop_todo_config_file]} --only #{todo.name} #{files.join(' ')}")
270
- puts("*" * 100) if options["n"] > 1
271
- puts
272
- end
250
+ puts "This is a no-op. Enforced cops are not currently supported."
273
251
  end
274
252
 
275
253
  private
276
254
 
277
- # some cops cannot be used with the --only option and will raise an error
278
- # this filters them out
279
- def cops_to_enforce
280
- cops = enforced_cops
281
-
282
- cops.delete("Lint/UnneededCopDisableDirective")
283
- cops.delete("Lint/RedundantCopDisableDirective")
284
-
285
- cops
286
- end
287
-
288
- def enforced_cops
289
- @_enforced_cops ||= YAML.load_file(options[:enforced_cops_file])
290
- end
291
-
292
255
  def capture_std_out(command, error_message = nil, stdin_data = nil)
293
256
  std_out, std_error, status = Open3.capture3(command, stdin_data: stdin_data)
294
257
  print_errors_and_exit(std_error, error_message) unless status.success?
@@ -303,15 +266,6 @@ module Nucop
303
266
  exit 1
304
267
  end
305
268
 
306
- def print_cops_being_run(only_option)
307
- if only_option
308
- enforced_cops_count = Helpers::CopCounter.count(enabled_cops, only_option.split(","))
309
- puts "Running with a force of #{enforced_cops_count} cops. See '#{options[:enforced_cops_file]}' for more details."
310
- else
311
- puts "Running all cops (specify using the 'only' option)"
312
- end
313
- end
314
-
315
269
  def multi_line_to_single_line(str)
316
270
  str.split(/\n+/).join(" ")
317
271
  end
@@ -325,67 +279,30 @@ module Nucop
325
279
  "--#{option} #{options[option] if is_flag_option}"
326
280
  end
327
281
 
328
- def files_changed_since(commit_spec)
329
- `git diff #{commit_spec} HEAD --name-only`
330
- .split("\n")
331
- .select { |e| e.end_with?(".rb") }
332
- end
333
-
334
282
  def regenerate_rubocop_todos
335
283
  puts "Regenerating '#{options[:rubocop_todo_file]}'. Please be patient..."
336
284
 
337
285
  rubocop_options = [
338
286
  "--auto-gen-config",
339
- "--config #{options[:rubocop_todo_config_file]}",
287
+ "--config #{RUBOCOP_DEFAULT_CONFIG_FILE}",
340
288
  "--exclude-limit #{options[:"exclude-limit"]}",
341
289
  "--no-server"
342
290
  ]
343
291
 
344
- rubocop_command = "DISABLE_SPRING=1 bundle exec rubocop #{rubocop_options.join(' ')} #{rubocop_gem_requires.join(' ')}"
292
+ system("rm -f #{options[:rubocop_todo_file]}")
293
+ system("touch #{options[:rubocop_todo_file]}")
345
294
 
295
+ rubocop_command = "DISABLE_SPRING=1 bundle exec rubocop #{rubocop_options.join(' ')} #{rubocop_gem_requires.join(' ')}"
346
296
  system(rubocop_command)
347
297
 
348
- # RuboCop wants to inherit from our todos (options[:rubocop_todo_file]) in our backlog configuration file (options[:rubocop_todo_config_file])
349
- # However, that means the next time we try to update our backlog, it will NOT include the violations recorded as todo
350
- # For now, we ignore any changes in our backlog config
351
- system("git checkout #{options[:rubocop_todo_config_file]}")
352
- end
353
-
354
- def rubocop_gem_plugins
355
- Nucop::Helpers::RubocopGemDependencies.rubocop_plugins.map { |rubocop_gem| "--plugin #{rubocop_gem}" }
298
+ # RuboCop wants to inherit from our todos (options[:rubocop_todo_file]) in our configuration file.
299
+ # However, that means the next time we try to update our backlog, it will NOT include the violations
300
+ # recorded as todo. For now, we ignore any changes in our config.
301
+ system("git checkout #{RUBOCOP_DEFAULT_CONFIG_FILE}")
356
302
  end
357
303
 
358
304
  def rubocop_gem_requires
359
305
  Nucop::Helpers::RubocopGemDependencies.rubocop_gems.map { |rubocop_gem| "--require #{rubocop_gem}" }
360
306
  end
361
-
362
- def update_enforced_cops
363
- puts "Updating enforced cops list..."
364
-
365
- current_enforced_cops = Helpers::CopSet.new(enforced_cops)
366
- cops_without_violations.each do |cop|
367
- current_enforced_cops.add_cop(cop)
368
- end
369
-
370
- if current_enforced_cops.cop_added?
371
- File.write(options[:enforced_cops_file], current_enforced_cops.to_a.sort.to_yaml)
372
- puts "Updated '#{options[:enforced_cops_file]}'!"
373
- else
374
- puts "No new cops are clear of violations"
375
- end
376
- end
377
-
378
- def cops_without_violations
379
- cops_with_violations = YAML.load_file(options[:rubocop_todo_file]).map(&:first)
380
-
381
- enabled_cops - cops_with_violations
382
- end
383
-
384
- def enabled_cops
385
- @_enabled_cops ||= YAML
386
- .safe_load(`bundle exec rubocop --no-server --parallel --show-cops`, permitted_classes: [Regexp, Symbol])
387
- .select { |_, config| config["Enabled"] }
388
- .map(&:first)
389
- end
390
307
  end
391
308
  end
data/lib/nucop/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nucop
2
- VERSION = "0.13.3"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nucop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.3
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Schweier
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-03-26 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rubocop
@@ -220,7 +219,6 @@ dependencies:
220
219
  - - "~>"
221
220
  - !ruby/object:Gem::Version
222
221
  version: '3.13'
223
- description:
224
222
  email:
225
223
  - jasons@nulogy.com
226
224
  executables:
@@ -239,7 +237,6 @@ files:
239
237
  - lib/nucop/cops/shadowing_factory_bot_creation_methods.rb
240
238
  - lib/nucop/formatters/git_diff_formatter.rb
241
239
  - lib/nucop/formatters/junit_formatter.rb
242
- - lib/nucop/helpers/cop_counter.rb
243
240
  - lib/nucop/helpers/cop_set.rb
244
241
  - lib/nucop/helpers/factory_bot_helper.rb
245
242
  - lib/nucop/helpers/file_path_helper.rb
@@ -254,7 +251,6 @@ metadata:
254
251
  changelog_uri: https://github.com/nulogy/nucop/blob/master/CHANGELOG.md
255
252
  bug_tracker_uri: https://github.com/nulogy/nucop/issues
256
253
  rubygems_mfa_required: 'true'
257
- post_install_message:
258
254
  rdoc_options: []
259
255
  require_paths:
260
256
  - lib
@@ -269,8 +265,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
269
265
  - !ruby/object:Gem::Version
270
266
  version: '0'
271
267
  requirements: []
272
- rubygems_version: 3.3.27
273
- signing_key:
268
+ rubygems_version: 3.7.0
274
269
  specification_version: 4
275
270
  summary: Nulogy's implementation of RuboCop, including custom cops and additional
276
271
  tooling.
@@ -1,51 +0,0 @@
1
- # class to count the number of cops from a list of RuboCop "only" options
2
- # i.e. it accounts for whole "Departments"
3
- #
4
- # Examples:
5
- # "Style/Blah" is 1 cops
6
- # "Layout" may represent 70 cops
7
- module Nucop
8
- module Helpers
9
- class CopCounter
10
- def self.count(all_cops, cops_or_departments)
11
- new(all_cops).count(cops_or_departments)
12
- end
13
-
14
- def initialize(cops)
15
- @cops_by_department = group_by_department(cops)
16
- end
17
-
18
- def count(cops_or_departments)
19
- cops_or_departments
20
- .map do |cop_or_department|
21
- if department?(cop_or_department)
22
- @cops_by_department.fetch(cop_or_department, []).length
23
- else
24
- 1
25
- end
26
- end
27
- .reduce(0, &:+)
28
- end
29
-
30
- private
31
-
32
- def group_by_department(cop_names)
33
- cop_names.group_by do |cop_name|
34
- if department?(cop_name)
35
- raise "Expected fully-qualified cops by name (i.e. Department/Cop). Got: #{cop_name}"
36
- end
37
-
38
- department(cop_name)
39
- end
40
- end
41
-
42
- def department?(cop_name)
43
- !cop_name.include?("/")
44
- end
45
-
46
- def department(cop_name)
47
- cop_name.split("/").first
48
- end
49
- end
50
- end
51
- end