From 1f963267b6bd415ce3024bb7860d5253ad8e0132 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sat, 22 Oct 2016 13:32:46 +0100 Subject: [PATCH] Update Rubocop style. Another look at the current Rubocop rules and how they fit with our existing and desired future style. Almost all of these changes were automatic. Split some rules between formulae/brew where brew doesn't have millions of cases that need fixed. --- Library/.rubocop.yml | 17 +++--- Library/Homebrew/.rubocop.yml | 87 ++++------------------------ Library/Homebrew/cmd/missing.rb | 2 +- Library/Homebrew/cmd/style.rb | 2 +- Library/Homebrew/dev-cmd/audit.rb | 7 +-- Library/Homebrew/extend/ENV/super.rb | 2 +- Library/Homebrew/locale.rb | 8 +-- Library/Homebrew/tap.rb | 2 +- Library/Homebrew/utils/formatter.rb | 4 +- 9 files changed, 33 insertions(+), 98 deletions(-) diff --git a/Library/.rubocop.yml b/Library/.rubocop.yml index 2fe2394470..d749adc353 100644 --- a/Library/.rubocop.yml +++ b/Library/.rubocop.yml @@ -48,6 +48,12 @@ Style/AlignHash: Style/AlignParameters: Enabled: false +Style/BarePercentLiterals: + EnforcedStyle: percent_q + +Style/BlockDelimiters: + EnforcedStyle: line_count_based + Style/CaseIndentation: IndentWhenRelativeTo: end @@ -76,9 +82,11 @@ Style/FileName: Style/GuardClause: Enabled: false +# depends_on a: :b looks weird in formulae. Style/HashSyntax: EnforcedStyle: hash_rockets +# disabled until it respects line length Style/IfUnlessModifier: Enabled: false @@ -133,8 +141,6 @@ Style/StringLiterals: Style/StringLiteralsInInterpolation: EnforcedStyle: double_quotes -# TODO: enforce when rubocop has shipped this -# https://github.com/bbatsov/rubocop/pull/3513 Style/TernaryParentheses: Enabled: false @@ -142,15 +148,8 @@ Style/TernaryParentheses: Style/TrailingCommaInLiteral: EnforcedStyleForMultiline: comma -Style/UnneededCapitalW: - Enabled: false - -# TODO: enforce when rubocop has fixed this -# https://github.com/bbatsov/rubocop/issues/3516 Style/VariableNumber: Enabled: false -# TODO: enforce when rubocop has fixed this -# https://github.com/bbatsov/rubocop/issues/1543 Style/WordArray: Enabled: false diff --git a/Library/Homebrew/.rubocop.yml b/Library/Homebrew/.rubocop.yml index f4f80800aa..3256743988 100644 --- a/Library/Homebrew/.rubocop.yml +++ b/Library/Homebrew/.rubocop.yml @@ -9,11 +9,19 @@ AllCops: - 'cask/**/*' - '**/vendor/**/*' +# so many of these in formulae but none in here +Lint/AmbiguousRegexpLiteral: + Enabled: true + # `formula do` uses nested method definitions Lint/NestedMethodDefinition: Exclude: - 'test/**/*' +# so many of these in formulae but none in here +Lint/ParenthesesAsGroupedExpression: + Enabled: false + Metrics/ModuleLength: CountComments: false Exclude: @@ -21,81 +29,11 @@ Metrics/ModuleLength: - 'cask/lib/hbc/macos.rb' - 'cask/lib/hbc/utils.rb' -Style/BarePercentLiterals: - EnforcedStyle: percent_q - -Style/BlockDelimiters: - EnforcedStyle: semantic - FunctionalMethods: - - expect - - find - - let - - let! - - subject - - watch - - inject - - map - - map! - - collect - - collect! - - reject - - reject! - - delete_if - - with_object - - popen_read - ProceduralMethods: - - after - - at_exit - - before - - benchmark - - bm - - bmbm - - capture_io - - capture_output - - capture_subprocess_io - - chdir - - context - - create - - define_method - - define_singleton_method - - fork - - measure - - new - - open - - realtime - - shutup - - tap - - each - - each_pair - - each_with_index - - reverse_each - - ignore_interrupts - IgnoredMethods: - - each_with_object - - it - - its - - lambda - - proc - - formula - - mock - - devel - - stable - - head - - assert_raises - - assert_nothing_raised - - resource - - with_build_environment - - ensure_writable - - satisfy - - fetch - - brew - - expand - - env - - recursive_dependencies - - trap - - link_dir - - with_system_path +# so many of these in formulae but none in here +Style/GuardClause: + Enabled: true +# hash-rockets preferred for formulae, a: 1 preferred elsewhere Style/HashSyntax: EnforcedStyle: ruby19_no_mixed_keys @@ -109,4 +47,3 @@ Style/PredicateName: Exclude: - 'compat/**/*' NameWhitelist: is_32_bit?, is_64_bit? - diff --git a/Library/Homebrew/cmd/missing.rb b/Library/Homebrew/cmd/missing.rb index 525461108b..148fe5bef0 100644 --- a/Library/Homebrew/cmd/missing.rb +++ b/Library/Homebrew/cmd/missing.rb @@ -20,7 +20,7 @@ module Homebrew Diagnostic.missing_deps(ff) do |name, missing| print "#{name}: " if ff.size > 1 - puts (missing * " ").to_s + puts missing.join(" ") end end end diff --git a/Library/Homebrew/cmd/style.rb b/Library/Homebrew/cmd/style.rb index 9538b890a9..08eb111a50 100644 --- a/Library/Homebrew/cmd/style.rb +++ b/Library/Homebrew/cmd/style.rb @@ -49,7 +49,7 @@ module Homebrew fix = options[:fix] Homebrew.install_gem_setup_path! "rubocop", "0.43.0" - args = %W[ + args = %w[ --force-exclusion ] args << "--auto-correct" if fix diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 9a15c6de71..12eaf9167e 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -137,7 +137,7 @@ class FormulaAuditor attr_reader :formula, :text, :problems - BUILD_TIME_DEPS = %W[ + BUILD_TIME_DEPS = %w[ autoconf automake boost-build @@ -449,9 +449,8 @@ class FormulaAuditor end return unless @new_formula - unless formula.deprecated_options.empty? - problem "New formulae should not use `deprecated_option`." - end + return if formula.deprecated_options.empty? + problem "New formulae should not use `deprecated_option`." end def audit_desc diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb index a3837c695a..a75cba406d 100644 --- a/Library/Homebrew/extend/ENV/super.rb +++ b/Library/Homebrew/extend/ENV/super.rb @@ -139,7 +139,7 @@ module Superenv end def determine_pkg_config_libdir - paths = %W[/usr/lib/pkgconfig] + paths = %w[/usr/lib/pkgconfig] paths += homebrew_extra_pkg_config_paths paths.to_path_s end diff --git a/Library/Homebrew/locale.rb b/Library/Homebrew/locale.rb index e749a5004c..5e778f3b4d 100644 --- a/Library/Homebrew/locale.rb +++ b/Library/Homebrew/locale.rb @@ -51,20 +51,20 @@ class Locale def include?(other) other = self.class.parse(other) unless other.is_a?(self.class) - [:language, :region, :script].all? { |var| + [:language, :region, :script].all? do |var| if other.public_send(var).nil? true else public_send(var) == other.public_send(var) end - } + end end def eql?(other) other = self.class.parse(other) unless other.is_a?(self.class) - [:language, :region, :script].all? { |var| + [:language, :region, :script].all? do |var| public_send(var) == other.public_send(var) - } + end rescue ParserError false end diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index d970a0a37f..3659abe4ff 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -206,7 +206,7 @@ class Tap end ohai "Unshallowing #{name}" unless quiet - args = %W[fetch --unshallow] + args = %w[fetch --unshallow] args << "-q" if quiet path.cd { safe_system "git", *args } return diff --git a/Library/Homebrew/utils/formatter.rb b/Library/Homebrew/utils/formatter.rb index 4685e8c5db..8a9afb9af4 100644 --- a/Library/Homebrew/utils/formatter.rb +++ b/Library/Homebrew/utils/formatter.rb @@ -78,9 +78,9 @@ module Formatter rows.times do |row_index| item_indices_for_row = row_index.step(objects.size - 1, rows).to_a - first_n = item_indices_for_row[0...-1].map { |index| + first_n = item_indices_for_row[0...-1].map do |index| objects[index] + "".rjust(col_width - object_lengths[index]) - } + end # don't add trailing whitespace to last column last = objects.values_at(item_indices_for_row.last)