nucop 0.13.2 → 1.0.0

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: 8fdaea0438691517f328186612ea951d183c9612f14164b8355879579507ec85
4
- data.tar.gz: 9c2f09f7ca3fe40cc8b5fc5343bef11b99929c6a2adc8e2718cdcf3411523f62
3
+ metadata.gz: 44f985b31c893d52701dcdcd58eb3370f110c0e1c9ba121f2515a33b214b6d68
4
+ data.tar.gz: 94b8dfb664058f6ed296fb93d4f9f35431083b947a7086e0187f96768041b80e
5
5
  SHA512:
6
- metadata.gz: 28791178bfc6236a1e89c4af22531a3e4ff65886940b092fd34cc62faff4884f06c8a73c0dba8c5642061c7a1808b190843e9ad301d78709b33b980c847f085a
7
- data.tar.gz: 39089fd3682b2354d7fc92f9f14792f64ad899f096efe0d866a849216aab960a20820c07c5841954d9315fc741ebf6f3362cb1c5d7aafdc450279e834b7c2350
6
+ metadata.gz: 9192e4cdf894fc997f6eabfd1a5d7c2a7d9d8c166a7fa708ae62e1ba7c6682ac7daaaf158c1d0fa2b5e4a1d8b9d5cc903ede638b20d347f472752d0bdd01d211
7
+ data.tar.gz: 83b0b6c83da6bd4905006844a64398f0ecd514ab2f2dcbee1ede5992fc5973d74fc7327937e55f95b0fdc596fe0b713f4a34996e6c95a228b48638afee3f25fc
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,40 +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
-
284
- cops
285
- end
286
-
287
- def enforced_cops
288
- @_enforced_cops ||= YAML.load_file(options[:enforced_cops_file])
289
- end
290
-
291
255
  def capture_std_out(command, error_message = nil, stdin_data = nil)
292
256
  std_out, std_error, status = Open3.capture3(command, stdin_data: stdin_data)
293
257
  print_errors_and_exit(std_error, error_message) unless status.success?
@@ -302,15 +266,6 @@ module Nucop
302
266
  exit 1
303
267
  end
304
268
 
305
- def print_cops_being_run(only_option)
306
- if only_option
307
- enforced_cops_count = Helpers::CopCounter.count(enabled_cops, only_option.split(","))
308
- puts "Running with a force of #{enforced_cops_count} cops. See '#{options[:enforced_cops_file]}' for more details."
309
- else
310
- puts "Running all cops (specify using the 'only' option)"
311
- end
312
- end
313
-
314
269
  def multi_line_to_single_line(str)
315
270
  str.split(/\n+/).join(" ")
316
271
  end
@@ -324,18 +279,12 @@ module Nucop
324
279
  "--#{option} #{options[option] if is_flag_option}"
325
280
  end
326
281
 
327
- def files_changed_since(commit_spec)
328
- `git diff #{commit_spec} HEAD --name-only`
329
- .split("\n")
330
- .select { |e| e.end_with?(".rb") }
331
- end
332
-
333
282
  def regenerate_rubocop_todos
334
283
  puts "Regenerating '#{options[:rubocop_todo_file]}'. Please be patient..."
335
284
 
336
285
  rubocop_options = [
337
286
  "--auto-gen-config",
338
- "--config #{options[:rubocop_todo_config_file]}",
287
+ "--config #{RUBOCOP_DEFAULT_CONFIG_FILE}",
339
288
  "--exclude-limit #{options[:"exclude-limit"]}",
340
289
  "--no-server"
341
290
  ]
@@ -344,47 +293,14 @@ module Nucop
344
293
 
345
294
  system(rubocop_command)
346
295
 
347
- # RuboCop wants to inherit from our todos (options[:rubocop_todo_file]) in our backlog configuration file (options[:rubocop_todo_config_file])
348
- # However, that means the next time we try to update our backlog, it will NOT include the violations recorded as todo
349
- # For now, we ignore any changes in our backlog config
350
- system("git checkout #{options[:rubocop_todo_config_file]}")
351
- end
352
-
353
- def rubocop_gem_plugins
354
- Nucop::Helpers::RubocopGemDependencies.rubocop_plugins.map { |rubocop_gem| "--plugin #{rubocop_gem}" }
296
+ # RuboCop wants to inherit from our todos (options[:rubocop_todo_file]) in our configuration file.
297
+ # However, that means the next time we try to update our backlog, it will NOT include the violations
298
+ # recorded as todo. For now, we ignore any changes in our config.
299
+ system("git checkout #{RUBOCOP_DEFAULT_CONFIG_FILE}")
355
300
  end
356
301
 
357
302
  def rubocop_gem_requires
358
303
  Nucop::Helpers::RubocopGemDependencies.rubocop_gems.map { |rubocop_gem| "--require #{rubocop_gem}" }
359
304
  end
360
-
361
- def update_enforced_cops
362
- puts "Updating enforced cops list..."
363
-
364
- current_enforced_cops = Helpers::CopSet.new(enforced_cops)
365
- cops_without_violations.each do |cop|
366
- current_enforced_cops.add_cop(cop)
367
- end
368
-
369
- if current_enforced_cops.cop_added?
370
- File.write(options[:enforced_cops_file], current_enforced_cops.to_a.sort.to_yaml)
371
- puts "Updated '#{options[:enforced_cops_file]}'!"
372
- else
373
- puts "No new cops are clear of violations"
374
- end
375
- end
376
-
377
- def cops_without_violations
378
- cops_with_violations = YAML.load_file(options[:rubocop_todo_file]).map(&:first)
379
-
380
- enabled_cops - cops_with_violations
381
- end
382
-
383
- def enabled_cops
384
- @_enabled_cops ||= YAML
385
- .safe_load(`bundle exec rubocop --no-server --parallel --show-cops`, permitted_classes: [Regexp, Symbol])
386
- .select { |_, config| config["Enabled"] }
387
- .map(&:first)
388
- end
389
305
  end
390
306
  end
data/lib/nucop/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nucop
2
- VERSION = "0.13.2"
2
+ VERSION = "1.0.0"
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.2
4
+ version: 1.0.0
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-19 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.5.22
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