diff options
| author | Mike McQuaid | 2016-10-01 21:20:18 +0100 |
|---|---|---|
| committer | GitHub | 2016-10-01 21:20:18 +0100 |
| commit | fa14c262454c2678ca9c8a1caa2f0080833ac67a (patch) | |
| tree | b58d6d7b308bfc2fa57f2ea544c6e4da6fcdf95b /Library/Homebrew | |
| parent | 19e633f1900ea910c2a9db85dc7c7bea0825676d (diff) | |
| parent | 84c29fcf1ff29df31ab98b03ed4cedf9222ce161 (diff) | |
| download | brew-fa14c262454c2678ca9c8a1caa2f0080833ac67a.tar.bz2 | |
Merge pull request #1169 from reitermarkus/rubocop-separate-configs
Use separate RuboCop configs for formulae and core code.
Diffstat (limited to 'Library/Homebrew')
| -rw-r--r-- | Library/Homebrew/.rubocop.yml | 112 | ||||
| -rw-r--r-- | Library/Homebrew/.rubocop_todo.yml | 211 | ||||
| -rw-r--r-- | Library/Homebrew/cmd/style.rb | 45 | ||||
| -rw-r--r-- | Library/Homebrew/dev-cmd/bottle.rb | 8 |
4 files changed, 352 insertions, 24 deletions
diff --git a/Library/Homebrew/.rubocop.yml b/Library/Homebrew/.rubocop.yml new file mode 100644 index 000000000..f4f80800a --- /dev/null +++ b/Library/Homebrew/.rubocop.yml @@ -0,0 +1,112 @@ +inherit_from: + - ../.rubocop.yml + - .rubocop_todo.yml + +AllCops: + Include: + - '**/.simplecov' + Exclude: + - 'cask/**/*' + - '**/vendor/**/*' + +# `formula do` uses nested method definitions +Lint/NestedMethodDefinition: + Exclude: + - 'test/**/*' + +Metrics/ModuleLength: + CountComments: false + Exclude: + - 'cask/lib/hbc/locations.rb' + - '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 + +Style/HashSyntax: + EnforcedStyle: ruby19_no_mixed_keys + +# we won't change backward compatible method names +Style/MethodName: + Exclude: + - 'compat/**/*' + +# we won't change backward compatible predicate names +Style/PredicateName: + Exclude: + - 'compat/**/*' + NameWhitelist: is_32_bit?, is_64_bit? + diff --git a/Library/Homebrew/.rubocop_todo.yml b/Library/Homebrew/.rubocop_todo.yml new file mode 100644 index 000000000..4c6a4bbc5 --- /dev/null +++ b/Library/Homebrew/.rubocop_todo.yml @@ -0,0 +1,211 @@ +# This configuration was generated by +# `rubocop --auto-gen-config --exclude-limit 100` +# on 2016-09-28 22:26:33 +0200 using RuboCop version 0.43.0. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 16 +Lint/HandleExceptions: + Exclude: + - 'cmd/install.rb' + - 'cmd/reinstall.rb' + - 'cmd/tap.rb' + - 'cmd/update-report.rb' + - 'cmd/upgrade.rb' + - 'cmd/uses.rb' + - 'descriptions.rb' + - 'diagnostic.rb' + - 'extend/ENV/super.rb' + - 'extend/pathname.rb' + - 'formula.rb' + - 'formula_versions.rb' + - 'test/test_ENV.rb' + +# Offense count: 3 +Lint/IneffectiveAccessModifier: + Exclude: + - 'formula.rb' + - 'version.rb' + +# Offense count: 1 +Lint/Loop: + Exclude: + - 'patch.rb' + +# Offense count: 28 +Lint/RescueException: + Exclude: + - 'brew.rb' + - 'build.rb' + - 'cmd/fetch.rb' + - 'cmd/reinstall.rb' + - 'cmd/update-report.rb' + - 'debrew.rb' + - 'dev-cmd/pull.rb' + - 'dev-cmd/test.rb' + - 'formula.rb' + - 'formula_installer.rb' + - 'migrator.rb' + - 'postinstall.rb' + - 'readall.rb' + - 'test.rb' + - 'test/test_ENV.rb' + - 'utils/fork.rb' + +# Offense count: 1 +Lint/ShadowedException: + Exclude: + - 'utils/fork.rb' + +# Offense count: 14 +Metrics/BlockNesting: + Max: 5 + +# Offense count: 19 +# Configuration parameters: CountComments. +Metrics/ModuleLength: + Max: 366 + +# Offense count: 2 +# Configuration parameters: CountKeywordArgs. +Metrics/ParameterLists: + Max: 6 + +# Offense count: 8 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: percent_q, bare_percent +Style/BarePercentLiterals: + Exclude: + - 'dev-cmd/audit.rb' + - 'test/test_diagnostic.rb' + - 'test/test_exceptions.rb' + - 'test/test_patch.rb' + - 'test/test_string.rb' + +# Offense count: 134 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods. +# SupportedStyles: line_count_based, semantic, braces_for_chaining +# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object +# FunctionalMethods: let, let!, subject, watch +# IgnoredMethods: lambda, proc, it +Style/BlockDelimiters: + Exclude: + - 'caveats.rb' + - 'cleaner.rb' + - 'cleanup.rb' + - 'cmd/deps.rb' + - 'cmd/desc.rb' + - 'cmd/fetch.rb' + - 'cmd/help.rb' + - 'cmd/info.rb' + - 'cmd/linkapps.rb' + - 'cmd/list.rb' + - 'cmd/outdated.rb' + - 'cmd/reinstall.rb' + - 'cmd/search.rb' + - 'cmd/tap-info.rb' + - 'cmd/unlinkapps.rb' + - 'cmd/update-report.rb' + - 'cmd/upgrade.rb' + - 'cmd/uses.rb' + - 'compilers.rb' + - 'debrew.rb' + - 'descriptions.rb' + - 'dev-cmd/aspell-dictionaries.rb' + - 'dev-cmd/audit.rb' + - 'dev-cmd/bottle.rb' + - 'dev-cmd/edit.rb' + - 'dev-cmd/man.rb' + - 'diagnostic.rb' + - 'exceptions.rb' + - 'extend/ARGV.rb' + - 'extend/ENV/shared.rb' + - 'extend/ENV/std.rb' + - 'extend/fileutils.rb' + - 'extend/os/mac/formula_cellar_checks.rb' + - 'extend/pathname.rb' + - 'formula.rb' + - 'formula_assertions.rb' + - 'formula_cellar_checks.rb' + - 'formula_installer.rb' + - 'formulary.rb' + - 'global.rb' + - 'keg.rb' + - 'language/haskell.rb' + - 'language/node.rb' + - 'language/python.rb' + - 'migrator.rb' + - 'os/mac/linkage_checker.rb' + - 'os/mac/xquartz.rb' + - 'patch.rb' + - 'readall.rb' + - 'software_spec.rb' + - 'tap.rb' + - 'test/lib/config.rb' + - 'test/test_ARGV.rb' + - 'test/test_cleanup.rb' + - 'test/test_dependency_collector.rb' + - 'test/test_formula_installer.rb' + - 'test/test_formula_installer_bottle.rb' + - 'test/test_formulary.rb' + - 'test/test_gpg.rb' + - 'test/test_migrator.rb' + - 'test/test_pathname.rb' + - 'test/test_tap.rb' + - 'test/test_utils.rb' + - 'test/testing_env.rb' + - 'utils.rb' + - 'utils/github.rb' + +# Offense count: 7 +Style/ClassVars: + Exclude: + - 'dev-cmd/audit.rb' + - 'formula_installer.rb' + - 'test/testing_env.rb' + - 'utils.rb' + +# Offense count: 13 +# Configuration parameters: AllowedVariables. +Style/GlobalVars: + Exclude: + - 'diagnostic.rb' + - 'utils.rb' + +# Offense count: 2 +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: module_function, extend_self +Style/ModuleFunction: + Exclude: + - 'global.rb' + - 'os/mac/xcode.rb' + +# Offense count: 8 +Style/MultilineBlockChain: + Exclude: + - 'cmd/search.rb' + - 'dev-cmd/aspell-dictionaries.rb' + - 'dev-cmd/audit.rb' + - 'dev-cmd/man.rb' + - 'diagnostic.rb' + - 'test/test_patching.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +Style/MutableConstant: + Exclude: + - 'dependency_collector.rb' + - 'formulary.rb' + - 'tab.rb' + - 'tap.rb' + +# Offense count: 8 +Style/OpMethod: + Exclude: + - 'dependencies.rb' + - 'install_renamed.rb' + - 'options.rb' diff --git a/Library/Homebrew/cmd/style.rb b/Library/Homebrew/cmd/style.rb index db61116be..e666eb200 100644 --- a/Library/Homebrew/cmd/style.rb +++ b/Library/Homebrew/cmd/style.rb @@ -19,7 +19,7 @@ require "utils/json" module Homebrew def style target = if ARGV.named.empty? - [HOMEBREW_LIBRARY_PATH] + nil elsif ARGV.named.any? { |file| File.exist? file } ARGV.named elsif ARGV.named.any? { |tap| tap.count("/") == 1 } @@ -49,27 +49,32 @@ module Homebrew args = %W[ --force-exclusion - --config #{HOMEBREW_LIBRARY}/.rubocop.yml ] args << "--auto-correct" if fix - args += files - - HOMEBREW_LIBRARY.cd do - case output_type - when :print - args << "--display-cop-names" if ARGV.include? "--display-cop-names" - system "rubocop", "--format", "simple", *args - !$?.success? - when :json - json = Utils.popen_read_text("rubocop", "--format", "json", *args) - # exit status of 1 just means violations were found; other numbers mean execution errors - # exitstatus can also be nil if RuboCop process crashes, e.g. due to - # native extension problems - raise "Error while running RuboCop" if $?.exitstatus.nil? || $?.exitstatus > 1 - RubocopResults.new(Utils::JSON.load(json)) - else - raise "Invalid output_type for check_style_impl: #{output_type}" - end + + if files.nil? + args << "--config" << HOMEBREW_LIBRARY_PATH/".rubocop.yml" + args += [HOMEBREW_LIBRARY_PATH] + else + args << "--config" << HOMEBREW_LIBRARY/".rubocop.yml" + args += files + end + + case output_type + when :print + args << "--display-cop-names" if ARGV.include? "--display-cop-names" + args << "--format" << "simple" if files + system "rubocop", *args + !$?.success? + when :json + json = Utils.popen_read_text("rubocop", "--format", "json", *args) + # exit status of 1 just means violations were found; other numbers mean execution errors + # exitstatus can also be nil if RuboCop process crashes, e.g. due to + # native extension problems + raise "Error while running RuboCop" if $?.exitstatus.nil? || $?.exitstatus > 1 + RubocopResults.new(Utils::JSON.load(json)) + else + raise "Invalid output_type for check_style_impl: #{output_type}" end end diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index b2aa3b2c5..83e40f25d 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -44,9 +44,9 @@ module Homebrew def keg_contain?(string, keg, ignores) @put_string_exists_header, @put_filenames = nil - def print_filename(string, filename) + print_filename = lambda do |str, filename| unless @put_string_exists_header - opoo "String '#{string}' still exists in these files:" + opoo "String '#{str}' still exists in these files:" @put_string_exists_header = true end @@ -68,7 +68,7 @@ module Homebrew result ||= !linked_libraries.empty? if ARGV.verbose? - print_filename(string, file) unless linked_libraries.empty? + print_filename.call(string, file) unless linked_libraries.empty? linked_libraries.each do |lib| puts " #{Tty.gray}-->#{Tty.reset} links to #{lib}" end @@ -91,7 +91,7 @@ module Homebrew end next unless ARGV.verbose? && !text_matches.empty? - print_filename string, file + print_filename.call(string, file) text_matches.first(MAXIMUM_STRING_MATCHES).each do |match, offset| puts " #{Tty.gray}-->#{Tty.reset} match '#{match}' at offset #{Tty.em}0x#{offset}#{Tty.reset}" end |
