Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up code style and remove .rubocop_todo.yml. #3278

Merged
merged 1 commit into from
Oct 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions Library/Homebrew/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
inherit_from:
- ../.rubocop.yml
- .rubocop_todo.yml

AllCops:
Include:
Expand All @@ -26,9 +25,26 @@ Lint/NestedMethodDefinition:
Lint/ParenthesesAsGroupedExpression:
Enabled: true

Metrics/BlockNesting:
Max: 5

Metrics/ModuleLength:
Max: 360
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea to just setting these to high values. Mind doing that for line length, too? Would be good to get it down eventually but at least stop it growing for now.


Metrics/ParameterLists:
CountKeywordArgs: false

# we won't change backward compatible method names
Naming/MethodName:
Exclude:
- 'compat/**/*'

# we won't change backward compatible predicate names
Naming/PredicateName:
Exclude:
- 'compat/**/*'
NameWhitelist: is_32_bit?, is_64_bit?

Style/BlockDelimiters:
Exclude:
- '**/*_spec.rb'
Expand All @@ -41,14 +57,3 @@ Style/GuardClause:
# hash-rockets preferred for formulae, a: 1 preferred elsewhere
Style/HashSyntax:
EnforcedStyle: ruby19_no_mixed_keys

# we won't change backward compatible method names
Naming/MethodName:
Exclude:
- 'compat/**/*'

# we won't change backward compatible predicate names
Naming/PredicateName:
Exclude:
- 'compat/**/*'
NameWhitelist: is_32_bit?, is_64_bit?
138 changes: 0 additions & 138 deletions Library/Homebrew/.rubocop_todo.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Library/Homebrew/brew.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
$stderr.puts " #{Formatter.url(e.issues_url)}"
end
exit 1
rescue Exception => e
rescue Exception => e # rubocop:disable Lint/RescueException
onoe e
if internal_cmd && defined?(OS::ISSUES_URL) &&
!ENV["HOMEBREW_NO_AUTO_UPDATE"]
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def fixopt(f)
options = Options.create(ARGV.flags_only)
build = Build.new(formula, options)
build.install
rescue Exception => e
rescue Exception => e # rubocop:disable Lint/RescueException
Marshal.dump(e, error_pipe)
error_pipe.close
exit! 1
Expand Down
6 changes: 4 additions & 2 deletions Library/Homebrew/cmd/fetch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ def fetch
if fetch_bottle?(f)
begin
fetch_formula(f.bottle)
rescue Exception => e
raise if ARGV.homebrew_developer? || e.is_a?(Interrupt)
rescue Interrupt
raise
rescue => e
raise if ARGV.homebrew_developer?
fetched_bottle = false
onoe e.message
opoo "Bottle fetch failed: fetching the source."
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/cmd/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ def install_formula(f)
rescue FormulaInstallationAlreadyAttemptedError
# We already attempted to install f as part of the dependency tree of
# another formula. In that case, don't generate an error, just move on.
return
rescue CannotInstallFormulaError => e
ofail e.message
end
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/cmd/reinstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def reinstall_formula(f)
fi.install
fi.finish
rescue FormulaInstallationAlreadyAttemptedError
# next
rescue Exception
return
rescue Exception # rubocop:disable Lint/RescueException
ignore_interrupts { restore_backup(keg, keg_was_linked) }
raise
else
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/cmd/style.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def check_style_impl(files, output_type, options = {})

case output_type
when :print
args << "--debug" if ARGV.debug?
args << "--display-cop-names" if ARGV.include? "--display-cop-names"
args << "--format" << "simple" if files
system(cache_env, "rubocop", "_#{HOMEBREW_RUBOCOP_VERSION}_", *args)
Expand Down
3 changes: 1 addition & 2 deletions Library/Homebrew/cmd/tap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ def tap
quiet: ARGV.quieter?
rescue TapRemoteMismatchError => e
odie e
rescue TapAlreadyTappedError, TapAlreadyUnshallowError
# Do nothing.
rescue TapAlreadyTappedError, TapAlreadyUnshallowError # rubocop:disable Lint/HandleExceptions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not worth keeping the comment and returning nil instead?

end
end
end
Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/cmd/update-report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def report
new_version = formula.pkg_version
old_version = FormulaVersions.new(formula).formula_at_revision(@initial_revision, &:pkg_version)
next if new_version == old_version
rescue Exception => e
rescue Exception => e # rubocop:disable Lint/RescueException
onoe "#{e.message}\n#{e.backtrace.join "\n"}" if ARGV.homebrew_developer?
end
@report[:M] << tap.formula_file_to_name(src)
Expand Down Expand Up @@ -460,7 +460,7 @@ def migrate_tap_migration
unless Formulary.factory(new_full_name).keg_only?
system HOMEBREW_BREW_FILE, "link", new_full_name, "--overwrite"
end
rescue Exception => e
rescue Exception => e # rubocop:disable Lint/RescueException
onoe "#{e.message}\n#{e.backtrace.join "\n"}" if ARGV.homebrew_developer?
end
next
Expand Down Expand Up @@ -521,7 +521,7 @@ def migrate_formula_rename

begin
f = Formulary.factory(new_full_name)
rescue Exception => e
rescue Exception => e # rubocop:disable Lint/RescueException
onoe "#{e.message}\n#{e.backtrace.join "\n"}" if ARGV.homebrew_developer?
next
end
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/cmd/upgrade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def upgrade_formula(f)
rescue FormulaInstallationAlreadyAttemptedError
# We already attempted to upgrade f as part of the dependency tree of
# another formula. In that case, don't generate an error, just move on.
return
rescue CannotInstallFormulaError => e
ofail e
rescue BuildError => e
Expand Down
6 changes: 4 additions & 2 deletions Library/Homebrew/cmd/uses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,13 @@ def uses
end
end

dep_formulae = deps.map do |dep|
dep_formulae = deps.flat_map do |dep|
begin
dep.to_formula
rescue
[]
end
end.compact
end

reqs_by_formula = ([f] + dep_formulae).flat_map do |formula|
formula.requirements.map { |req| [formula, req] }
Expand Down Expand Up @@ -118,6 +119,7 @@ def uses
rescue FormulaUnavailableError
# Silently ignore this case as we don't care about things used in
# taps that aren't currently tapped.
next
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/debrew.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Debrew
module Raise
def raise(*)
super
rescue Exception => e
rescue Exception => e # rubocop:disable Lint/RescueException
e.extend(Ignorable)
super(e) unless Debrew.debug(e) == :ignore
end
Expand Down Expand Up @@ -92,7 +92,7 @@ def self.debrew
yield
rescue SystemExit
original_raise
rescue Exception => e
rescue Exception => e # rubocop:disable Lint/RescueException
debug(e)
ensure
@active = false
Expand All @@ -119,7 +119,7 @@ def self.debug(e)
if e.is_a?(Ignorable)
menu.choice(:irb) do
puts "When you exit this IRB session, execution will continue."
set_trace_func proc { |event, _, _, id, binding, klass|
set_trace_func proc { |event, _, _, id, binding, klass| # rubocop:disable Metrics/ParameterLists
if klass == Raise && id == :raise && event == "return"
set_trace_func(nil)
synchronize { IRB.start_within(binding) }
Expand Down
3 changes: 1 addition & 2 deletions Library/Homebrew/debrew/irb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ module IRB
@setup_done = false

extend Module.new {
def parse_opts
end
def parse_opts; end

def start_within(binding)
unless @setup_done
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _dump(*)
end

def self._load(marshaled)
new(*Marshal.load(marshaled))
new(*Marshal.load(marshaled)) # rubocop:disable Security/MarshalLoad
end

class << self
Expand Down
11 changes: 4 additions & 7 deletions Library/Homebrew/dependency_collector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require "requirement"
require "requirements"
require "set"
require "extend/cachable"

## A dependency is a formula that another formula needs to install.
## A requirement is something other than a formula that another formula
Expand All @@ -16,17 +17,13 @@
# This class is used by `depends_on` in the formula DSL to turn dependency
# specifications into the proper kinds of dependencies and requirements.
class DependencyCollector
extend Cachable

# Define the languages that we can handle as external dependencies.
LANGUAGE_MODULES = Set[
:lua, :lua51, :perl, :python, :python3, :ruby
].freeze

CACHE = {}

def self.clear_cache
CACHE.clear
end

attr_reader :deps, :requirements

def initialize
Expand All @@ -45,7 +42,7 @@ def add(spec)
end

def fetch(spec)
CACHE.fetch(cache_key(spec)) { |key| CACHE[key] = build(spec) }
self.class.cache.fetch(cache_key(spec)) { |key| self.class.cache[key] = build(spec) }
end

def cache_key(spec)
Expand Down
Loading