Skip to content

Commit

Permalink
Merge pull request #16518 from issyl0/rubocop-md
Browse files Browse the repository at this point in the history
rubocop: Try out `rubocop-md` for linting the code in our docs
  • Loading branch information
issyl0 authored Feb 2, 2024
2 parents 8f89403 + ca92fca commit 06028c2
Show file tree
Hide file tree
Showing 15 changed files with 184 additions and 140 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ jobs:
working-directory: ${{ steps.set-up-homebrew.outputs.repository-path }}/docs
run: bundle exec rake lint

- name: Check code blocks conform to our Ruby style guide
working-directory: ${{ steps.set-up-homebrew.outputs.repository-path }}/docs
run: brew style .

- name: Build the site and check for broken links
working-directory: ${{ steps.set-up-homebrew.outputs.repository-path }}/docs
run: |
Expand Down
1 change: 1 addition & 0 deletions Library/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
require:
- ./Homebrew/rubocops.rb
- rubocop-md
- rubocop-performance
- rubocop-rspec
- rubocop-sorbet
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ group :pry, optional: true do
end
group :style, optional: true do
gem "rubocop", require: false
gem "rubocop-md", require: false
gem "rubocop-performance", require: false
gem "rubocop-rspec", require: false
gem "rubocop-sorbet", require: false
Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ GEM
rubocop (~> 1.41)
rubocop-factory_bot (2.25.1)
rubocop (~> 1.41)
rubocop-md (1.2.2)
rubocop (>= 1.0)
rubocop-performance (1.20.2)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.30.0, < 2.0)
Expand Down Expand Up @@ -190,6 +192,7 @@ DEPENDENCIES
rspec_junit_formatter
rubocop
rubocop-ast
rubocop-md
rubocop-performance
rubocop-rspec
rubocop-sorbet
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/style.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ def self.run_rubocop(files, output_type,
files&.map!(&:expand_path)
if files.blank? || files == [HOMEBREW_REPOSITORY]
files = [HOMEBREW_LIBRARY_PATH]
elsif files.any? { |f| f.to_s.start_with? HOMEBREW_REPOSITORY/"docs" }
args << "--config" << (HOMEBREW_REPOSITORY/"docs/.rubocop.yml")
elsif files.none? { |f| f.to_s.start_with? HOMEBREW_LIBRARY_PATH }
args << "--config" << (HOMEBREW_LIBRARY/".rubocop.yml")
end
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/vendor/bundle/bundler/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def self.extension_api_version
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-1.60.2/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-capybara-2.20.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-factory_bot-2.25.1/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-md-1.2.2/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-performance-1.20.2/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-rspec-2.26.1/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-sorbet-0.7.6/lib")
Expand Down
32 changes: 32 additions & 0 deletions docs/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
inherit_from: ../Library/.rubocop.yml

AllCops:
Exclude:
- Gemfile
- ".mdl*.rb"
- Rakefile
- "_site/**/*"
- Manpage.md

# These are included in docs deliberately to show what
# `brew create` does and what the user should replace.
FormulaAudit/Comments:
Enabled: false

# This forces us to use dummy descriptions/homepages in example formulae which we don't need to clutter the docs with.
FormulaAudit/Desc:
Enabled: false
FormulaAudit/Homepage:
Enabled: false

Layout/LineLength:
Exclude:
- Bottles.md # The bottle block line length is long in its full form.

# Apparently Casks are allowed to have constant definitions in blocks and we document this.
Lint/ConstantDefinitionInBlock:
Enabled: false

# A fake regexp is deliberately documented for `inreplace` in the Formula Cookbook.
Style/RedundantRegexpArgument:
Enabled: false
29 changes: 3 additions & 26 deletions docs/Adding-Software-to-Homebrew.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,36 +165,13 @@ If the `generate_cask_token` script does not work for you, see [Cask Token Detai

#### Creating the cask file

Once you know the token, create your cask with the handy-dandy `brew create --cask` command:
Once you know the token, create your cask with the `brew create --cask` command:

```bash
brew create --cask download-url --set-name my-new-cask
```

This will open `EDITOR` with a template for your new cask, to be stored in the file `my-new-cask.rb`. Running the `create` command above will get you a template that looks like this:

```ruby
cask "my-new-cask" do
version ""
sha256 ""

url "download-url"
name ""
desc ""
homepage ""

livecheck do
url ""
strategy ""
end

depends_on macos: ""

app ""

zap trash: ""
end
```
This will open `EDITOR` with a template for your new cask, to be stored in the file `my-new-cask.rb`.

#### Cask stanzas

Expand Down Expand Up @@ -242,7 +219,7 @@ Example:
1. So, the `app` stanza should include the subfolder as a relative path:

```ruby
app "Simple Floating Clock/SimpleFloatingClock.app"
app "Simple Floating Clock/SimpleFloatingClock.app"
```

### Testing and auditing the cask
Expand Down
33 changes: 15 additions & 18 deletions docs/Cask-Cookbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,7 @@ Exception: `do` blocks such as `postflight` may enclose a block of pure Ruby cod

## Header line details

The first non-comment line in a cask follows the form:

```ruby
cask "<cask-token>" do
```

[`<cask-token>`](#token-reference) should match the cask filename, without the `.rb` extension, enclosed in double quotes.
The Cask name ([`<cask-token>`](#token-reference)) on the header line `cask <cask-token> do` should match the cask filename, without the `.rb` extension, enclosed in double quotes.

There are currently some arbitrary limitations on cask tokens which are in the process of being removed. GitHub Actions will catch any errors during the transition.

Expand Down Expand Up @@ -852,12 +846,12 @@ An example, with commonly used signals in ascending order of severity:

```ruby
uninstall signal: [
["TERM", "fr.madrau.switchresx.daemon"],
["QUIT", "fr.madrau.switchresx.daemon"],
["INT", "fr.madrau.switchresx.daemon"],
["HUP", "fr.madrau.switchresx.daemon"],
["KILL", "fr.madrau.switchresx.daemon"],
]
["TERM", "fr.madrau.switchresx.daemon"],
["QUIT", "fr.madrau.switchresx.daemon"],
["INT", "fr.madrau.switchresx.daemon"],
["HUP", "fr.madrau.switchresx.daemon"],
["KILL", "fr.madrau.switchresx.daemon"],
]
```

Note that when multiple running processes match the given bundle ID, all matching processes will be signaled.
Expand Down Expand Up @@ -1082,7 +1076,7 @@ we can use:

```ruby
version "1.2.3"
url "https://example.com/file-version-#{version.delete('.')}.dmg"
url "https://example.com/file-version-#{version.delete(".")}.dmg"
```

We can also leverage the power of regular expressions. So instead of:
Expand All @@ -1096,7 +1090,7 @@ we can use:

```ruby
version "1.2.3build4"
url "https://example.com/#{version.sub(%r{build\d+}, '')}/file-version-#{version}.dmg"
url "https://example.com/#{version.sub(/build\d+/, "")}/file-version-#{version}.dmg"
```

#### `version` methods
Expand Down Expand Up @@ -1197,6 +1191,7 @@ cask "libreoffice" do

url "https://download.documentfoundation.org/libreoffice/stable/#{version}/mac/#{folder}/LibreOffice_#{version}_MacOS_#{arch}.dmg",
verified: "download.documentfoundation.org/libreoffice/stable/"
end
```

If the version number is different for each architecture, locate the unique `version` and (if checked) `sha256` stanzas within `on_arm` and `on_intel` blocks. Example (from [inkscape.rb](https://github.com/Homebrew/homebrew-cask/blob/11f6966bf17628b98895d64a61a4fb0bc1bb31bf/Casks/i/inkscape.rb#L1-L13)):
Expand All @@ -1215,6 +1210,7 @@ cask "inkscape" do
end

url "https://inkscape.org/gallery/item/#{version.csv.second}/Inkscape-#{version.csv.first}_#{arch}.dmg"
end
```

To adjust the installed version depending on the current macOS release, use a series of `on_<system>` blocks that cover the range of supported releases. Each block can contain stanzas that set which version to download and customize installation/uninstallation and livecheck behaviour for one or more releases. Example (from [calibre.rb](https://github.com/Homebrew/homebrew-cask/blob/482c34e950da8d649705f4aaea7b760dcb4b5402/Casks/c/calibre.rb#L1-L34)):
Expand Down Expand Up @@ -1244,6 +1240,7 @@ cask "calibre" do
strategy :github_latest
end
end
end
```

Such `on_<system>` blocks can be nested and contain other stanzas not listed here. Examples: [calhash.rb](https://github.com/Homebrew/homebrew-cask/blob/HEAD/Casks/c/calhash.rb), [openzfs.rb](https://github.com/Homebrew/homebrew-cask/blob/HEAD/Casks/o/openzfs.rb), [r.rb](https://github.com/Homebrew/homebrew-cask/blob/HEAD/Casks/r/r.rb), [wireshark.rb](https://github.com/Homebrew/homebrew-cask/blob/HEAD/Casks/w/wireshark.rb)
Expand All @@ -1260,17 +1257,17 @@ In the exceptional case that the cask DSL is insufficient, it is possible to def
cask "myapp" do
module Utils
def self.arbitrary_method
...
# ...
end
end

name "MyApp"
version "1.0"
sha256 "a32565cdb1673f4071593d4cc9e1c26bc884218b62fef8abc450daa47ba8fa92"

url "https://#{Utils.arbitrary_method}"
name "MyApp"
homepage "https://www.example.com/"
...
# ...
end
```

Expand Down
Loading

0 comments on commit 06028c2

Please sign in to comment.