From aaddc66548a2c0617fe335e8afb057f39422c9dc Mon Sep 17 00:00:00 2001 From: Issy Long Date: Sat, 27 Jan 2024 12:30:00 +0000 Subject: [PATCH] Fix remaining RuboCop `FormulaAudit` offenses in example code --- docs/Adding-Software-to-Homebrew.md | 10 +++---- docs/Formula-Cookbook.md | 45 +++++++++++++++++++++++------ docs/Node-for-Formula-Authors.md | 5 ++-- docs/Python-for-Formula-Authors.md | 8 +++-- 4 files changed, 50 insertions(+), 18 deletions(-) diff --git a/docs/Adding-Software-to-Homebrew.md b/docs/Adding-Software-to-Homebrew.md index f084cbffea..0bedc6eae3 100644 --- a/docs/Adding-Software-to-Homebrew.md +++ b/docs/Adding-Software-to-Homebrew.md @@ -175,13 +175,13 @@ This will open `EDITOR` with a template for your new cask, to be stored in the f ```ruby cask "my-new-cask" do - version "" - sha256 "" + version "fill in the version here" + sha256 "fill in the sha256 here" url "download-url" - name "" - desc "" - homepage "" + name "fill in the name" + desc "Fill in the description here" + homepage "fill in the homepage here" livecheck do url "" diff --git a/docs/Formula-Cookbook.md b/docs/Formula-Cookbook.md index 3e2883eea2..db5aa895a2 100644 --- a/docs/Formula-Cookbook.md +++ b/docs/Formula-Cookbook.md @@ -66,11 +66,11 @@ This creates `$(brew --repository)/Library/Taps/homebrew/homebrew-core/Formula/f ```ruby class Foo < Formula - desc "" - homepage "" + desc "Fill in a one-line description of your formula" + homepage "https://your.homepage/" url "https://example.com/foo-0.1.tar.gz" sha256 "85cc828a96735bdafcf29eb6291ca91bac846579bcef7308536e0c875d6c81d7" - license "" + license "Fill in a license identifier" # depends_on "cmake" => :build @@ -145,6 +145,9 @@ Special exceptions are OpenSSL and LibreSSL. Things that use either *should* be ```ruby class Foo < Formula + desc "Example formula" + homepage "https://example.com" + depends_on "httpd" => [:build, :test] depends_on xcode: ["9.3", :build] depends_on arch: :x86_64 @@ -153,6 +156,8 @@ class Foo < Formula depends_on "pkg-config" depends_on "readline" => :recommended depends_on "gtk+" => :optional + + # ... end ``` @@ -284,6 +289,10 @@ If all else fails, you'll want to use [`resource`](https://rubydoc.brew.sh/Formu ```ruby class Foo < Formula + desc "Example formula" + homepage "https://example.com" + url "https://example.com/foo-1.0.tar.gz" + resource "pycrypto" do url "https://files.pythonhosted.org/packages/60/db/645aa9af249f059cc3a368b118de33889219e0362141e75d4eaf6f80f163/pycrypto-2.6.1.tar.gz" sha256 "f2ce1e989b272cfcb677616763e0a2e7ec659effa67a88aa92b3a65528f60a3c" @@ -662,6 +671,9 @@ Formulae can specify an alternate download for the upstream project’s developm ```ruby class Foo < Formula + desc "Description" + homepage "https://example.com" + head "https://github.com/some/package.git", branch: "main" # the default is "master" end ``` @@ -670,6 +682,9 @@ You can also bundle the URL and any `head`-specific dependencies and resources i ```ruby class Foo < Formula + desc "Description" + homepage "https://example.com" + head do url "https://svn.code.sf.net/p/project/code/trunk" depends_on "pkg-config" => :build @@ -685,8 +700,8 @@ When parsing a download URL, Homebrew auto-detects the resource type it points t ```ruby class Foo < Formula + desc "Some package" homepage "https://github.com/some/package" - description "Some package" url "https://github.com/some/package.git", tag: "v1.6.2", revision: "344cd2ee3463abab4c16ac0f9529a846314932a2" @@ -697,8 +712,8 @@ If not inferable, specify which of Homebrew’s built-in download strategies to ```ruby class Nginx < Formula + desc "Some package" homepage "https://nginx.org/" - description "Some package" url "https://nginx.org/download/nginx-1.23.2.tar.gz", using: :homebrew_curl sha256 "a80cc272d3d72aaee70aa8b517b4862a635c0256790434dbfc4d618a999b0b46" head "https://hg.nginx.org/nginx/", using: :hg @@ -732,8 +747,9 @@ class MyDownloadStrategy < SomeHomebrewDownloadStrategy end class Foo < Formula + desc "Some package" + homepage "https://example.com" url "something", using: MyDownloadStrategy - description "Some package" end ``` @@ -894,6 +910,10 @@ If you want to add an [`option`](https://rubydoc.brew.sh/Formula#option-class_me ```ruby class Yourformula < Formula + desc "Description" + homepage "https://example.com" + url "https://example.com/yourformula-1.0.tar.gz" + sha256 "abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc1" # ... option "with-ham", "Description of the option" option "without-spam", "Another description" @@ -925,9 +945,16 @@ end Any initialization steps that aren't necessarily part of the install process can be located in a `post_install` block, such as setup commands or data directory creation. This block can be re-run separately with `brew postinstall `. ```ruby -def post_install - rm_f pkgetc/"cert.pem" - pkgetc.install_symlink Formula["ca-certificates"].pkgetc/"cert.pem" +class Foo < Formula + desc "Description" + homepage "https://example.com" + url "https://example.com/foo-1.0.tar.gz" + + def post_install + rm_f pkgetc/"cert.pem" + pkgetc.install_symlink Formula["ca-certificates"].pkgetc/"cert.pem" + end + # ... end ``` diff --git a/docs/Node-for-Formula-Authors.md b/docs/Node-for-Formula-Authors.md index 7f1c4cd9ee..c44cd667ed 100644 --- a/docs/Node-for-Formula-Authors.md +++ b/docs/Node-for-Formula-Authors.md @@ -92,7 +92,7 @@ require "language/node" class Foo < Formula desc "Description" - homepage "..." + homepage "https://example.com" url "https://registry.npmjs.org/foo/-/foo-1.4.2.tgz" sha256 "abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc1" @@ -106,7 +106,8 @@ class Foo < Formula end test do - # add a meaningful test here + # add a meaningful test here, version isn't usually meaningful + assert_match version.to_s, shell_output("#{bin}/foo --version") end end ``` diff --git a/docs/Python-for-Formula-Authors.md b/docs/Python-for-Formula-Authors.md index 213cbf0170..5aff5f096c 100644 --- a/docs/Python-for-Formula-Authors.md +++ b/docs/Python-for-Formula-Authors.md @@ -74,8 +74,8 @@ class Foo < Formula name "foo" desc "Bar" homepage "https://example.com" - url "..." - sha256 "abc123" + url "https://example.com/foo-1.0.tar.gz" + sha256 "abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc1" def install # Create a virtualenv in `libexec`. If your app needs Python 3, make sure that @@ -101,6 +101,8 @@ Installing a formula with dependencies will look like this: class Foo < Formula include Language::Python::Virtualenv + desc "Description" + homepage "https://example.com" url "..." resource "six" do @@ -125,6 +127,8 @@ You can also use the more verbose form and request that specific resources be in class Foo < Formula include Language::Python::Virtualenv + desc "Description" + homepage "https://example.com" url "..." def install