diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5aa53cfe54..8d65a0c650 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -46,6 +46,19 @@ jobs: - run: brew typecheck + - name: Check RuboCop filepaths + working-directory: ${{ steps.set-up-homebrew.outputs.repository-path }}/Library/Homebrew + run: | + public_apis=$(git grep -l "@api public" | wc -l | tr -d ' ') + rubocop_docs=$(yq '.Style/Documentation.Include' .rubocop.yml | wc -l | tr -d ' ') + if [[ public_apis -ne rubocop_docs ]] + then + echo "All public Homebrew APIs should be included in the Style/Documentation RuboCop." + echo "There were ${public_apis} '@api public' lines but ${rubocop_docs} filepaths for the 'Style/Documentation' RuboCop." + echo "Add or remove the filepaths from Library/Homebrew/.rubocop.yml as appropriate." + exit 1 + fi + tap-syntax: name: tap syntax needs: syntax diff --git a/Library/.rubocop.yml b/Library/.rubocop.yml index b87af86cf6..78dd2c2e74 100644 --- a/Library/.rubocop.yml +++ b/Library/.rubocop.yml @@ -359,7 +359,7 @@ Style/DisableCopsWithinSourceCodeDirective: - "/**/{Formula,Casks}/**/*.rb" - "**/{Formula,Casks}/**/*.rb" -# Don't enforce documentation in casks or formulae. +# The files actually scanned in this cop are in `Library/Homebrew/.rubocop.yml`. Style/Documentation: Exclude: - "Taps/**/*" diff --git a/Library/Homebrew/.rubocop.yml b/Library/Homebrew/.rubocop.yml index 8f3c4b34a1..b0c21afab7 100644 --- a/Library/Homebrew/.rubocop.yml +++ b/Library/Homebrew/.rubocop.yml @@ -17,27 +17,48 @@ Naming/PredicateName: - is_32_bit? - is_64_bit? +# Only enforce documentation for public APIs. +# Checked by the tests.yml syntax job Style/Documentation: AllowedConstants: - Homebrew - Exclude: - - "extend/**/*.rb" - - "test/**/*.rb" - - "cask/macos.rb" - - "cli/args.rb" - - "cli/parser.rb" - - "cmd/list.rb" - - "cmd/update-report.rb" - - "dev-cmd/irb.rb" - - "dev-cmd/pr-pull.rb" - - "keg_relocate.rb" - - "os/mac/keg.rb" - - "software_spec.rb" - - "utils.rb" - - "utils/fork.rb" - - "utils/git_repository.rb" - - "utils/popen.rb" - - "utils/shell.rb" + Include: + - cask/dsl.rb + - cask/dsl/version.rb + - cask/url.rb + - download_strategy.rb + - extend/kernel.rb + - formula.rb + - formula_assertions.rb + - formula_free_port.rb + - language/go.rb + - language/java.rb + - language/node.rb + - language/perl.rb + - language/python.rb + - livecheck/strategy/apache.rb + - livecheck/strategy/bitbucket.rb + - livecheck/strategy/cpan.rb + - livecheck/strategy/extract_plist.rb + - livecheck/strategy/git.rb + - livecheck/strategy/github_latest.rb + - livecheck/strategy/gnome.rb + - livecheck/strategy/gnu.rb + - livecheck/strategy/hackage.rb + - livecheck/strategy/json.rb + - livecheck/strategy/launchpad.rb + - livecheck/strategy/npm.rb + - livecheck/strategy/page_match.rb + - livecheck/strategy/pypi.rb + - livecheck/strategy/sourceforge.rb + - livecheck/strategy/sparkle.rb + - livecheck/strategy/xorg.rb + - os.rb + - resource.rb + - utils/inreplace.rb + - utils/shebang.rb + - utils/string_inreplace_extension.rb + - version.rb Style/HashAsLastArrayItem: Exclude: diff --git a/Library/Homebrew/extend/kernel.rb b/Library/Homebrew/extend/kernel.rb index f48cd57ab8..1cf47c04d7 100644 --- a/Library/Homebrew/extend/kernel.rb +++ b/Library/Homebrew/extend/kernel.rb @@ -1,6 +1,8 @@ # typed: false # frozen_string_literal: true +# Contains shorthand Homebrew utility methods like `ohai`, `opoo`, `odisabled`. +# TODO: move these out of `Kernel`. module Kernel extend T::Sig diff --git a/Library/Homebrew/test/style_spec.rb b/Library/Homebrew/test/style_spec.rb index 9867bc1e19..227b09b840 100644 --- a/Library/Homebrew/test/style_spec.rb +++ b/Library/Homebrew/test/style_spec.rb @@ -40,7 +40,7 @@ describe Homebrew::Style do describe ".check_style_and_print" do let(:dir) { mktmpdir } - it "returns false for conforming file with only audit-level violations" do + it "returns true (success) for conforming file with only audit-level violations" do # This file is known to use non-rocket hashes and other things that trigger audit, # but not regular, cop violations target_file = HOMEBREW_LIBRARY_PATH/"utils.rb"