style: check Bash style with shellcheck
This commit is contained in:
parent
728189d3e9
commit
96504ec9dc
@ -76,13 +76,15 @@ module Homebrew
|
|||||||
|
|
||||||
cache_env = { "XDG_CACHE_HOME" => "#{HOMEBREW_CACHE}/style" }
|
cache_env = { "XDG_CACHE_HOME" => "#{HOMEBREW_CACHE}/style" }
|
||||||
|
|
||||||
|
rubocop_success = false
|
||||||
|
|
||||||
case output_type
|
case output_type
|
||||||
when :print
|
when :print
|
||||||
args << "--debug" if ARGV.debug?
|
args << "--debug" if ARGV.debug?
|
||||||
args << "--display-cop-names" if ARGV.include? "--display-cop-names"
|
args << "--display-cop-names" if ARGV.include? "--display-cop-names"
|
||||||
args << "--format" << "simple" if files
|
args << "--format" << "simple" if files
|
||||||
system(cache_env, "rubocop", "_#{HOMEBREW_RUBOCOP_VERSION}_", *args)
|
system(cache_env, "rubocop", "_#{HOMEBREW_RUBOCOP_VERSION}_", *args)
|
||||||
!$CHILD_STATUS.success?
|
rubocop_success = $CHILD_STATUS.success?
|
||||||
when :json
|
when :json
|
||||||
json, err, status =
|
json, err, status =
|
||||||
Open3.capture3(cache_env, "rubocop", "_#{HOMEBREW_RUBOCOP_VERSION}_",
|
Open3.capture3(cache_env, "rubocop", "_#{HOMEBREW_RUBOCOP_VERSION}_",
|
||||||
@ -96,10 +98,35 @@ module Homebrew
|
|||||||
raise "Error running `rubocop --format json #{args.join " "}`\n#{err}"
|
raise "Error running `rubocop --format json #{args.join " "}`\n#{err}"
|
||||||
end
|
end
|
||||||
|
|
||||||
RubocopResults.new(JSON.parse(json))
|
return RubocopResults.new(JSON.parse(json))
|
||||||
else
|
else
|
||||||
raise "Invalid output_type for check_style_impl: #{output_type}"
|
raise "Invalid output_type for check_style_impl: #{output_type}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return !rubocop_success if !files.nil? && !has_non_formula
|
||||||
|
|
||||||
|
shellcheck = which("shellcheck")
|
||||||
|
shellcheck ||= which("shellcheck", ENV["HOMEBREW_PATH"])
|
||||||
|
shellcheck ||= begin
|
||||||
|
ohai "Installing `shellcheck` for shell style checks..."
|
||||||
|
system HOMEBREW_BREW_FILE, "install", "shellcheck"
|
||||||
|
which("shellcheck") || which("shellcheck", ENV["HOMEBREW_PATH"])
|
||||||
|
end
|
||||||
|
unless shellcheck
|
||||||
|
opoo "Could not find or install `shellcheck`! Not checking shell style."
|
||||||
|
return !rubocop_success
|
||||||
|
end
|
||||||
|
|
||||||
|
shell_files = [
|
||||||
|
HOMEBREW_BREW_FILE,
|
||||||
|
*Pathname.glob("#{HOMEBREW_LIBRARY}/Homebrew/*.sh"),
|
||||||
|
*Pathname.glob("#{HOMEBREW_LIBRARY}/Homebrew/cmd/*.sh"),
|
||||||
|
*Pathname.glob("#{HOMEBREW_LIBRARY}/Homebrew/utils/*.sh"),
|
||||||
|
].select(&:exist?)
|
||||||
|
# TODO: check, fix completions here too.
|
||||||
|
# TODO: consider using ShellCheck JSON output
|
||||||
|
shellcheck_success = system shellcheck, "--shell=bash", *shell_files
|
||||||
|
!rubocop_success || !shellcheck_success
|
||||||
end
|
end
|
||||||
|
|
||||||
class RubocopResults
|
class RubocopResults
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user