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 +4 -4
- data/lib/arb/formatters/rubocop.rb +18 -11
- data/lib/arb/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef827ae7d7d476a5cf69ba40c6c437225c413fddf45a619315e82b5b4afeef5b
|
4
|
+
data.tar.gz: 0dc97c1311bd52c88912fbd00d23f54166f9fb5c76f01cde07cc49d02f1ae2f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
5
|
-
# isn't bundled or is just a dependency
|
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
|
-
|
8
|
+
require "bundler"
|
9
|
+
require "rubocop"
|
10
|
+
return unless rubocop_bundled_at_top_level? || rubocop_config_exists?
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
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