Merge pull request #2718 from reitermarkus/rubocop-audit
Fix `rubocop` in `brew audit`.
This commit is contained in:
commit
0d124f7510
@ -120,7 +120,7 @@ module Homebrew
|
|||||||
# exitstatus can also be nil if RuboCop process crashes, e.g. due to
|
# exitstatus can also be nil if RuboCop process crashes, e.g. due to
|
||||||
# native extension problems.
|
# native extension problems.
|
||||||
# JSON needs to be at least 2 characters.
|
# JSON needs to be at least 2 characters.
|
||||||
if !status.success? || json.to_s.length < 2
|
if !(0..1).cover?(status.exitstatus) || json.to_s.length < 2
|
||||||
raise "Error running `rubocop --format json #{args.join " "}`"
|
raise "Error running `rubocop --format json #{args.join " "}`"
|
||||||
end
|
end
|
||||||
RubocopResults.new(JSON.parse(json))
|
RubocopResults.new(JSON.parse(json))
|
||||||
|
|||||||
34
Library/Homebrew/test/cmd/style_spec.rb
Normal file
34
Library/Homebrew/test/cmd/style_spec.rb
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
require "cmd/style"
|
||||||
|
|
||||||
|
describe "brew style" do
|
||||||
|
around(:each) do |example|
|
||||||
|
begin
|
||||||
|
FileUtils.ln_s HOMEBREW_LIBRARY_PATH, HOMEBREW_LIBRARY/"Homebrew"
|
||||||
|
FileUtils.ln_s HOMEBREW_LIBRARY_PATH.parent/".rubocop.yml", HOMEBREW_LIBRARY/".rubocop.yml"
|
||||||
|
|
||||||
|
example.run
|
||||||
|
ensure
|
||||||
|
FileUtils.rm_f HOMEBREW_LIBRARY/"Homebrew"
|
||||||
|
FileUtils.rm_f HOMEBREW_LIBRARY/".rubocop.yml"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "Homebrew::check_style_json" do
|
||||||
|
let(:dir) { mktmpdir }
|
||||||
|
|
||||||
|
it "returns RubocopResults when RuboCop reports offenses" do
|
||||||
|
formula = dir/"my-formula.rb"
|
||||||
|
|
||||||
|
formula.write <<-'EOS'.undent
|
||||||
|
class MyFormula < Formula
|
||||||
|
|
||||||
|
end
|
||||||
|
EOS
|
||||||
|
|
||||||
|
rubocop_result = Homebrew.check_style_json([formula])
|
||||||
|
|
||||||
|
expect(rubocop_result.file_offenses(formula.realpath.to_s).map(&:message))
|
||||||
|
.to include("Extra empty line detected at class body beginning.")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
x
Reference in New Issue
Block a user