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

Fix brew style path checking #17482

Merged
merged 5 commits into from
Jun 13, 2024
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
5 changes: 3 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ jobs:
working-directory: docs
run: bundle exec rake lint

- name: Check code blocks conform to our Ruby style guide
run: brew style docs
# TODO: reenable when possible.
# - name: Check code blocks conform to our Ruby style guide
# run: brew style docs

- name: Generate formulae.brew.sh API samples
if: github.repository == 'Homebrew/formulae.brew.sh'
Expand Down
17 changes: 13 additions & 4 deletions Library/Homebrew/style.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
debug: false, verbose: false)
raise ArgumentError, "Invalid output type: #{output_type.inspect}" if [:print, :json].exclude?(output_type)

ruby_files = []
shell_files = []
actionlint_files = []
ruby_files = T.let([], T::Array[Pathname])
shell_files = T.let([], T::Array[Pathname])
actionlint_files = T.let([], T::Array[Pathname])
Array(files).map(&method(:Pathname))
.each do |path|
case path.extname
Expand All @@ -57,7 +57,14 @@
when ".yml"
actionlint_files << path if path.realpath.to_s.include?("/.github/workflows/")
else
shell_files << path if path.realpath == HOMEBREW_BREW_FILE.realpath
ruby_files << path
shell_files += if [HOMEBREW_PREFIX, HOMEBREW_REPOSITORY].include?(path)

Check warning on line 61 in Library/Homebrew/style.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/style.rb#L61

Added line #L61 was not covered by tests
shell_scripts
else
path.glob("**/*.sh")
.reject { |path| path.to_s.include?("/vendor/") }

Check warning on line 65 in Library/Homebrew/style.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/style.rb#L65

Added line #L65 was not covered by tests
end
actionlint_files += (path/".github/workflows").glob("*.y{,a}ml")

Check warning on line 67 in Library/Homebrew/style.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/style.rb#L67

Added line #L67 was not covered by tests
end
end

Expand Down Expand Up @@ -263,8 +270,10 @@

def self.run_actionlint(files)
files = github_workflow_files if files.blank?
# the ignore is to avoid false positives in e.g. actions, homebrew-test-bot
system actionlint, "-shellcheck", shellcheck,
"-config-file", HOMEBREW_REPOSITORY/".github/actionlint.yaml",
"-ignore", "image: string; options: string",
*files
$CHILD_STATUS.success?
end
Expand Down
7 changes: 5 additions & 2 deletions docs/.mdl_ruleset.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
rule 'HB034', 'Bare unstyled URL used' do
# typed: true
# frozen_string_literal: true

rule "HB034", "Bare unstyled URL used" do
tags :links, :url
aliases 'no-bare-unstyled-urls'
aliases "no-bare-unstyled-urls"
check do |doc|
doc.matching_text_element_lines(%r{(?<=\s)https?://})
end
Expand Down
17 changes: 10 additions & 7 deletions docs/.mdl_style.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# typed: true
# frozen_string_literal: true

all
rule 'MD007', indent: 2 # Unordered list indentation
rule 'MD026', punctuation: ',;:' # Trailing punctuation in header
exclude_rule 'MD013' # Line length
exclude_rule 'MD029' # Ordered list item prefix
exclude_rule 'MD033' # Inline HTML
exclude_rule 'MD034' # Bare URL used (replaced by HB034)
exclude_rule 'MD046' # Code block style
rule "MD007", indent: 2 # Unordered list indentation
rule "MD026", punctuation: ",;:" # Trailing punctuation in header
exclude_rule "MD013" # Line length
exclude_rule "MD029" # Ordered list item prefix
exclude_rule "MD033" # Inline HTML
exclude_rule "MD034" # Bare URL used (replaced by HB034)
exclude_rule "MD046" # Code block style
3 changes: 0 additions & 3 deletions docs/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ inherit_from: ../Library/.rubocop.yml

AllCops:
Exclude:
- Gemfile
- ".mdl*.rb"
- Rakefile
- "_site/**/*"
- Manpage.md
- "vendor/**/*"
Expand Down
2 changes: 2 additions & 0 deletions docs/Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source "https://rubygems.org"

ruby file: ".ruby-version"
Expand Down
2 changes: 2 additions & 0 deletions docs/Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "rake"

task default: :build
Expand Down
Loading