diff options
43 files changed, 771 insertions, 710 deletions
diff --git a/Library/.rubocop.yml b/Library/.rubocop.yml index 99de0d8a2..2fe239447 100644 --- a/Library/.rubocop.yml +++ b/Library/.rubocop.yml @@ -1,12 +1,156 @@ -inherit_from: - - .rubocop_rules.yml - - .rubocop_todo.yml - AllCops: TargetRubyVersion: 2.0 - Include: - - '**/.simplecov' - Exclude: - - 'Homebrew/cask/**/*' - - 'Homebrew/vendor/**/*' - - 'Homebrew/test/vendor/**/*' + +Metrics/AbcSize: + Enabled: false + +Metrics/ClassLength: + Enabled: false + +Metrics/CyclomaticComplexity: + Enabled: false + +Metrics/LineLength: + Enabled: false + +Metrics/MethodLength: + Enabled: false + +Metrics/ModuleLength: + CountComments: false + +Metrics/PerceivedComplexity: + Enabled: false + +# favor parens-less DSL-style arguments +Lint/AmbiguousOperator: + Enabled: false + +Lint/AmbiguousRegexpLiteral: + Enabled: false + +Lint/AssignmentInCondition: + Enabled: false + +Lint/EndAlignment: + AlignWith: variable + +Lint/ParenthesesAsGroupedExpression: + Enabled: false + +Style/Alias: + EnforcedStyle: prefer_alias + +Style/AlignHash: + Enabled: false + +# `system` is a special case and aligns on second argument +Style/AlignParameters: + Enabled: false + +Style/CaseIndentation: + IndentWhenRelativeTo: end + +Style/ClassAndModuleChildren: + EnforcedStyle: nested + +# percent-x is allowed for multiline +Style/CommandLiteral: + EnforcedStyle: mixed + +# our current conditional style is established, clear and +# requiring users to change that now would be confusing. +Style/ConditionalAssignment: + Enabled: false + +Style/Documentation: + Enabled: false + +Style/EmptyLineBetweenDefs: + AllowAdjacentOneLineDefs: true + +# dashes in filenames are typical +Style/FileName: + Regex: !ruby/regexp /^[\w\@\-\+\.]+(\.rb)?$/ + +Style/GuardClause: + Enabled: false + +Style/HashSyntax: + EnforcedStyle: hash_rockets + +Style/IfUnlessModifier: + Enabled: false + +Style/IndentArray: + EnforcedStyle: special_inside_parentheses + +# only for numbers >= 1_000_000 +Style/NumericLiterals: + MinDigits: 7 + +# zero-prefixed octal literals are just too widely used (and mostly understood) +Style/NumericLiteralPrefix: + EnforcedOctalStyle: zero_only + +# consistency and readability when faced with string interpolation +Style/PercentLiteralDelimiters: + PreferredDelimiters: + '%': '()' + '%i': '()' + '%q': '()' + '%Q': '()' + '%r': '{}' + '%s': '()' + '%w': '[]' + '%W': '[]' + '%x': '()' + +# we prefer Perl-style regex back references +Style/PerlBackrefs: + Enabled: false + +Style/RaiseArgs: + EnforcedStyle: exploded + +# paths abound, easy escape +Style/RegexpLiteral: + EnforcedStyle: slashes + +# conflicts with DSL-style path concatenation with `/` +Style/SpaceAroundOperators: + Enabled: false + +# not a problem for typical shell users +Style/SpecialGlobalVars: + Enabled: false + +# ruby style guide favorite +Style/StringLiterals: + EnforcedStyle: double_quotes + +# consistency with above +Style/StringLiteralsInInterpolation: + EnforcedStyle: double_quotes + +# TODO: enforce when rubocop has shipped this +# https://github.com/bbatsov/rubocop/pull/3513 +Style/TernaryParentheses: + Enabled: false + +# makes diffs nicer +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/.rubocop_rules.yml b/Library/.rubocop_rules.yml deleted file mode 100644 index 638989291..000000000 --- a/Library/.rubocop_rules.yml +++ /dev/null @@ -1,258 +0,0 @@ -Metrics/AbcSize: - Enabled: false - -Metrics/ClassLength: - Enabled: false - -Metrics/CyclomaticComplexity: - Enabled: false - -Metrics/LineLength: - Enabled: false - -Metrics/MethodLength: - Enabled: false - -Metrics/ModuleLength: - CountComments: false - Exclude: - - 'Homebrew/cask/lib/hbc/locations.rb' - - 'Homebrew/cask/lib/hbc/macos.rb' - - 'Homebrew/cask/lib/hbc/utils.rb' - -Metrics/PerceivedComplexity: - Enabled: false - -# favor parens-less DSL-style arguments -Lint/AmbiguousOperator: - Enabled: false - -Lint/AmbiguousRegexpLiteral: - Enabled: false - -Lint/AssignmentInCondition: - Enabled: false - -Lint/EndAlignment: - AlignWith: variable - -# `formula do` uses nested method definitions -Lint/NestedMethodDefinition: - Exclude: - - 'Homebrew/test/**/*' - -Lint/ParenthesesAsGroupedExpression: - Enabled: false - -Style/Alias: - EnforcedStyle: prefer_alias - -Style/AlignHash: - Enabled: false - -# `system` is a special case and aligns on second argument -Style/AlignParameters: - Enabled: false - -Style/BarePercentLiterals: - Exclude: - - 'Taps/**/*' - EnforcedStyle: percent_q - -Style/BlockDelimiters: - EnforcedStyle: semantic - Exclude: - - 'Taps/**/*' - 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/CaseIndentation: - IndentWhenRelativeTo: end - -Style/ClassAndModuleChildren: - EnforcedStyle: nested - -# percent-x is allowed for multiline -Style/CommandLiteral: - EnforcedStyle: mixed - -# our current conditional style is established, clear and -# requiring users to change that now would be confusing. -Style/ConditionalAssignment: - Enabled: false - -Style/Documentation: - Enabled: false - -Style/EmptyLineBetweenDefs: - AllowAdjacentOneLineDefs: true - -# dashes in filenames are typical -Style/FileName: - Regex: !ruby/regexp /^[\w\@\-\+\.]+(\.rb)?$/ - -# counterproductive in formulas, notably within the install method -Style/GuardClause: - Exclude: - - 'Taps/**/*' - -# depends_on foo: :bar looks rubbish -Style/HashSyntax: - EnforcedStyle: ruby19_no_mixed_keys - Exclude: - - 'Taps/**/*' - -Style/IfUnlessModifier: - Exclude: - - 'Taps/**/*' - -Style/IndentArray: - EnforcedStyle: special_inside_parentheses - -# we won't change backward compatible method names -Style/MethodName: - Exclude: - - 'Homebrew/compat/**/*' - -# only for numbers >= 1_000_000 -Style/NumericLiterals: - MinDigits: 7 - -# zero-prefixed octal literals are just too widely used (and mostly understood) -Style/NumericLiteralPrefix: - EnforcedOctalStyle: zero_only - -# consistency and readability when faced with string interpolation -Style/PercentLiteralDelimiters: - PreferredDelimiters: - '%': '()' - '%i': '()' - '%q': '()' - '%Q': '()' - '%r': '{}' - '%s': '()' - '%w': '[]' - '%W': '[]' - '%x': '()' - -# we prefer Perl-style regex back references -Style/PerlBackrefs: - Enabled: false - -# we won't change backward compatible predicate names -Style/PredicateName: - Exclude: - - 'Homebrew/compat/**/*' - NameWhitelist: is_32_bit?, is_64_bit? - -Style/RaiseArgs: - EnforcedStyle: exploded - -# paths abound, easy escape -Style/RegexpLiteral: - EnforcedStyle: slashes - -# conflicts with DSL-style path concatenation with `/` -Style/SpaceAroundOperators: - Enabled: false - -# not a problem for typical shell users -Style/SpecialGlobalVars: - Enabled: false - -# ruby style guide favorite -Style/StringLiterals: - EnforcedStyle: double_quotes - -# consistency with above -Style/StringLiteralsInInterpolation: - EnforcedStyle: double_quotes - -# TODO: enforce when rubocop has shipped this -# https://github.com/bbatsov/rubocop/pull/3513 -Style/TernaryParentheses: - Enabled: false - -# makes diffs nicer -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/.rubocop_todo.yml b/Library/.rubocop_todo.yml deleted file mode 100644 index d3be22eb5..000000000 --- a/Library/.rubocop_todo.yml +++ /dev/null @@ -1,231 +0,0 @@ -# This configuration was generated by -# `rubocop --auto-gen-config --exclude-limit 100` -# on 2016-09-25 02:39:38 +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: - - 'Homebrew/cmd/install.rb' - - 'Homebrew/cmd/reinstall.rb' - - 'Homebrew/cmd/tap.rb' - - 'Homebrew/cmd/update-report.rb' - - 'Homebrew/cmd/upgrade.rb' - - 'Homebrew/cmd/uses.rb' - - 'Homebrew/descriptions.rb' - - 'Homebrew/diagnostic.rb' - - 'Homebrew/extend/ENV/super.rb' - - 'Homebrew/extend/pathname.rb' - - 'Homebrew/formula.rb' - - 'Homebrew/formula_versions.rb' - - 'Homebrew/test/test_ENV.rb' - -# Offense count: 3 -Lint/IneffectiveAccessModifier: - Exclude: - - 'Homebrew/formula.rb' - - 'Homebrew/version.rb' - -# Offense count: 1 -Lint/Loop: - Exclude: - - 'Homebrew/patch.rb' - -# Offense count: 1 -Lint/NestedMethodDefinition: - Exclude: - - 'Homebrew/test/**/*' - - 'Homebrew/dev-cmd/bottle.rb' - -# Offense count: 28 -Lint/RescueException: - Exclude: - - 'Homebrew/brew.rb' - - 'Homebrew/build.rb' - - 'Homebrew/cmd/fetch.rb' - - 'Homebrew/cmd/reinstall.rb' - - 'Homebrew/cmd/update-report.rb' - - 'Homebrew/debrew.rb' - - 'Homebrew/dev-cmd/pull.rb' - - 'Homebrew/dev-cmd/test.rb' - - 'Homebrew/formula.rb' - - 'Homebrew/formula_installer.rb' - - 'Homebrew/migrator.rb' - - 'Homebrew/postinstall.rb' - - 'Homebrew/readall.rb' - - 'Homebrew/test.rb' - - 'Homebrew/test/test_ENV.rb' - - 'Homebrew/utils/fork.rb' - -# Offense count: 1 -Lint/ShadowedException: - Exclude: - - 'Homebrew/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: 9 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: percent_q, bare_percent -Style/BarePercentLiterals: - Exclude: - - 'Taps/**/*' - - 'Homebrew/dev-cmd/audit.rb' - - 'Homebrew/test/test_diagnostic.rb' - - 'Homebrew/test/test_exceptions.rb' - - 'Homebrew/test/test_integration_cmds.rb' - - 'Homebrew/test/test_patch.rb' - - 'Homebrew/test/test_string.rb' - -# Offense count: 136 -# 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: - - 'Taps/**/*' - - 'Homebrew/caveats.rb' - - 'Homebrew/cleaner.rb' - - 'Homebrew/cleanup.rb' - - 'Homebrew/cmd/deps.rb' - - 'Homebrew/cmd/desc.rb' - - 'Homebrew/cmd/fetch.rb' - - 'Homebrew/cmd/help.rb' - - 'Homebrew/cmd/info.rb' - - 'Homebrew/cmd/linkapps.rb' - - 'Homebrew/cmd/list.rb' - - 'Homebrew/cmd/outdated.rb' - - 'Homebrew/cmd/reinstall.rb' - - 'Homebrew/cmd/search.rb' - - 'Homebrew/cmd/tap-info.rb' - - 'Homebrew/cmd/unlinkapps.rb' - - 'Homebrew/cmd/update-report.rb' - - 'Homebrew/cmd/upgrade.rb' - - 'Homebrew/cmd/uses.rb' - - 'Homebrew/compilers.rb' - - 'Homebrew/debrew.rb' - - 'Homebrew/descriptions.rb' - - 'Homebrew/dev-cmd/aspell-dictionaries.rb' - - 'Homebrew/dev-cmd/audit.rb' - - 'Homebrew/dev-cmd/bottle.rb' - - 'Homebrew/dev-cmd/edit.rb' - - 'Homebrew/dev-cmd/man.rb' - - 'Homebrew/diagnostic.rb' - - 'Homebrew/exceptions.rb' - - 'Homebrew/extend/ARGV.rb' - - 'Homebrew/extend/ENV/shared.rb' - - 'Homebrew/extend/ENV/std.rb' - - 'Homebrew/extend/fileutils.rb' - - 'Homebrew/extend/os/mac/formula_cellar_checks.rb' - - 'Homebrew/extend/pathname.rb' - - 'Homebrew/formula.rb' - - 'Homebrew/formula_assertions.rb' - - 'Homebrew/formula_cellar_checks.rb' - - 'Homebrew/formula_installer.rb' - - 'Homebrew/formulary.rb' - - 'Homebrew/global.rb' - - 'Homebrew/keg.rb' - - 'Homebrew/language/haskell.rb' - - 'Homebrew/language/node.rb' - - 'Homebrew/language/python.rb' - - 'Homebrew/migrator.rb' - - 'Homebrew/os/mac/linkage_checker.rb' - - 'Homebrew/os/mac/xquartz.rb' - - 'Homebrew/patch.rb' - - 'Homebrew/readall.rb' - - 'Homebrew/software_spec.rb' - - 'Homebrew/tap.rb' - - 'Homebrew/test/lib/config.rb' - - 'Homebrew/test/test_ARGV.rb' - - 'Homebrew/test/test_cleanup.rb' - - 'Homebrew/test/test_cmd_audit.rb' - - 'Homebrew/test/test_dependency_collector.rb' - - 'Homebrew/test/test_formula_installer.rb' - - 'Homebrew/test/test_formula_installer_bottle.rb' - - 'Homebrew/test/test_formulary.rb' - - 'Homebrew/test/test_gpg.rb' - - 'Homebrew/test/test_integration_cmds.rb' - - 'Homebrew/test/test_migrator.rb' - - 'Homebrew/test/test_pathname.rb' - - 'Homebrew/test/test_tap.rb' - - 'Homebrew/test/test_utils.rb' - - 'Homebrew/test/testing_env.rb' - - 'Homebrew/utils.rb' - - 'Homebrew/utils/github.rb' - -# Offense count: 7 -Style/ClassVars: - Exclude: - - 'Homebrew/dev-cmd/audit.rb' - - 'Homebrew/formula_installer.rb' - - 'Homebrew/test/testing_env.rb' - - 'Homebrew/utils.rb' - -# Offense count: 13 -# Configuration parameters: AllowedVariables. -Style/GlobalVars: - Exclude: - - 'Homebrew/diagnostic.rb' - - 'Homebrew/utils.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: SupportedStyles, IndentationWidth. -# SupportedStyles: special_inside_parentheses, consistent, align_brackets -Style/IndentArray: - EnforcedStyle: special_inside_parentheses - -# Offense count: 5 -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: module_function, extend_self -Style/ModuleFunction: - Exclude: - - 'Homebrew/global.rb' - - 'Homebrew/os/mac/xcode.rb' - - 'Homebrew/os/mac/xquartz.rb' - -# Offense count: 8 -Style/MultilineBlockChain: - Exclude: - - 'Homebrew/cmd/search.rb' - - 'Homebrew/dev-cmd/aspell-dictionaries.rb' - - 'Homebrew/dev-cmd/audit.rb' - - 'Homebrew/dev-cmd/man.rb' - - 'Homebrew/diagnostic.rb' - - 'Homebrew/test/test_patching.rb' - -# Offense count: 4 -# Cop supports --auto-correct. -Style/MutableConstant: - Exclude: - - 'Homebrew/dependency_collector.rb' - - 'Homebrew/formulary.rb' - - 'Homebrew/tab.rb' - - 'Homebrew/tap.rb' - -# Offense count: 9 -# Offense count: 8 -Style/OpMethod: - Exclude: - - 'Homebrew/dependencies.rb' - - 'Homebrew/install_renamed.rb' - - 'Homebrew/options.rb' 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/blacklist.rb b/Library/Homebrew/blacklist.rb index 4312d0bf3..1c79da159 100644 --- a/Library/Homebrew/blacklist.rb +++ b/Library/Homebrew/blacklist.rb @@ -16,7 +16,7 @@ def blacklisted?(name) Homebrew provides pip via: `brew install python`. However you will then have two Pythons installed on your Mac, so alternatively you can install pip via the instructions at: - https://pip.readthedocs.io/en/stable/installing/ + #{Formatter.url("https://pip.readthedocs.io/en/stable/installing/")} EOS when "pil" then <<-EOS.undent Instead of PIL, consider `pip install pillow` or `brew install Homebrew/python/pillow`. @@ -24,7 +24,7 @@ def blacklisted?(name) when "macruby" then <<-EOS.undent MacRuby is not packaged and is on an indefinite development hiatus. You can read more about it at: - https://github.com/MacRuby/MacRuby + #{Formatter.url("https://github.com/MacRuby/MacRuby")} EOS when /(lib)?lzma/ "lzma is now part of the xz formula." @@ -50,7 +50,7 @@ def blacklisted?(name) To install Clojure you should install Leiningen: brew install leiningen and then follow the tutorial: - https://github.com/technomancy/leiningen/blob/stable/doc/TUTORIAL.md + #{Formatter.url("https://github.com/technomancy/leiningen/blob/stable/doc/TUTORIAL.md")} EOS when "osmium" then <<-EOS.undent The creator of Osmium requests that it not be packaged and that people @@ -65,8 +65,8 @@ def blacklisted?(name) brew install typesafe-activator You can read more about this change at: - https://www.playframework.com/documentation/2.3.x/Migration23 - https://www.playframework.com/documentation/2.3.x/Highlights23 + #{Formatter.url("https://www.playframework.com/documentation/2.3.x/Migration23")} + #{Formatter.url("https://www.playframework.com/documentation/2.3.x/Highlights23")} EOS when "haskell-platform" then <<-EOS.undent We no longer package haskell-platform. Consider installing ghc diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index f961a82f6..985a93de9 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -144,8 +144,8 @@ rescue Exception => e Utils::Analytics.report_exception(e) onoe e if internal_cmd && defined?(OS::ISSUES_URL) - $stderr.puts "#{Tty.white}Please report this bug:" - $stderr.puts " #{Tty.em}#{OS::ISSUES_URL}#{Tty.reset}" + $stderr.puts "#{Tty.bold}Please report this bug:#{Tty.reset}" + $stderr.puts " #{Formatter.url(OS::ISSUES_URL)}" end $stderr.puts e.backtrace exit 1 diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index 22ebb87ed..1ccd8832a 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -4,6 +4,10 @@ then HOMEBREW_VERSION=">1.0.0 (no git repository)" fi +# A depth of 1 means this command was directly invoked by a user. +# Higher depths mean this command was invoked by another Homebrew command. +export HOMEBREW_COMMAND_DEPTH=$((HOMEBREW_COMMAND_DEPTH + 1)) + onoe() { if [[ -t 2 ]] # check whether stderr is a tty. then diff --git a/Library/Homebrew/cask/lib/hbc/artifact/moved.rb b/Library/Homebrew/cask/lib/hbc/artifact/moved.rb index 6095887e3..22124005c 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/moved.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/moved.rb @@ -79,13 +79,10 @@ module Hbc load_specification artifact_spec if target.exist? - target_abv = " (#{target.abv})" + "#{printable_target} (#{target.abv})" else - warning = "Missing #{self.class.artifact_english_name}" - warning = "#{Tty.red}#{warning}#{Tty.reset}: " + Formatter.error(printable_target, label: "Missing #{self.class.artifact_english_name}") end - - "#{warning}#{printable_target}#{target_abv}" end end end diff --git a/Library/Homebrew/cask/lib/hbc/artifact/symlinked.rb b/Library/Homebrew/cask/lib/hbc/artifact/symlinked.rb index 3ab45cccc..46dd42322 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/symlinked.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/symlinked.rb @@ -57,12 +57,17 @@ module Hbc def summarize_artifact(artifact_spec) load_specification artifact_spec - return unless self.class.islink?(target) - - link_description = "#{Tty.red}Broken Link#{Tty.reset}: " unless target.exist? - target_readlink_abv = " (#{target.readlink.abv})" if target.readlink.exist? + if self.class.islink?(target) && target.exist? && target.readlink.exist? + "#{printable_target} -> #{target.readlink} (#{target.readlink.abv})" + else + string = if self.class.islink?(target) + "#{printable_target} -> #{target.readlink}" + else + printable_target + end - "#{link_description}#{printable_target} -> #{target.readlink}#{target_readlink_abv}" + Formatter.error(string, label: "Broken Link") + end end end end diff --git a/Library/Homebrew/cask/lib/hbc/checkable.rb b/Library/Homebrew/cask/lib/hbc/checkable.rb index 42c47ea78..03f052629 100644 --- a/Library/Homebrew/cask/lib/hbc/checkable.rb +++ b/Library/Homebrew/cask/lib/hbc/checkable.rb @@ -28,11 +28,11 @@ module Hbc def result if errors? - "#{Tty.red}failed#{Tty.reset}" + Formatter.error("failed") elsif warnings? - "#{Tty.yellow}warning#{Tty.reset}" + Formatter.warning("warning") else - "#{Tty.green}passed#{Tty.reset}" + Formatter.success("passed") end end @@ -40,11 +40,11 @@ module Hbc summary = ["#{summary_header}: #{result}"] errors.each do |error| - summary << " #{Tty.red}-#{Tty.reset} #{error}" + summary << " #{Formatter.error("-")} #{error}" end warnings.each do |warning| - summary << " #{Tty.yellow}-#{Tty.reset} #{warning}" + summary << " #{Formatter.warning("-")} #{warning}" end summary.join("\n") diff --git a/Library/Homebrew/cask/lib/hbc/cli/doctor.rb b/Library/Homebrew/cask/lib/hbc/cli/doctor.rb index 34f000b29..e36999200 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/doctor.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/doctor.rb @@ -122,11 +122,11 @@ module Hbc end def self.notfound_string - "#{Tty.red}Not Found - Unknown Error#{Tty.reset}" + Formatter.error("Not Found - Unknown Error") end def self.error_string(string = "Error") - "#{Tty.red}(#{string})#{Tty.reset}" + Formatter.error("(#{string})") end def self.render_with_none(string) diff --git a/Library/Homebrew/cask/lib/hbc/cli/info.rb b/Library/Homebrew/cask/lib/hbc/cli/info.rb index 7fbdff3eb..0957ba4fd 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/info.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/info.rb @@ -18,16 +18,16 @@ module Hbc def self.info(cask) puts "#{cask.token}: #{cask.version}" - puts formatted_url(cask.homepage) if cask.homepage + puts Formatter.url(cask.homepage) if cask.homepage installation_info(cask) - puts "From: #{formatted_url(github_info(cask))}" if github_info(cask) + puts "From: #{Formatter.url(github_info(cask))}" if github_info(cask) name_info(cask) artifact_info(cask) Installer.print_caveats(cask) end def self.formatted_url(url) - "#{Tty.em}#{url}#{Tty.reset}" + "#{Tty.underline}#{url}#{Tty.reset}" end def self.installation_info(cask) @@ -37,7 +37,7 @@ module Hbc puts versioned_staged_path.to_s .concat(" (") - .concat(versioned_staged_path.exist? ? versioned_staged_path.abv : "#{Tty.red}does not exist#{Tty.reset}") + .concat(versioned_staged_path.exist? ? versioned_staged_path.abv : Formatter.error("does not exist")) .concat(")") end else @@ -47,7 +47,7 @@ module Hbc def self.name_info(cask) ohai cask.name.size > 1 ? "Names" : "Name" - puts cask.name.empty? ? "#{Tty.red}None#{Tty.reset}" : cask.name + puts cask.name.empty? ? Formatter.error("None") : cask.name end def self.github_info(cask) diff --git a/Library/Homebrew/cask/lib/hbc/cli/style.rb b/Library/Homebrew/cask/lib/hbc/cli/style.rb index 66117da8b..bb179fb0c 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/style.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/style.rb @@ -30,7 +30,7 @@ module Hbc begin Homebrew.install_gem_setup_path! "rubocop-cask", RUBOCOP_CASK_VERSION, "rubocop" rescue SystemExit - raise CaskError, $stderr.string.chomp.sub("#{Tty.red}Error#{Tty.reset}: ", "") + raise CaskError, Tty.strip_ansi($stderr.string).chomp.sub(/\AError: /, "") end end end diff --git a/Library/Homebrew/cask/lib/hbc/dsl/caveats.rb b/Library/Homebrew/cask/lib/hbc/dsl/caveats.rb index 5efd7d562..9dd9abab1 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl/caveats.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl/caveats.rb @@ -102,12 +102,12 @@ module Hbc A report has been made to Apple about this app. Their certificate will hopefully be revoked. See the public report at - https://openradar.appspot.com/#{radar_number} + #{Formatter.url("https://openradar.appspot.com/#{radar_number}")} If this report is accurate, please duplicate it at - https://bugreport.apple.com/ + #{Formatter.url("https://bugreport.apple.com/")} If this report is a mistake, please let us know by opening an issue at - https://github.com/caskroom/homebrew-cask/issues/new + #{Formatter.url("https://github.com/caskroom/homebrew-cask/issues/new")} EOS end diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index f0cc0d1a9..4d29acb75 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -87,7 +87,7 @@ module Hbc s = if MacOS.version >= :lion && !ENV["HOMEBREW_NO_EMOJI"] (ENV["HOMEBREW_INSTALL_BADGE"] || "\xf0\x9f\x8d\xba") + " " else - "#{Tty.blue}==>#{Tty.reset} #{Tty.white}Success!#{Tty.reset} " + Formatter.headline("Success! ", color: :blue) end s << "#{@cask} was successfully installed!" end diff --git a/Library/Homebrew/cask/lib/hbc/utils.rb b/Library/Homebrew/cask/lib/hbc/utils.rb index 9159544a6..d42d78ef7 100644 --- a/Library/Homebrew/cask/lib/hbc/utils.rb +++ b/Library/Homebrew/cask/lib/hbc/utils.rb @@ -32,12 +32,7 @@ end def odebug(title, *sput) return unless Hbc.respond_to?(:debug) return unless Hbc.debug - - width = Tty.width * 4 - 6 - if $stdout.tty? && title.to_s.length > width - title = title.to_s[0, width - 3] + "..." - end - puts "#{Tty.magenta}==>#{Tty.reset} #{Tty.white}#{title}#{Tty.reset}" + puts Formatter.headline(title, color: :magenta) puts sput unless sput.empty? end @@ -151,12 +146,10 @@ module Hbc def self.error_message_with_suggestions <<-EOS.undent Most likely, this means you have an outdated version of Homebrew-Cask. Please run: + #{UPDATE_CMD} - #{Tty.green}#{UPDATE_CMD} - - #{Tty.reset}If this doesn’t fix the problem, please report this bug: - - #{Tty.em}#{ISSUES_URL}#{Tty.reset} + If this doesn’t fix the problem, please report this bug: + #{Formatter.url(ISSUES_URL)} EOS end diff --git a/Library/Homebrew/cmd/doctor.rb b/Library/Homebrew/cmd/doctor.rb index 89f32dc25..0fcd3a74d 100644 --- a/Library/Homebrew/cmd/doctor.rb +++ b/Library/Homebrew/cmd/doctor.rb @@ -42,9 +42,9 @@ module Homebrew next if out.nil? || out.empty? if first_warning $stderr.puts <<-EOS.undent - #{Tty.white}Please note that these warnings are just used to help the Homebrew maintainers - with debugging if you file an issue. If everything you use Homebrew for is - working fine: please don't worry and just ignore them. Thanks!#{Tty.reset} + #{Tty.bold}Please note that these warnings are just used to help the Homebrew maintainers + with debugging if you file an issue. If everything you use Homebrew for is + working fine: please don't worry and just ignore them. Thanks!#{Tty.reset} EOS end diff --git a/Library/Homebrew/cmd/help.rb b/Library/Homebrew/cmd/help.rb index 200e68738..bfcb6838d 100644 --- a/Library/Homebrew/cmd/help.rb +++ b/Library/Homebrew/cmd/help.rb @@ -81,9 +81,10 @@ module Homebrew else help_lines.map do |line| line.slice(2..-1) - .sub(/^ \* /, "#{Tty.highlight}brew#{Tty.reset} ") - .gsub(/`(.*?)`/, "#{Tty.highlight}\\1#{Tty.reset}") - .gsub(/<(.*?)>/, "#{Tty.em}\\1#{Tty.reset}") + .sub(/^ \* /, "#{Tty.bold}brew#{Tty.reset} ") + .gsub(/`(.*?)`/, "#{Tty.bold}\\1#{Tty.reset}") + .gsub(%r{<([^\s]+?://[^\s]+?)>}) { |url| Formatter.url(url) } + .gsub(/<(.*?)>/, "#{Tty.underline}\\1#{Tty.reset}") .gsub("@hide_from_man_page", "") end.join.strip end diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb index 6f242039c..2cfb89ea5 100644 --- a/Library/Homebrew/cmd/info.rb +++ b/Library/Homebrew/cmd/info.rb @@ -117,7 +117,7 @@ module Homebrew puts "#{f.full_name}: #{specs * ", "}#{" [#{attrs * ", "}]" unless attrs.empty?}" puts f.desc if f.desc - puts "#{Tty.em}#{f.homepage}#{Tty.reset}" if f.homepage + puts Formatter.url(f.homepage) if f.homepage conflicts = f.conflicts.map(&:name).sort! puts "Conflicts with: #{conflicts*", "}" unless conflicts.empty? @@ -133,7 +133,7 @@ module Homebrew end end - puts "From: #{Tty.em}#{github_info(f)}#{Tty.reset}" + puts "From: #{Formatter.url(github_info(f))}" unless f.deps.empty? ohai "Dependencies" diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 8a8323252..402a159db 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -199,16 +199,6 @@ module Homebrew puts_columns(taps_search_results) puts "To install one of them, run (for example):\n brew install #{taps_search_results.first}" end - - # If they haven't updated in 48 hours (172800 seconds), that - # might explain the error - master = HOMEBREW_REPOSITORY/".git/refs/heads/master" - return unless master.exist? && (Time.now.to_i - File.mtime(master).to_i) > 172800 - ohai "You haven't updated Homebrew in a while." - puts <<-EOS.undent - A formula for #{e.name} might have been added recently. - Run `brew update` to get the latest Homebrew updates! - EOS end end end 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/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb index 18f2f370c..f97191bda 100644 --- a/Library/Homebrew/cmd/update-report.rb +++ b/Library/Homebrew/cmd/update-report.rb @@ -282,13 +282,13 @@ module Homebrew EOS rescue => e ofail <<-EOS.undent - #{Tty.white}Failed to migrate HOMEBREW_REPOSITORY to #{new_homebrew_repository}! + #{Tty.bold}Failed to migrate HOMEBREW_REPOSITORY to #{new_homebrew_repository}!#{Tty.reset} The error was: #{e} Please try to resolve this error yourself and then run `brew update` again to complete the migration. If you need help please +1 an existing error or comment with your new error in issue: - #{Tty.em}https://github.com/Homebrew/brew/issues/987#{Tty.reset} + #{Formatter.url("https://github.com/Homebrew/brew/issues/987")} EOS $stderr.puts e.backtrace end diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index 5e534078d..f2c3799ab 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -23,6 +23,14 @@ module Homebrew Homebrew.perform_preinstall_checks + if ARGV.include?("--all") + opoo <<-EOS.undent + We decided to not change the behaviour of `brew upgrade` so + `brew upgrade --all` is equivalent to `brew upgrade` without any other + arguments (so the `--all` is a no-op and can be removed). + EOS + end + if ARGV.named.empty? outdated = Formula.installed.select do |f| f.outdated?(fetch_head: ARGV.fetch_head?) diff --git a/Library/Homebrew/compat.rb b/Library/Homebrew/compat.rb index eabc7dfa0..98624aebd 100644 --- a/Library/Homebrew/compat.rb +++ b/Library/Homebrew/compat.rb @@ -15,3 +15,4 @@ require "compat/dependency_collector" require "compat/language/haskell" require "compat/xcode" require "compat/software_spec" +require "compat/utils" diff --git a/Library/Homebrew/compat/utils.rb b/Library/Homebrew/compat/utils.rb index 7de5e85c3..7b529f04e 100644 --- a/Library/Homebrew/compat/utils.rb +++ b/Library/Homebrew/compat/utils.rb @@ -8,3 +8,11 @@ def shell_profile else "~/.bash_profile" end end + +module Tty + module_function + + def white + reset.bold + end +end diff --git a/Library/Homebrew/debrew.rb b/Library/Homebrew/debrew.rb index 1c5047a8c..668a0b4d2 100644 --- a/Library/Homebrew/debrew.rb +++ b/Library/Homebrew/debrew.rb @@ -111,7 +111,7 @@ module Debrew begin puts e.backtrace.first.to_s - puts "#{Tty.red}#{e.class.name}#{Tty.reset}: #{e}" + puts Formatter.error(e, label: e.class.name) loop do Menu.choose do |menu| diff --git a/Library/Homebrew/descriptions.rb b/Library/Homebrew/descriptions.rb index 0ef4316d3..cc690c050 100644 --- a/Library/Homebrew/descriptions.rb +++ b/Library/Homebrew/descriptions.rb @@ -119,12 +119,12 @@ class Descriptions # Take search results -- a hash mapping formula names to descriptions -- and # print them. def print - blank = "#{Tty.yellow}[no description]#{Tty.reset}" + blank = Formatter.warning("[no description]") @descriptions.keys.sort.each do |full_name| short_name = short_names[full_name] printed_name = short_name_counts[short_name] == 1 ? short_name : full_name description = @descriptions[full_name] || blank - puts "#{Tty.white}#{printed_name}:#{Tty.reset} #{description}" + puts "#{Tty.bold}#{printed_name}:#{Tty.reset} #{description}" end end diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index b2aa3b2c5..b62af1044 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 @@ -54,7 +54,7 @@ module Homebrew return if @put_filenames.include? filename - puts "#{Tty.red}#{filename}#{Tty.reset}" + puts Formatter.error(filename.to_s) @put_filenames << filename end @@ -68,9 +68,9 @@ 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}" + puts " #{Tty.bold}-->#{Tty.reset} links to #{lib}" end end @@ -91,9 +91,9 @@ 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}" + puts " #{Tty.bold}-->#{Tty.reset} match '#{match}' at offset #{Tty.bold}0x#{offset}#{Tty.reset}" end if text_matches.size > MAXIMUM_STRING_MATCHES diff --git a/Library/Homebrew/dev-cmd/update-test.rb b/Library/Homebrew/dev-cmd/update-test.rb index 18980b691..8d0391f66 100644 --- a/Library/Homebrew/dev-cmd/update-test.rb +++ b/Library/Homebrew/dev-cmd/update-test.rb @@ -8,11 +8,16 @@ #: If `--before=<date>` is passed, use the commit at `<date>` as the #: start commit. #: +#: If `--to-tag` is passed, set HOMEBREW_UPDATE_TO_TAG to test updating +#: between tags. +#: #: If `--keep-tmp` is passed, retain the temporary directory containing #: the new repository clone. module Homebrew def update_test + ENV["HOMEBREW_UPDATE_TO_TAG"] = "1" if ARGV.include?("--to-tag") + cd HOMEBREW_REPOSITORY start_commit = if commit = ARGV.value("commit") commit diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index ca8ade9ff..6546714e8 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -473,7 +473,7 @@ module Homebrew If you have trouble downloading packages with Homebrew, then maybe this is the problem? If the following command doesn't work, then try removing your curlrc: - curl https://github.com + curl #{Formatter.url("https://github.com")} EOS end @@ -610,7 +610,7 @@ module Homebrew Setting DYLD_INSERT_LIBRARIES can cause Go builds to fail. Having this set is common if you use this software: - http://asepsis.binaryage.com/ + #{Formatter.url("http://asepsis.binaryage.com/")} EOS end @@ -752,7 +752,7 @@ module Homebrew Without a correctly configured origin, Homebrew won't update properly. You can solve this by adding the Homebrew remote: cd #{HOMEBREW_REPOSITORY} - git remote add origin https://github.com/Homebrew/brew.git + git remote add origin #{Formatter.url("https://github.com/Homebrew/brew.git")} EOS elsif origin !~ %r{Homebrew/brew(\.git)?$} <<-EOS.undent @@ -764,7 +764,7 @@ module Homebrew Unless you have compelling reasons, consider setting the origin remote to point at the main repository, located at: - https://github.com/Homebrew/brew.git + #{Formatter.url("https://github.com/Homebrew/brew.git")} EOS end end @@ -956,8 +956,8 @@ module Homebrew <<-EOS.undent A .pydistutils.cfg file was found in $HOME, which may cause Python builds to fail. See: - https://bugs.python.org/issue6138 - https://bugs.python.org/issue4655 + #{Formatter.url("https://bugs.python.org/issue6138")} + #{Formatter.url("https://bugs.python.org/issue4655")} EOS end diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index 07658c6e7..e01a60c75 100644 --- a/Library/Homebrew/exceptions.rb +++ b/Library/Homebrew/exceptions.rb @@ -318,7 +318,7 @@ class BuildError < RuntimeError def dump if !ARGV.verbose? puts - puts "#{Tty.red}READ THIS#{Tty.reset}: #{Tty.em}#{OS::ISSUES_URL}#{Tty.reset}" + puts Formatter.error(Formatter.url(OS::ISSUES_URL), label: "READ THIS") if formula.tap case formula.tap.name when "homebrew/boneyard" @@ -327,7 +327,7 @@ class BuildError < RuntimeError else if issues_url = formula.tap.issues_url puts "If reporting this issue please do so at (not Homebrew/brew):" - puts " #{issues_url}" + puts " #{Formatter.url(issues_url)}" end end end diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 652f87ae3..09c11318e 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -214,7 +214,7 @@ class FormulaInstaller opoo "#{formula.full_name}: #{old_flag} was deprecated; using #{new_flag} instead!" end - oh1 "Installing #{Tty.green}#{formula.full_name}#{Tty.reset}" if show_header? + oh1 "Installing #{Formatter.identifier(formula.full_name)}" if show_header? if formula.tap && !formula.tap.private? options = [] @@ -426,7 +426,7 @@ class FormulaInstaller if deps.empty? && only_deps? puts "All dependencies for #{formula.full_name} are satisfied." elsif !deps.empty? - oh1 "Installing dependencies for #{formula.full_name}: #{Tty.green}#{deps.map(&:first)*", "}#{Tty.reset}", + oh1 "Installing dependencies for #{formula.full_name}: #{deps.map(&:first).map(&Formatter.method(:identifier)).join(", ")}", truncate: false deps.each { |dep, options| install_dependency(dep, options) } end @@ -476,7 +476,7 @@ class FormulaInstaller fi.verbose = verbose? && !quieter? fi.debug = debug? fi.prelude - oh1 "Installing #{formula.full_name} dependency: #{Tty.green}#{dep.name}#{Tty.reset}" + oh1 "Installing #{formula.full_name} dependency: #{Formatter.identifier(dep.name)}" fi.install fi.finish rescue Exception diff --git a/Library/Homebrew/migrator.rb b/Library/Homebrew/migrator.rb index 4f8cba1ce..fe480cd3b 100644 --- a/Library/Homebrew/migrator.rb +++ b/Library/Homebrew/migrator.rb @@ -153,7 +153,7 @@ class Migrator end begin - oh1 "Migrating #{Tty.green}#{oldname}#{Tty.white} to #{Tty.green}#{newname}#{Tty.reset}" + oh1 "Migrating #{Formatter.identifier(oldname)} to #{Formatter.identifier(newname)}" lock unlink_oldname move_to_new_directory @@ -200,7 +200,7 @@ class Migrator end def unlink_oldname - oh1 "Unlinking #{Tty.green}#{oldname}#{Tty.reset}" + oh1 "Unlinking #{Formatter.identifier(oldname)}" old_cellar.subdirs.each do |d| keg = Keg.new(d) keg.unlink @@ -208,7 +208,7 @@ class Migrator end def link_newname - oh1 "Linking #{Tty.green}#{newname}#{Tty.reset}" + oh1 "Linking #{Formatter.identifier(newname)}" new_keg = Keg.new(new_linked_keg_record) # If old_keg wasn't linked then we just optlink a keg. diff --git a/Library/Homebrew/requirements.rb b/Library/Homebrew/requirements.rb index 274ba5c9b..87b315cb7 100644 --- a/Library/Homebrew/requirements.rb +++ b/Library/Homebrew/requirements.rb @@ -44,7 +44,7 @@ class XcodeRequirement < Requirement EOS else message + <<-EOS.undent - Xcode can be installed from https://developer.apple.com/xcode/downloads/ + Xcode can be installed from #{Formatter.url("https://developer.apple.com/xcode/downloads/")} EOS end end diff --git a/Library/Homebrew/test/test_utils.rb b/Library/Homebrew/test/test_utils.rb index c88c0f416..a40a56775 100644 --- a/Library/Homebrew/test/test_utils.rb +++ b/Library/Homebrew/test/test_utils.rb @@ -5,8 +5,11 @@ require "utils/shell" class TtyTests < Homebrew::TestCase def test_strip_ansi - assert_equal "hello", - Tty.strip_ansi("\033\[36;7mhello\033\[0m") + assert_equal "hello", Tty.strip_ansi("\033\[36;7mhello\033\[0m") + end + + def test_width + assert_kind_of Integer, Tty.width end def test_truncate @@ -21,15 +24,26 @@ class TtyTests < Homebrew::TestCase def test_no_tty_formatting $stdout.stubs(:tty?).returns false - assert_nil Tty.blue - assert_nil Tty.white - assert_nil Tty.red - assert_nil Tty.green - assert_nil Tty.gray - assert_nil Tty.yellow - assert_nil Tty.reset - assert_nil Tty.em - assert_nil Tty.highlight + assert_equal "", Tty.to_s + assert_equal "", Tty.red.to_s + assert_equal "", Tty.green.to_s + assert_equal "", Tty.yellow.to_s + assert_equal "", Tty.blue.to_s + assert_equal "", Tty.magenta.to_s + assert_equal "", Tty.cyan.to_s + assert_equal "", Tty.default.to_s + end + + def test_formatting + $stdout.stubs(:tty?).returns(true) + assert_equal "", Tty.to_s + assert_equal "\033[31m", Tty.red.to_s + assert_equal "\033[32m", Tty.green.to_s + assert_equal "\033[33m", Tty.yellow.to_s + assert_equal "\033[34m", Tty.blue.to_s + assert_equal "\033[35m", Tty.magenta.to_s + assert_equal "\033[36m", Tty.cyan.to_s + assert_equal "\033[39m", Tty.default.to_s end end diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 58083fe1b..8d91c15c0 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -1,6 +1,7 @@ require "pathname" require "emoji" require "exceptions" +require "utils/formatter" require "utils/hash" require "utils/json" require "utils/inreplace" @@ -10,85 +11,11 @@ require "utils/git" require "utils/analytics" require "utils/github" require "utils/curl" - -class Tty - class << self - def strip_ansi(string) - string.gsub(/\033\[\d+(;\d+)*m/, "") - end - - def blue - bold 34 - end - - def white - bold 39 - end - - def magenta - bold 35 - end - - def red - underline 31 - end - - def yellow - underline 33 - end - - def reset - escape 0 - end - - def em - underline 39 - end - - def green - bold 32 - end - - def gray - bold 30 - end - - def highlight - bold 39 - end - - def width - `/usr/bin/tput cols`.strip.to_i - end - - def truncate(str) - w = width - w > 10 ? str.to_s[0, w - 4] : str - end - - private - - def color(n) - escape "0;#{n}" - end - - def bold(n) - escape "1;#{n}" - end - - def underline(n) - escape "4;#{n}" - end - - def escape(n) - "\033[#{n}m" if $stdout.tty? - end - end -end +require "utils/tty" def ohai(title, *sput) title = Tty.truncate(title) if $stdout.tty? && !ARGV.verbose? - puts "#{Tty.blue}==>#{Tty.white} #{title}#{Tty.reset}" + puts Formatter.headline(title, color: :blue) puts sput end @@ -96,16 +23,16 @@ def oh1(title, options = {}) if $stdout.tty? && !ARGV.verbose? && options.fetch(:truncate, :auto) == :auto title = Tty.truncate(title) end - puts "#{Tty.green}==>#{Tty.white} #{title}#{Tty.reset}" + puts Formatter.headline(title, color: :green) end # Print a warning (do this rarely) -def opoo(warning) - $stderr.puts "#{Tty.yellow}Warning#{Tty.reset}: #{warning}" +def opoo(message) + $stderr.puts Formatter.warning(message, label: "Warning") end -def onoe(error) - $stderr.puts "#{Tty.red}Error#{Tty.reset}: #{error}" +def onoe(message) + $stderr.puts Formatter.error(message, label: "Error") end def ofail(error) @@ -171,9 +98,9 @@ def pretty_installed(f) if !$stdout.tty? f.to_s elsif Emoji.enabled? - "#{Tty.highlight}#{f} #{Tty.green}#{Emoji.tick}#{Tty.reset}" + "#{Tty.bold}#{f} #{Formatter.success(Emoji.tick)}#{Tty.reset}" else - "#{Tty.highlight}#{Tty.green}#{f} (installed)#{Tty.reset}" + Formatter.success("#{Tty.bold}#{f} (installed)#{Tty.reset}") end end @@ -181,9 +108,9 @@ def pretty_uninstalled(f) if !$stdout.tty? f.to_s elsif Emoji.enabled? - "#{f} #{Tty.red}#{Emoji.cross}#{Tty.reset}" + "#{Tty.bold}#{f} #{Formatter.error(Emoji.cross)}#{Tty.reset}" else - "#{Tty.red}#{f} (uninstalled)#{Tty.reset}" + Formatter.error("#{Tty.bold}#{f} (uninstalled)#{Tty.reset}") end end diff --git a/Library/Homebrew/utils/analytics.sh b/Library/Homebrew/utils/analytics.sh index 24839709e..19b341fdc 100644 --- a/Library/Homebrew/utils/analytics.sh +++ b/Library/Homebrew/utils/analytics.sh @@ -70,6 +70,9 @@ setup-analytics() { report-analytics-screenview-command() { [[ -n "$HOMEBREW_NO_ANALYTICS" || -n "$HOMEBREW_NO_ANALYTICS_THIS_RUN" ]] && return + # Don't report commands that are invoked as part of other commands. + [[ "$HOMEBREW_COMMAND_DEPTH" != 1 ]] && return + # Don't report non-official commands. if ! [[ "$HOMEBREW_COMMAND" = "bundle" || "$HOMEBREW_COMMAND" = "services" || diff --git a/Library/Homebrew/utils/formatter.rb b/Library/Homebrew/utils/formatter.rb new file mode 100644 index 000000000..cb4f041f4 --- /dev/null +++ b/Library/Homebrew/utils/formatter.rb @@ -0,0 +1,52 @@ +require "utils/tty" + +module Formatter + module_function + + def arrow(string, color: nil) + prefix("==>", string, color) + end + + def headline(string, color: nil) + arrow("#{Tty.bold}#{string}#{Tty.reset}", color: color) + end + + def identifier(string) + "#{Tty.green}#{string}#{Tty.reset}" + end + + def success(string, label: nil) + label(label, string, :green) + end + + def warning(string, label: nil) + label(label, string, :yellow) + end + + def error(string, label: nil) + label(label, string, :red) + end + + def url(string) + "#{Tty.underline}#{string}#{Tty.no_underline}" + end + + def label(label, string, color) + label = "#{label}:" unless label.nil? + prefix(label, string, color) + end + private_class_method :label + + def prefix(prefix, string, color) + if prefix.nil? && color.nil? + string + elsif prefix.nil? + "#{Tty.send(color)}#{string}#{Tty.reset}" + elsif color.nil? + "#{prefix} #{string}" + else + "#{Tty.send(color)}#{prefix}#{Tty.reset} #{string}" + end + end + private_class_method :prefix +end diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index b7ec538f9..5611f9aad 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -14,7 +14,7 @@ module GitHub super <<-EOS.undent GitHub API Error: #{error} Try again in #{pretty_ratelimit_reset(reset)}, or create a personal access token: - #{Tty.em}https://github.com/settings/tokens/new?scopes=&description=Homebrew#{Tty.reset} + #{Formatter.url("https://github.com/settings/tokens/new?scopes=&description=Homebrew")} and then set the token as: export HOMEBREW_GITHUB_API_TOKEN="your_new_token" EOS end @@ -30,7 +30,7 @@ module GitHub if ENV["HOMEBREW_GITHUB_API_TOKEN"] message << <<-EOS.undent HOMEBREW_GITHUB_API_TOKEN may be invalid or expired; check: - #{Tty.em}https://github.com/settings/tokens#{Tty.reset} + #{Formatter.url("https://github.com/settings/tokens")} EOS else message << <<-EOS.undent @@ -38,7 +38,7 @@ module GitHub Clear them with: printf "protocol=https\\nhost=github.com\\n" | git credential-osxkeychain erase Or create a personal access token: - #{Tty.em}https://github.com/settings/tokens/new?scopes=&description=Homebrew#{Tty.reset} + #{Formatter.url("https://github.com/settings/tokens/new?scopes=&description=Homebrew")} and then set the token as: export HOMEBREW_GITHUB_API_TOKEN="your_new_token" EOS end @@ -106,14 +106,14 @@ module GitHub onoe <<-EOS.undent Your macOS keychain GitHub credentials do not have sufficient scope! Scopes they have: #{credentials_scopes} - Create a personal access token: https://github.com/settings/tokens + Create a personal access token: #{Formatter.url("https://github.com/settings/tokens")} and then set HOMEBREW_GITHUB_API_TOKEN as the authentication method instead. EOS when :environment onoe <<-EOS.undent Your HOMEBREW_GITHUB_API_TOKEN does not have sufficient scope! Scopes it has: #{credentials_scopes} - Create a new personal access token: https://github.com/settings/tokens + Create a new personal access token: #{Formatter.url("https://github.com/settings/tokens")} and then set the new HOMEBREW_GITHUB_API_TOKEN as the authentication method instead. EOS end diff --git a/Library/Homebrew/utils/tty.rb b/Library/Homebrew/utils/tty.rb new file mode 100644 index 000000000..505165dc5 --- /dev/null +++ b/Library/Homebrew/utils/tty.rb @@ -0,0 +1,64 @@ +module Tty + module_function + + def strip_ansi(string) + string.gsub(/\033\[\d+(;\d+)*m/, "") + end + + def width + `/usr/bin/tput cols`.strip.to_i + end + + def truncate(string) + (w = width).zero? ? string.to_s : string.to_s[0, w - 4] + end + + COLOR_CODES = { + red: 31, + green: 32, + yellow: 33, + blue: 34, + magenta: 35, + cyan: 36, + default: 39, + }.freeze + + STYLE_CODES = { + reset: 0, + bold: 1, + italic: 3, + underline: 4, + strikethrough: 9, + no_underline: 24, + }.freeze + + CODES = COLOR_CODES.merge(STYLE_CODES).freeze + + def append_to_escape_sequence(code) + @escape_sequence ||= [] + @escape_sequence << code + self + end + + def current_escape_sequence + return "" if @escape_sequence.nil? + "\033[#{@escape_sequence.join(";")}m" + end + + def reset_escape_sequence! + @escape_sequence = nil + end + + CODES.each do |name, code| + define_singleton_method(name) do + append_to_escape_sequence(code) + end + end + + def to_s + return "" unless $stdout.tty? + current_escape_sequence + ensure + reset_escape_sequence! + end +end diff --git a/docs/brew.1.html b/docs/brew.1.html index bfdd885f0..0911dd79c 100644 --- a/docs/brew.1.html +++ b/docs/brew.1.html @@ -593,6 +593,9 @@ not deleted.</p> <p>If <code>--before=<date></code> is passed, use the commit at <code><date></code> as the start commit.</p> +<p>If <code>--to-tag</code> is passed, set HOMEBREW_UPDATE_TO_TAG to test updating +between tags.</p> + <p>If <code>--keep-tmp</code> is passed, retain the temporary directory containing the new repository clone.</p></dd> </dl> diff --git a/manpages/brew.1 b/manpages/brew.1 index 2642a0e28..ada470f19 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -796,6 +796,9 @@ If \fB\-\-commit=<commit>\fR is passed, use \fB<commit>\fR as the start commit\. If \fB\-\-before=<date>\fR is passed, use the commit at \fB<date>\fR as the start commit\. . .IP +If \fB\-\-to\-tag\fR is passed, set HOMEBREW_UPDATE_TO_TAG to test updating between tags\. +. +.IP If \fB\-\-keep\-tmp\fR is passed, retain the temporary directory containing the new repository clone\. . .SH "EXTERNAL COMMANDS" |
