advent_of_ruby 0.3.4 → 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: 35a9db6d1ec1dcc7cee17157e2ed4df19f3617c9882b68d22143e36985e73239
4
- data.tar.gz: c2ba5d624f05063b5e5c70b3a04346435d1d57964050fbb14b94a63c5323f9ca
3
+ metadata.gz: ef827ae7d7d476a5cf69ba40c6c437225c413fddf45a619315e82b5b4afeef5b
4
+ data.tar.gz: 0dc97c1311bd52c88912fbd00d23f54166f9fb5c76f01cde07cc49d02f1ae2f9
5
5
  SHA512:
6
- metadata.gz: a95ced50daf64f11587136162bce59c260756e124668da1c02bb8644647126271d9063d6897b4ca67c4eec0193419de51d2e58d6994f1358804ea7ad0af78f13
7
- data.tar.gz: 658ab7ec7e10ee74889dd94abdbfdc7e7257bacdb2cf3cba5ffdde828a2e9d98ef099fece75020a1880a8c66cfbf76b97a0b3f48edf7d7649408cff6a2aec982
6
+ metadata.gz: 12bf51e1a30e704ff8799d0e69d86c623acecd1aeb17d260842c936f0a3e899dae2bae52df7b6e6709c4af3bf48f4258d883aad7eced150e3259838b9cdf8d33
7
+ data.tar.gz: 2eec5db6f2e168adc267385021d3fa130972c360a682b15d16d4b6c6deec9d7c25db37f77f71c95d6d289a18e097a16f7416498c1ff534c04731a204129283d0
@@ -1,24 +1,31 @@
1
1
  module Formatters
2
2
  module RuboCop
3
3
  # Formats newly created files using RuboCop if it is bundled at the top
4
- # level, i.e. as `gem "rubocop"` in the Gemfile. Does nothing if RuboCop
5
- # isn't bundled or is just a dependency, e.g. of Standard.
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.
6
7
  def self.format(file_path)
7
- return unless rubocop_bundled_at_top_level?
8
+ require "bundler"
9
+ require "rubocop"
10
+ return unless rubocop_bundled_at_top_level? || rubocop_config_exists?
8
11
 
9
- begin
10
- require "rubocop"
11
- RuboCop::CLI.new.run(["-A", file_path, "--out", File::NULL])
12
- rescue LoadError
13
- # Do nothing if RuboCop is bundled but not actually installed.
14
- end
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.
15
16
  end
16
17
 
17
18
  private_class_method def self.rubocop_bundled_at_top_level?
18
- require "bundler"
19
19
  Bundler.definition.dependencies.any? { it.name == "rubocop" }
20
- rescue LoadError, Bundler::GemfileNotFound
20
+ rescue Bundler::GemfileNotFound
21
21
  false
22
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
23
30
  end
24
31
  end
data/lib/arb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Arb
2
- VERSION = "0.3.4"
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.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felipe Vogel