Merge branch 'master' into audit_line_rubocop_part_4_rebase_attempt_1
This commit is contained in:
commit
bdc7eba4b3
@ -63,26 +63,26 @@ Metrics/AbcSize:
|
|||||||
Max: 250
|
Max: 250
|
||||||
|
|
||||||
Metrics/BlockLength:
|
Metrics/BlockLength:
|
||||||
Max: 1250
|
Max: 144
|
||||||
|
|
||||||
Metrics/ClassLength:
|
Metrics/ClassLength:
|
||||||
Max: 1500
|
Max: 589
|
||||||
|
|
||||||
Metrics/CyclomaticComplexity:
|
Metrics/CyclomaticComplexity:
|
||||||
Max: 75
|
Max: 75
|
||||||
|
|
||||||
Metrics/LineLength:
|
Metrics/LineLength:
|
||||||
Max: 400
|
Max: 324
|
||||||
|
|
||||||
Metrics/MethodLength:
|
Metrics/MethodLength:
|
||||||
Max: 250
|
Max: 222
|
||||||
|
|
||||||
Metrics/ModuleLength:
|
Metrics/ModuleLength:
|
||||||
CountComments: false
|
CountComments: false
|
||||||
Exclude:
|
Max: 367
|
||||||
- '**/bin/**/*'
|
|
||||||
- '**/cmd/**/*'
|
Metrics/ParameterLists:
|
||||||
- '**/lib/**/*'
|
CountKeywordArgs: false
|
||||||
|
|
||||||
Metrics/PerceivedComplexity:
|
Metrics/PerceivedComplexity:
|
||||||
Max: 100
|
Max: 100
|
||||||
@ -94,6 +94,9 @@ Performance/Caller:
|
|||||||
Style/Alias:
|
Style/Alias:
|
||||||
EnforcedStyle: prefer_alias
|
EnforcedStyle: prefer_alias
|
||||||
|
|
||||||
|
Style/AsciiComments:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
Style/AutoResourceCleanup:
|
Style/AutoResourceCleanup:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
@ -119,7 +122,7 @@ Style/Encoding:
|
|||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
# use spaces for indentation; detect tabs
|
# use spaces for indentation; detect tabs
|
||||||
Style/Tab:
|
Layout/Tab:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
# dashes in filenames are typical
|
# dashes in filenames are typical
|
||||||
|
|||||||
@ -25,14 +25,20 @@ Lint/NestedMethodDefinition:
|
|||||||
Lint/ParenthesesAsGroupedExpression:
|
Lint/ParenthesesAsGroupedExpression:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
|
Metrics/BlockLength:
|
||||||
|
Max: 1250
|
||||||
|
|
||||||
Metrics/BlockNesting:
|
Metrics/BlockNesting:
|
||||||
Max: 5
|
Max: 5
|
||||||
|
|
||||||
Metrics/ModuleLength:
|
Metrics/ClassLength:
|
||||||
Max: 360
|
Max: 1226
|
||||||
|
|
||||||
Metrics/ParameterLists:
|
Metrics/LineLength:
|
||||||
CountKeywordArgs: false
|
Max: 244
|
||||||
|
|
||||||
|
Metrics/MethodLength:
|
||||||
|
Max: 195
|
||||||
|
|
||||||
# we won't change backward compatible method names
|
# we won't change backward compatible method names
|
||||||
Naming/MethodName:
|
Naming/MethodName:
|
||||||
|
|||||||
@ -9,7 +9,7 @@ RUBY_VERSION_SPLIT = RUBY_VERSION.split "."
|
|||||||
RUBY_X = RUBY_VERSION_SPLIT[0].to_i
|
RUBY_X = RUBY_VERSION_SPLIT[0].to_i
|
||||||
RUBY_Y = RUBY_VERSION_SPLIT[1].to_i
|
RUBY_Y = RUBY_VERSION_SPLIT[1].to_i
|
||||||
if RUBY_X < 2 || (RUBY_X == 2 && RUBY_Y < 3)
|
if RUBY_X < 2 || (RUBY_X == 2 && RUBY_Y < 3)
|
||||||
raise "Homebrew must be run under Ruby 2.3!"
|
raise "Homebrew must be run under Ruby 2.3! You're running #{RUBY_VERSION}."
|
||||||
end
|
end
|
||||||
|
|
||||||
require "pathname"
|
require "pathname"
|
||||||
|
|||||||
@ -8,9 +8,6 @@ module Hbc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
cask = casks.first
|
|
||||||
cask_path = cask.sourcefile_path
|
|
||||||
odebug "Opening editor for Cask #{cask.token}"
|
|
||||||
exec_editor cask_path
|
exec_editor cask_path
|
||||||
rescue CaskUnavailableError => e
|
rescue CaskUnavailableError => e
|
||||||
reason = e.reason.empty? ? "" : "#{e.reason} "
|
reason = e.reason.empty? ? "" : "#{e.reason} "
|
||||||
@ -18,6 +15,14 @@ module Hbc
|
|||||||
raise e.class.new(e.token, reason)
|
raise e.class.new(e.token, reason)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def cask_path
|
||||||
|
casks.first.sourcefile_path
|
||||||
|
rescue CaskInvalidError
|
||||||
|
path = CaskLoader.path(args.first)
|
||||||
|
return path if path.file?
|
||||||
|
raise
|
||||||
|
end
|
||||||
|
|
||||||
def self.help
|
def self.help
|
||||||
"edits the given Cask"
|
"edits the given Cask"
|
||||||
end
|
end
|
||||||
|
|||||||
@ -88,7 +88,7 @@ module Hbc
|
|||||||
bomfile.close
|
bomfile.close
|
||||||
|
|
||||||
Tempfile.open(["", ".list"]) do |filelist|
|
Tempfile.open(["", ".list"]) do |filelist|
|
||||||
filelist.write(bom_filelist_from_path(mount))
|
filelist.puts(bom_filelist_from_path(mount))
|
||||||
filelist.close
|
filelist.close
|
||||||
|
|
||||||
@command.run!("/usr/bin/mkbom", args: ["-s", "-i", filelist.path, "--", bomfile.path])
|
@command.run!("/usr/bin/mkbom", args: ["-s", "-i", filelist.path, "--", bomfile.path])
|
||||||
@ -98,16 +98,17 @@ module Hbc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def bom_filelist_from_path(mount)
|
def bom_filelist_from_path(mount)
|
||||||
Dir.chdir(mount) do
|
# We need to use `find` here instead of Ruby in order to properly handle
|
||||||
Dir.glob("**/*", File::FNM_DOTMATCH).map do |path|
|
# file names containing special characters, such as “e” + “´” vs. “é”.
|
||||||
next if skip_path?(Pathname(path))
|
@command.run("/usr/bin/find", args: [".", "-print0"], chdir: mount, print_stderr: false).stdout
|
||||||
(path == ".") ? path : path.prepend("./")
|
.split("\0")
|
||||||
end.compact.join("\n").concat("\n")
|
.reject { |path| skip_path?(mount, path) }
|
||||||
end
|
.join("\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
def skip_path?(path)
|
def skip_path?(mount, path)
|
||||||
dmg_metadata?(path) || system_dir_symlink?(path)
|
path = Pathname(path.sub(%r{^\./}, ""))
|
||||||
|
dmg_metadata?(path) || system_dir_symlink?(mount, path)
|
||||||
end
|
end
|
||||||
|
|
||||||
# unnecessary DMG metadata
|
# unnecessary DMG metadata
|
||||||
@ -130,9 +131,10 @@ module Hbc
|
|||||||
DMG_METADATA_FILES.include?(relative_root.basename.to_s)
|
DMG_METADATA_FILES.include?(relative_root.basename.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
def system_dir_symlink?(path)
|
def system_dir_symlink?(mount, path)
|
||||||
|
full_path = Pathname(mount).join(path)
|
||||||
# symlinks to system directories (commonly to /Applications)
|
# symlinks to system directories (commonly to /Applications)
|
||||||
path.symlink? && MacOS.system_dir?(path.readlink)
|
full_path.symlink? && MacOS.system_dir?(full_path.readlink)
|
||||||
end
|
end
|
||||||
|
|
||||||
def mounts_from_plist(plist)
|
def mounts_from_plist(plist)
|
||||||
|
|||||||
@ -8,14 +8,14 @@ require "hbc/utils/hash_validator"
|
|||||||
|
|
||||||
module Hbc
|
module Hbc
|
||||||
class SystemCommand
|
class SystemCommand
|
||||||
attr_reader :command
|
extend Predicable
|
||||||
|
|
||||||
def self.run(executable, options = {})
|
def self.run(executable, **options)
|
||||||
new(executable, options).run!
|
new(executable, **options).run!
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.run!(command, options = {})
|
def self.run!(command, **options)
|
||||||
run(command, options.merge(must_succeed: true))
|
run(command, **options, must_succeed: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def run!
|
def run!
|
||||||
@ -26,38 +26,49 @@ module Hbc
|
|||||||
case type
|
case type
|
||||||
when :stdout
|
when :stdout
|
||||||
processed_output[:stdout] << line
|
processed_output[:stdout] << line
|
||||||
ohai line.chomp if options[:print_stdout]
|
ohai line.chomp if print_stdout?
|
||||||
when :stderr
|
when :stderr
|
||||||
processed_output[:stderr] << line
|
processed_output[:stderr] << line
|
||||||
ohai line.chomp if options[:print_stderr]
|
ohai line.chomp if print_stderr?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_success if options[:must_succeed]
|
assert_success if must_succeed?
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(executable, options)
|
def initialize(executable, args: [], sudo: false, input: [], print_stdout: false, print_stderr: true, must_succeed: false, **options)
|
||||||
|
executable, *args = Shellwords.shellescape(executable) if args.empty?
|
||||||
|
|
||||||
@executable = executable
|
@executable = executable
|
||||||
|
@args = args
|
||||||
|
@sudo = sudo
|
||||||
|
@input = input
|
||||||
|
@print_stdout = print_stdout
|
||||||
|
@print_stderr = print_stderr
|
||||||
|
@must_succeed = must_succeed
|
||||||
|
options.extend(HashValidator).assert_valid_keys(:chdir)
|
||||||
@options = options
|
@options = options
|
||||||
process_options!
|
end
|
||||||
|
|
||||||
|
def command
|
||||||
|
@command ||= [
|
||||||
|
*sudo_prefix,
|
||||||
|
executable,
|
||||||
|
*args,
|
||||||
|
].freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
attr_reader :executable, :options, :processed_output, :processed_status
|
attr_reader :executable, :args, :input, :options, :processed_output, :processed_status
|
||||||
|
|
||||||
def process_options!
|
attr_predicate :sudo?, :print_stdout?, :print_stderr?, :must_succeed?
|
||||||
options.extend(HashValidator)
|
|
||||||
.assert_valid_keys :input, :print_stdout, :print_stderr, :args, :must_succeed, :sudo
|
def sudo_prefix
|
||||||
sudo_prefix = %w[/usr/bin/sudo -E --]
|
return [] unless sudo?
|
||||||
sudo_prefix = sudo_prefix.insert(1, "-A") unless ENV["SUDO_ASKPASS"].nil?
|
askpass_flags = ENV.key?("SUDO_ASKPASS") ? ["-A"] : []
|
||||||
@command = [executable]
|
["/usr/bin/sudo", *askpass_flags, "-E", "--"]
|
||||||
options[:print_stderr] = true unless options.key?(:print_stderr)
|
|
||||||
@command.unshift(*sudo_prefix) if options[:sudo]
|
|
||||||
@command.concat(options[:args]) if options.key?(:args) && !options[:args].empty?
|
|
||||||
@command[0] = Shellwords.shellescape(@command[0]) if @command.size == 1
|
|
||||||
nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_success
|
def assert_success
|
||||||
@ -77,7 +88,7 @@ module Hbc
|
|||||||
|
|
||||||
def each_output_line(&b)
|
def each_output_line(&b)
|
||||||
raw_stdin, raw_stdout, raw_stderr, raw_wait_thr =
|
raw_stdin, raw_stdout, raw_stderr, raw_wait_thr =
|
||||||
Open3.popen3(*expanded_command)
|
Open3.popen3(*expanded_command, **options)
|
||||||
|
|
||||||
write_input_to(raw_stdin)
|
write_input_to(raw_stdin)
|
||||||
raw_stdin.close_write
|
raw_stdin.close_write
|
||||||
@ -87,7 +98,7 @@ module Hbc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def write_input_to(raw_stdin)
|
def write_input_to(raw_stdin)
|
||||||
[*options[:input]].each { |line| raw_stdin.print line }
|
[*input].each(&raw_stdin.method(:print))
|
||||||
end
|
end
|
||||||
|
|
||||||
def each_line_from(sources)
|
def each_line_from(sources)
|
||||||
|
|||||||
@ -109,7 +109,7 @@ module Homebrew
|
|||||||
args << "--config" << HOMEBREW_LIBRARY_PATH/".rubocop.yml"
|
args << "--config" << HOMEBREW_LIBRARY_PATH/".rubocop.yml"
|
||||||
args << HOMEBREW_LIBRARY_PATH
|
args << HOMEBREW_LIBRARY_PATH
|
||||||
else
|
else
|
||||||
args << "--config" << HOMEBREW_LIBRARY/".auditcops.yml"
|
args << "--config" << HOMEBREW_LIBRARY/".rubocop_audit.yml"
|
||||||
args += files
|
args += files
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -78,4 +78,9 @@ class Formula
|
|||||||
def startup_plist
|
def startup_plist
|
||||||
odeprecated "Formula#startup_plist", "Formula#plist"
|
odeprecated "Formula#startup_plist", "Formula#plist"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def rake(*args)
|
||||||
|
# odeprecated "FileUtils#rake", "system \"rake\""
|
||||||
|
system "rake", *args
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -560,7 +560,7 @@ module Homebrew
|
|||||||
req = Net::HTTP::Head.new bottle_info.url
|
req = Net::HTTP::Head.new bottle_info.url
|
||||||
req.initialize_http_header "User-Agent" => HOMEBREW_USER_AGENT_RUBY
|
req.initialize_http_header "User-Agent" => HOMEBREW_USER_AGENT_RUBY
|
||||||
res = http.request req
|
res = http.request req
|
||||||
break if res.is_a?(Net::HTTPSuccess)
|
break if res.is_a?(Net::HTTPSuccess) || res.code == "302"
|
||||||
|
|
||||||
unless res.is_a?(Net::HTTPClientError)
|
unless res.is_a?(Net::HTTPClientError)
|
||||||
raise "Failed to find published #{f} bottle at #{url} (#{res.code} #{res.message})!"
|
raise "Failed to find published #{f} bottle at #{url} (#{res.code} #{res.message})!"
|
||||||
|
|||||||
@ -101,11 +101,6 @@ module FileUtils
|
|||||||
system Formulary.factory("scons").opt_bin/"scons", *args
|
system Formulary.factory("scons").opt_bin/"scons", *args
|
||||||
end
|
end
|
||||||
|
|
||||||
# Run the `rake` from the `ruby` Homebrew is using rather than whatever is in the `PATH`.
|
|
||||||
def rake(*args)
|
|
||||||
system RUBY_BIN/"rake", *args
|
|
||||||
end
|
|
||||||
|
|
||||||
# Run `make` 3.81 or newer.
|
# Run `make` 3.81 or newer.
|
||||||
# Uses the system make on Leopard and newer, and the
|
# Uses the system make on Leopard and newer, and the
|
||||||
# path to the actually-installed make on Tiger or older.
|
# path to the actually-installed make on Tiger or older.
|
||||||
|
|||||||
@ -47,19 +47,11 @@ module OS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def languages
|
def languages
|
||||||
return @languages unless @languages.nil?
|
@languages ||= [
|
||||||
|
*ARGV.value("language")&.split(","),
|
||||||
@languages = Utils.popen_read("defaults", "read", ".GlobalPreferences", "AppleLanguages").scan(/[^ \n"(),]+/)
|
*ENV["HOMEBREW_LANGUAGES"]&.split(","),
|
||||||
|
*Open3.capture2("defaults", "read", "-g", "AppleLanguages")[0].scan(/[^ \n"(),]+/),
|
||||||
if ENV["HOMEBREW_LANGUAGES"]
|
].uniq
|
||||||
@languages = ENV["HOMEBREW_LANGUAGES"].split(",") + @languages
|
|
||||||
end
|
|
||||||
|
|
||||||
if ARGV.value("language")
|
|
||||||
@languages = ARGV.value("language").split(",") + @languages
|
|
||||||
end
|
|
||||||
|
|
||||||
@languages = @languages.uniq
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def language
|
def language
|
||||||
|
|||||||
@ -18,8 +18,14 @@ module RuboCop
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
# Check if a formula's desc is too long
|
# Check the formula's desc length. Should be >0 and <80 characters.
|
||||||
desc = parameters(desc_call).first
|
desc = parameters(desc_call).first
|
||||||
|
pure_desc_length = string_content(desc).length
|
||||||
|
if pure_desc_length.zero?
|
||||||
|
problem "The desc (description) should not be an empty string."
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
desc_length = "#{@formula_name}: #{string_content(desc)}".length
|
desc_length = "#{@formula_name}: #{string_content(desc)}".length
|
||||||
max_desc_length = 80
|
max_desc_length = 80
|
||||||
return if desc_length <= max_desc_length
|
return if desc_length <= max_desc_length
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
require 'FileUtils'
|
require "FileUtils"
|
||||||
require_relative "./extend/formula_cop"
|
require_relative "./extend/formula_cop"
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
@ -89,7 +89,7 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
find_instance_method_call(body_node, :man, :+) do |method|
|
find_instance_method_call(body_node, :man, :+) do |method|
|
||||||
next unless match = regex_match_group(parameters(method).first, %r{man[1-8]})
|
next unless match = regex_match_group(parameters(method).first, /man[1-8]/)
|
||||||
problem "\"#{method.source}\" should be \"#{match[0]}\""
|
problem "\"#{method.source}\" should be \"#{match[0]}\""
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -132,13 +132,13 @@ module RuboCop
|
|||||||
|
|
||||||
find_every_method_call_by_name(body_node, :depends_on).each do |method|
|
find_every_method_call_by_name(body_node, :depends_on).each do |method|
|
||||||
key, value = destructure_hash(parameters(method).first)
|
key, value = destructure_hash(parameters(method).first)
|
||||||
next if (key.nil? || value.nil?)
|
next if key.nil? || value.nil?
|
||||||
next unless match = regex_match_group(value, %r{(lua|perl|python|ruby)(\d*)})
|
next unless match = regex_match_group(value, /(lua|perl|python|ruby)(\d*)/)
|
||||||
problem "#{match[1]} modules should be vendored rather than use deprecated #{method.source}`"
|
problem "#{match[1]} modules should be vendored rather than use deprecated #{method.source}`"
|
||||||
end
|
end
|
||||||
|
|
||||||
find_every_method_call_by_name(body_node, :system).each do |method|
|
find_every_method_call_by_name(body_node, :system).each do |method|
|
||||||
next unless match = regex_match_group(parameters(method).first, %r{(env|export)(\s+)?})
|
next unless match = regex_match_group(parameters(method).first, /(env|export)(\s+)?/)
|
||||||
problem "Use ENV instead of invoking '#{match[1]}' to modify the environment"
|
problem "Use ENV instead of invoking '#{match[1]}' to modify the environment"
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -163,7 +163,7 @@ module RuboCop
|
|||||||
|
|
||||||
find_instance_method_call(body_node, "ARGV", :include?) do |method|
|
find_instance_method_call(body_node, "ARGV", :include?) do |method|
|
||||||
param = parameters(method).first
|
param = parameters(method).first
|
||||||
next unless match = regex_match_group(param, %r{--(HEAD|devel)})
|
next unless match = regex_match_group(param, /--(HEAD|devel)/)
|
||||||
problem "Use \"if build.#{match[1].downcase}?\" instead"
|
problem "Use \"if build.#{match[1].downcase}?\" instead"
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -240,9 +240,21 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
find_every_method_call_by_name(body_node, :assert).each do |method|
|
find_every_method_call_by_name(body_node, :assert).each do |method|
|
||||||
if method_called?(method, :include?) && !method_called?(method, :!)
|
if method_called_ever?(method, :include?) && !method_called_ever?(method, :!)
|
||||||
problem "Use `assert_match` instead of `assert ...include?`"
|
problem "Use `assert_match` instead of `assert ...include?`"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if method_called_ever?(method, :exist?) && !method_called_ever?(method, :!)
|
||||||
|
problem "Use `assert_predicate <path_to_file>, :exist?` instead of `#{method.source}`"
|
||||||
|
end
|
||||||
|
|
||||||
|
if method_called_ever?(method, :exist?) && method_called_ever?(method, :!)
|
||||||
|
problem "Use `refute_predicate <path_to_file>, :exist?` instead of `#{method.source}`"
|
||||||
|
end
|
||||||
|
|
||||||
|
if method_called_ever?(method, :executable?) && !method_called_ever?(method, :!)
|
||||||
|
problem "Use `assert_predicate <path_to_file>, :executable?` instead of `#{method.source}`"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
find_every_method_call_by_name(body_node, :depends_on).each do |method|
|
find_every_method_call_by_name(body_node, :depends_on).each do |method|
|
||||||
@ -259,16 +271,15 @@ module RuboCop
|
|||||||
|
|
||||||
find_instance_method_call(body_node, "Dir", :[]) do |method|
|
find_instance_method_call(body_node, "Dir", :[]) do |method|
|
||||||
path = parameters(method).first
|
path = parameters(method).first
|
||||||
next if !path.str_type?
|
next unless path.str_type?
|
||||||
next unless match = regex_match_group(path, /^[^\*{},]+$/)
|
next unless match = regex_match_group(path, /^[^\*{},]+$/)
|
||||||
problem "Dir([\"#{string_content(path)}\"]) is unnecessary; just use \"#{match[0]}\""
|
problem "Dir([\"#{string_content(path)}\"]) is unnecessary; just use \"#{match[0]}\""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fileutils_methods = Regexp.new(FileUtils.singleton_methods(false).map { |m| "(?-mix:^" + Regexp.escape(m) + "$)" }.join("|"))
|
||||||
fileUtils_methods= Regexp.new(FileUtils.singleton_methods(false).map { |m| '(?-mix:^'+Regexp.escape(m)+'$)' }.join '|')
|
|
||||||
find_every_method_call_by_name(body_node, :system).each do |method|
|
find_every_method_call_by_name(body_node, :system).each do |method|
|
||||||
param = parameters(method).first
|
param = parameters(method).first
|
||||||
next unless match = regex_match_group(param, fileUtils_methods)
|
next unless match = regex_match_group(param, fileutils_methods)
|
||||||
problem "Use the `#{match}` Ruby method instead of `#{method.source}`"
|
problem "Use the `#{match}` Ruby method instead of `#{method.source}`"
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -300,25 +311,25 @@ module RuboCop
|
|||||||
|
|
||||||
find_instance_method_call(body_node, :build, :without?) do |method|
|
find_instance_method_call(body_node, :build, :without?) do |method|
|
||||||
arg = parameters(method).first
|
arg = parameters(method).first
|
||||||
next unless match = regex_match_group(arg, %r{-?-?without-(.*)})
|
next unless match = regex_match_group(arg, /-?-?without-(.*)/)
|
||||||
problem "Don't duplicate 'without': Use `build.without? \"#{match[1]}\"` to check for \"--without-#{match[1]}\""
|
problem "Don't duplicate 'without': Use `build.without? \"#{match[1]}\"` to check for \"--without-#{match[1]}\""
|
||||||
end
|
end
|
||||||
|
|
||||||
find_instance_method_call(body_node, :build, :with?) do |method|
|
find_instance_method_call(body_node, :build, :with?) do |method|
|
||||||
arg = parameters(method).first
|
arg = parameters(method).first
|
||||||
next unless match = regex_match_group(arg, %r{-?-?with-(.*)})
|
next unless match = regex_match_group(arg, /-?-?with-(.*)/)
|
||||||
problem "Don't duplicate 'with': Use `build.with? \"#{match[1]}\"` to check for \"--with-#{match[1]}\""
|
problem "Don't duplicate 'with': Use `build.with? \"#{match[1]}\"` to check for \"--with-#{match[1]}\""
|
||||||
end
|
end
|
||||||
|
|
||||||
find_instance_method_call(body_node, :build, :include?) do |method|
|
find_instance_method_call(body_node, :build, :include?) do |method|
|
||||||
arg = parameters(method).first
|
arg = parameters(method).first
|
||||||
next unless match = regex_match_group(arg, %r{with(out)?-(.*)})
|
next unless match = regex_match_group(arg, /with(out)?-(.*)/)
|
||||||
problem "Use build.with#{match[1]}? \"#{match[2]}\" instead of build.include? 'with#{match[1]}-#{match[2]}'"
|
problem "Use build.with#{match[1]}? \"#{match[2]}\" instead of build.include? 'with#{match[1]}-#{match[2]}'"
|
||||||
end
|
end
|
||||||
|
|
||||||
find_instance_method_call(body_node, :build, :include?) do |method|
|
find_instance_method_call(body_node, :build, :include?) do |method|
|
||||||
arg = parameters(method).first
|
arg = parameters(method).first
|
||||||
next unless match = regex_match_group(arg, %r{\-\-(.*)})
|
next unless match = regex_match_group(arg, /\-\-(.*)/)
|
||||||
problem "Reference '#{match[1]}' without dashes"
|
problem "Reference '#{match[1]}' without dashes"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -4,12 +4,12 @@ describe "brew style" do
|
|||||||
around(:each) do |example|
|
around(:each) do |example|
|
||||||
begin
|
begin
|
||||||
FileUtils.ln_s HOMEBREW_LIBRARY_PATH, HOMEBREW_LIBRARY/"Homebrew"
|
FileUtils.ln_s HOMEBREW_LIBRARY_PATH, HOMEBREW_LIBRARY/"Homebrew"
|
||||||
FileUtils.ln_s HOMEBREW_LIBRARY_PATH.parent/".rubocop.yml", HOMEBREW_LIBRARY/".auditcops.yml"
|
FileUtils.ln_s HOMEBREW_LIBRARY_PATH.parent/".rubocop.yml", HOMEBREW_LIBRARY/".rubocop_audit.yml"
|
||||||
|
|
||||||
example.run
|
example.run
|
||||||
ensure
|
ensure
|
||||||
FileUtils.rm_f HOMEBREW_LIBRARY/"Homebrew"
|
FileUtils.rm_f HOMEBREW_LIBRARY/"Homebrew"
|
||||||
FileUtils.rm_f HOMEBREW_LIBRARY/".auditcops.yml"
|
FileUtils.rm_f HOMEBREW_LIBRARY/".rubocop_audit.yml"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -27,6 +27,27 @@ describe RuboCop::Cop::FormulaAuditStrict::DescLength do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "reports an offense when desc is an empty string" do
|
||||||
|
source = <<-EOS.undent
|
||||||
|
class Foo < Formula
|
||||||
|
url 'http://example.com/foo-1.0.tgz'
|
||||||
|
desc ''
|
||||||
|
end
|
||||||
|
EOS
|
||||||
|
|
||||||
|
msg = "The desc (description) should not be an empty string."
|
||||||
|
expected_offenses = [{ message: msg,
|
||||||
|
severity: :convention,
|
||||||
|
line: 3,
|
||||||
|
column: 2,
|
||||||
|
source: source }]
|
||||||
|
|
||||||
|
inspect_source(source, "/homebrew-core/Formula/foo.rb")
|
||||||
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||||
|
expect_offense(expected, actual)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it "When desc is too long" do
|
it "When desc is too long" do
|
||||||
source = <<-EOS.undent
|
source = <<-EOS.undent
|
||||||
class Foo < Formula
|
class Foo < Formula
|
||||||
|
|||||||
@ -70,7 +70,7 @@ describe RuboCop::Cop::FormulaAudit::ClassInheritance do
|
|||||||
column: 10,
|
column: 10,
|
||||||
source: source }]
|
source: source }]
|
||||||
|
|
||||||
inspect_source(source, '/homebrew-core/Formula/foo.rb')
|
inspect_source(source, "/homebrew-core/Formula/foo.rb")
|
||||||
|
|
||||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||||
expect_offense(expected, actual)
|
expect_offense(expected, actual)
|
||||||
@ -535,6 +535,72 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "assert ...exist? without a negation" do
|
||||||
|
source = <<-EOS.undent
|
||||||
|
class Foo < Formula
|
||||||
|
desc "foo"
|
||||||
|
url 'http://example.com/foo-1.0.tgz'
|
||||||
|
assert File.exist? "default.ini"
|
||||||
|
end
|
||||||
|
EOS
|
||||||
|
|
||||||
|
expected_offenses = [{ message: 'Use `assert_predicate <path_to_file>, :exist?` instead of `assert File.exist? "default.ini"`',
|
||||||
|
severity: :convention,
|
||||||
|
line: 4,
|
||||||
|
column: 9,
|
||||||
|
source: source }]
|
||||||
|
|
||||||
|
inspect_source(source)
|
||||||
|
|
||||||
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||||
|
expect_offense(expected, actual)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "assert ...exist? with a negation" do
|
||||||
|
source = <<-EOS.undent
|
||||||
|
class Foo < Formula
|
||||||
|
desc "foo"
|
||||||
|
url 'http://example.com/foo-1.0.tgz'
|
||||||
|
assert !File.exist?("default.ini")
|
||||||
|
end
|
||||||
|
EOS
|
||||||
|
|
||||||
|
expected_offenses = [{ message: 'Use `refute_predicate <path_to_file>, :exist?` instead of `assert !File.exist?("default.ini")`',
|
||||||
|
severity: :convention,
|
||||||
|
line: 4,
|
||||||
|
column: 9,
|
||||||
|
source: source }]
|
||||||
|
|
||||||
|
inspect_source(source)
|
||||||
|
|
||||||
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||||
|
expect_offense(expected, actual)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "assert ...executable? without a negation" do
|
||||||
|
source = <<-EOS.undent
|
||||||
|
class Foo < Formula
|
||||||
|
desc "foo"
|
||||||
|
url 'http://example.com/foo-1.0.tgz'
|
||||||
|
assert File.executable? f
|
||||||
|
end
|
||||||
|
EOS
|
||||||
|
|
||||||
|
expected_offenses = [{ message: "Use `assert_predicate <path_to_file>, :executable?` instead of `assert File.executable? f`",
|
||||||
|
severity: :convention,
|
||||||
|
line: 4,
|
||||||
|
column: 9,
|
||||||
|
source: source }]
|
||||||
|
|
||||||
|
inspect_source(source)
|
||||||
|
|
||||||
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||||
|
expect_offense(expected, actual)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it "depends_on with an instance as an argument" do
|
it "depends_on with an instance as an argument" do
|
||||||
source = <<-EOS.undent
|
source = <<-EOS.undent
|
||||||
class Foo < Formula
|
class Foo < Formula
|
||||||
|
|||||||
@ -44,12 +44,12 @@ Note they are largely untested, and as always, be careful about running untested
|
|||||||
|
|
||||||
### brew-livecheck
|
### brew-livecheck
|
||||||
Check if there is a new upstream version of a formula.
|
Check if there is a new upstream version of a formula.
|
||||||
See the [`README`](https://github.com/youtux/homebrew-livecheck/blob/master/README.md) for more info and usage.
|
See the [`README`](https://github.com/Homebrew/homebrew-livecheck/blob/master/README.md) for more info and usage.
|
||||||
|
|
||||||
Install using:
|
Install using:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
brew tap youtux/livecheck
|
brew tap homebrew/livecheck
|
||||||
```
|
```
|
||||||
|
|
||||||
### brew-gem
|
### brew-gem
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user