advent_of_ruby 0.3.3 → 0.3.5

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: 7157738053e4ec2024b29f3e309d1b8629bf82a72b5478cba1391bb581770ba4
4
- data.tar.gz: 47fcaf827ea7994744420bcb300739eba636396d7c0510391e2baa517b3b7e3f
3
+ metadata.gz: ef827ae7d7d476a5cf69ba40c6c437225c413fddf45a619315e82b5b4afeef5b
4
+ data.tar.gz: 0dc97c1311bd52c88912fbd00d23f54166f9fb5c76f01cde07cc49d02f1ae2f9
5
5
  SHA512:
6
- metadata.gz: c6210bc305da01a6b3ada2b2394e162e3c57762f2a6fac902b787be3d117a3857fc8889d3c1428d32ae455a7fe96f02778461517018d4dede39418468591ab4c
7
- data.tar.gz: 77b145c6665bff896e9816c3930f53e06878c6b90fbe5fee05fe28e326e91c3e78e1d3922599472dc2f2901bc28f49fd7d8ea78cd88daa5d5b6809fc3376e62e
6
+ metadata.gz: 12bf51e1a30e704ff8799d0e69d86c623acecd1aeb17d260842c936f0a3e899dae2bae52df7b6e6709c4af3bf48f4258d883aad7eced150e3259838b9cdf8d33
7
+ data.tar.gz: 2eec5db6f2e168adc267385021d3fa130972c360a682b15d16d4b6c6deec9d7c25db37f77f71c95d6d289a18e097a16f7416498c1ff534c04731a204129283d0
@@ -13,7 +13,7 @@ module Arb
13
13
  File.write(file_path, template(year:, day:))
14
14
  end
15
15
 
16
- Formatter.format(file_path)
16
+ Formatters::RuboCop.format(file_path)
17
17
 
18
18
  file_path
19
19
  end
@@ -13,7 +13,7 @@ module Arb
13
13
  File.write(file_path, template(year:, day:))
14
14
  end
15
15
 
16
- Formatter.format(file_path)
16
+ Formatters::RuboCop.format(file_path)
17
17
 
18
18
  file_path
19
19
  end
@@ -0,0 +1,31 @@
1
+ module Formatters
2
+ module RuboCop
3
+ # Formats newly created files using RuboCop if it is bundled at the top
4
+ # level (i.e. as `gem "rubocop"` in the Gemfile) or if a RuboCop config file
5
+ # is present. Does nothing if RuboCop isn't bundled or is just a dependency
6
+ # (e.g. of Standard), and if there is no RuboCop config file.
7
+ def self.format(file_path)
8
+ require "bundler"
9
+ require "rubocop"
10
+ return unless rubocop_bundled_at_top_level? || rubocop_config_exists?
11
+
12
+ ::RuboCop::CLI.new.run(["-A", file_path, "--out", File::NULL])
13
+ rescue LoadError
14
+ # Do nothing if Bundler is not installed, or if RuboCop is bundled but not
15
+ # actually installed.
16
+ end
17
+
18
+ private_class_method def self.rubocop_bundled_at_top_level?
19
+ Bundler.definition.dependencies.any? { it.name == "rubocop" }
20
+ rescue Bundler::GemfileNotFound
21
+ false
22
+ end
23
+
24
+ # A shorter approach would be simply `File.exist?(".rubocop.yml")`, but
25
+ # the approach below avoids directly reading a file.
26
+ private_class_method def self.rubocop_config_exists?
27
+ config_path = ::RuboCop::ConfigFinder.find_config_path(Dir.pwd)
28
+ config_path && !config_path.end_with?("config/default.yml")
29
+ end
30
+ end
31
+ end
data/lib/arb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Arb
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: advent_of_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felipe Vogel
@@ -2705,7 +2705,7 @@ files:
2705
2705
  - lib/arb/files/other_solutions.rb
2706
2706
  - lib/arb/files/solution.rb
2707
2707
  - lib/arb/files/spec.rb
2708
- - lib/arb/formatter.rb
2708
+ - lib/arb/formatters/rubocop.rb
2709
2709
  - lib/arb/version.rb
2710
2710
  - lib/download_solutions/api/github.rb
2711
2711
  - lib/download_solutions/api/github/repos.rb
data/lib/arb/formatter.rb DELETED
@@ -1,22 +0,0 @@
1
- begin
2
- gem "rubocop"
3
- require "rubocop"
4
- rescue LoadError
5
- # If RuboCop isn't available, no formatting will be done
6
- end
7
-
8
- module Formatter
9
- class << self
10
- def format(file_path)
11
- return unless rubocop_loaded?
12
-
13
- RuboCop::CLI.new.run(["-A", file_path, "--out", File::NULL])
14
- end
15
-
16
- private
17
-
18
- def rubocop_loaded?
19
- defined?(RuboCop)
20
- end
21
- end
22
- end