language stringclasses 1
value | owner stringlengths 2 15 | repo stringlengths 2 21 | sha stringlengths 45 45 | message stringlengths 7 36.3k | path stringlengths 1 199 | patch stringlengths 15 102k | is_multipart bool 2
classes |
|---|---|---|---|---|---|---|---|
Other | Homebrew | brew | 03ace9b1104f1ddc2adc75a68531167d7e3ea7e0.json | Require more HTTP mirrors for old OS X versions.
This allows the bootstrap of `curl` and `git` on versions of Mac OS X
that cannot reliably download from HTTPS servers any longer. Once these
are both installed users are able to update Homebrew and download files
securely.
Also, as we're doing this, don't point 10.5 users to Tigerbrew as they
are already given caveats for using Homebrew itself. | docs/Installation.md | @@ -47,7 +47,7 @@ PowerPC and Tiger branches from other users in the fork network. See
[Interesting Taps and Forks](Interesting-Taps-and-Forks.md).
<a name="2"><sup>2</sup></a> 10.10 or higher is recommended. 10.5–10.9 are
-supported on a best-effort basis. For 10.4 and 10.5, see
+supported on a best-effort basis. For 10.4 see
[Tigerbrew](https://github.com/mistydemeo/tigerbrew).
<a name="3"><sup>3</sup></a> Most formulae require a compiler. A handful | true |
Other | Homebrew | brew | 049a453b460a5580991e5ca0f8c77fcd1f86eea1.json | linkage_checker: avoid some false positives | Library/Homebrew/os/mac/linkage_checker.rb | @@ -80,7 +80,7 @@ def check_undeclared_deps
end
extraneous_deps = declared_dep_names.reject do |full_name|
name = full_name.split("/").last
- @brewed_dylibs.keys.map { |x| x.split("/").last }.include? name
+ Formula[name].bin.directory? || @brewed_dylibs.keys.map { |x| x.split("/").last }.include?(name)
end
[undeclared_deps, extraneous_deps]
end | false |
Other | Homebrew | brew | 732bf2212d1d52e4f14bef82df94ba4ed537b5fb.json | build: fix HOMEBREW_FORMULA_PREFIX for head
so that it includes the commit. | Library/Homebrew/build.rb | @@ -112,6 +112,10 @@ def install
formula.extend(Debrew::Formula) if ARGV.debug?
formula.brew do |_formula, staging|
+ # For head builds, HOMEBREW_FORMULA_PREFIX should include the commit,
+ # which is not known until after the formula has been staged.
+ ENV["HOMEBREW_FORMULA_PREFIX"] = formula.prefix
+
staging.retain! if ARGV.keep_tmp?
formula.patch
| false |
Other | Homebrew | brew | 49d2d7b94d85dd150956ea14d66a34870d2f70fd.json | home_spec: use different test formula.
Instead of `testball` use a formula named `testballhome` to avoid this
clashing with any other formula named testball. | Library/Homebrew/test/cmd/home_spec.rb | @@ -7,10 +7,10 @@
end
it "opens the homepage for a given Formula" do
- setup_test_formula "testball"
+ setup_test_formula "testballhome"
- expect { brew "home", "testball", "HOMEBREW_BROWSER" => "echo" }
- .to output("#{Formula["testball"].homepage}\n").to_stdout
+ expect { brew "home", "testballhome", "HOMEBREW_BROWSER" => "echo" }
+ .to output("#{Formula["testballhome"].homepage}\n").to_stdout
.and not_to_output.to_stderr
.and be_a_success
end | false |
Other | Homebrew | brew | a6d1ddf32611109b3284b045fdc5123c40e23b9e.json | git_spec.rb: use HTTPS for Git remote test | Library/Homebrew/test/utils/git_spec.rb | @@ -130,7 +130,7 @@
context "when git is available" do
it "returns true when git remote exists", :needs_network do
git = HOMEBREW_SHIMS_PATH/"scm/git"
- url = "http://github.com/Homebrew/homebrew.github.io"
+ url = "https://github.com/Homebrew/homebrew.github.io"
repo = HOMEBREW_CACHE/"hey"
repo.mkpath
| false |
Other | Homebrew | brew | 01872506000619bd57b48e5b69593b5d42ded29e.json | travis.yml: fix umask for brew audit.
Change the umask before we create any files to avoid `brew audit`
complaining about the `chmod` of formulae. | .travis.yml | @@ -20,21 +20,22 @@ matrix:
before_install:
- export HOMEBREW_NO_AUTO_UPDATE=1
- export HOMEBREW_DEVELOPER=1
- - git clone --depth=1 https://github.com/Homebrew/homebrew-test-bot Library/Taps/homebrew/homebrew-test-bot
- if [ "${TRAVIS_OS_NAME}" = "osx" ]; then
+ git clone --depth=1 https://github.com/Homebrew/homebrew-test-bot Library/Taps/homebrew/homebrew-test-bot;
HOMEBREW_REPOSITORY="$(brew --repo)";
sudo chown -R "$USER" "$HOMEBREW_REPOSITORY/Library/Taps";
mv "$HOMEBREW_REPOSITORY/Library/Taps" "$PWD/Library";
sudo rm -rf "$HOMEBREW_REPOSITORY";
sudo ln -s "$PWD" "$HOMEBREW_REPOSITORY";
else
+ umask 022;
+ git clone --depth=1 https://github.com/Homebrew/homebrew-test-bot Library/Taps/homebrew/homebrew-test-bot;
git fetch --unshallow;
export PATH="$PWD/bin:$PATH";
HOMEBREW_CORE_TAP_DIR="$(brew --repo "homebrew/core")";
mkdir -p "$HOMEBREW_CORE_TAP_DIR";
HOMEBREW_TEST_BOT_TAP_DIR="$(brew --repo "homebrew/test-bot")";
ln -s "$HOMEBREW_TEST_BOT_TAP_DIR/.git" "$HOMEBREW_TEST_BOT_TAP_DIR/Formula" "$HOMEBREW_CORE_TAP_DIR";
- umask 022;
fi
script: | false |
Other | Homebrew | brew | d45ff9c0fdfa834c55c01f9c95fe18064fabd76a.json | audit: Add a global flag to silent warning when auditing | Library/Homebrew/dev-cmd/audit.rb | @@ -54,6 +54,7 @@ module Homebrew
def audit
Homebrew.inject_dump_stats!(FormulaAuditor, /^audit_/) if ARGV.switch? "D"
+ Homebrew.auditing = true
formula_count = 0
problem_count = 0 | true |
Other | Homebrew | brew | d45ff9c0fdfa834c55c01f9c95fe18064fabd76a.json | audit: Add a global flag to silent warning when auditing | Library/Homebrew/global.rb | @@ -45,11 +45,15 @@ def failed?
@failed == true
end
- attr_writer :raise_deprecation_exceptions
+ attr_writer :raise_deprecation_exceptions, :auditing
def raise_deprecation_exceptions?
@raise_deprecation_exceptions == true
end
+
+ def auditing?
+ @auditing == true
+ end
end
end
| true |
Other | Homebrew | brew | d45ff9c0fdfa834c55c01f9c95fe18064fabd76a.json | audit: Add a global flag to silent warning when auditing | Library/Homebrew/utils.rb | @@ -102,7 +102,7 @@ def odeprecated(method, replacement = nil, disable: false, disable_on: nil, call
if ARGV.homebrew_developer? || disable ||
Homebrew.raise_deprecation_exceptions?
raise MethodDeprecatedError, message
- else
+ elsif !Homebrew.auditing?
opoo "#{message}\n"
end
end | true |
Other | Homebrew | brew | b582ed513b3b28197369cb3cf808e9c4025ee581.json | audit: Add tests for rubocop methods in line_cop.rb | Library/Homebrew/rubocops/extend/formula_cop.rb | @@ -108,6 +108,8 @@ def find_method_with_args(node, method_name, *args)
# Matches a method with a receiver,
# EX: to match `Formula.factory(name)`
# call `find_instance_method_call(node, "Formula", :factory)`
+ # EX: to match `build.head?`
+ # call `find_instance_method_call(node, :build, :head?)`
# yields to a block with matching method node
def find_instance_method_call(node, instance, method_name)
methods = find_every_method_call_by_name(node, method_name) | true |
Other | Homebrew | brew | b582ed513b3b28197369cb3cf808e9c4025ee581.json | audit: Add tests for rubocop methods in line_cop.rb | Library/Homebrew/rubocops/lines_cop.rb | @@ -129,7 +129,7 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
end
# Node Pattern search for Language::Node
- def_node_search :languageNodeModule?, <<-EOS.undent
+ def_node_search :languageNodeModule?, <<-EOS.undent
(const (const nil :Language) :Node)
EOS
end | true |
Other | Homebrew | brew | b582ed513b3b28197369cb3cf808e9c4025ee581.json | audit: Add tests for rubocop methods in line_cop.rb | Library/Homebrew/test/rubocops/lines_cop_spec.rb | @@ -200,5 +200,276 @@ class Foo < Formula
expect_offense(expected, actual)
end
end
+
+ it "with invalid rebuild" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ bottle do
+ rebuild 0
+ sha256 "fe0679b932dd43a87fd415b609a7fbac7a069d117642ae8ebaac46ae1fb9f0b3" => :sierra
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "'rebuild 0' should be removed",
+ severity: :convention,
+ line: 5,
+ column: 4,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "with OS.linux? check" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ bottle do
+ if OS.linux?
+ nil
+ end
+ sha256 "fe0679b932dd43a87fd415b609a7fbac7a069d117642ae8ebaac46ae1fb9f0b3" => :sierra
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "Don't use OS.linux?; Homebrew/core only supports macOS",
+ severity: :convention,
+ line: 5,
+ column: 7,
+ source: source }]
+
+ inspect_source(cop, source, "/homebrew-core/")
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "with fails_with :llvm" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ bottle do
+ sha256 "fe0679b932dd43a87fd415b609a7fbac7a069d117642ae8ebaac46ae1fb9f0b3" => :sierra
+ end
+ fails_with :llvm do
+ build 2335
+ cause "foo"
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "'fails_with :llvm' is now a no-op so should be removed",
+ severity: :convention,
+ line: 7,
+ column: 2,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "with def test" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+
+ def test
+ assert_equals "1", "1"
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "Use new-style test definitions (test do)",
+ severity: :convention,
+ line: 5,
+ column: 2,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "with def options" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+
+ def options
+ [["--bar", "desc"]]
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "Use new-style option definitions",
+ severity: :convention,
+ line: 5,
+ column: 2,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "with deprecated skip_clean call" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ skip_clean :all
+ end
+ EOS
+
+ expected_offenses = [{ message: <<-EOS.undent.chomp,
+ `skip_clean :all` is deprecated; brew no longer strips symbols
+ Pass explicit paths to prevent Homebrew from removing empty folders.
+ EOS
+ severity: :convention,
+ line: 4,
+ column: 2,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "with build.universal?" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ if build.universal?
+ "foo"
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "macOS has been 64-bit only since 10.6 so build.universal? is deprecated.",
+ severity: :convention,
+ line: 4,
+ column: 5,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "with ENV.universal_binary" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ if build?
+ ENV.universal_binary
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "macOS has been 64-bit only since 10.6 so ENV.universal_binary is deprecated.",
+ severity: :convention,
+ line: 5,
+ column: 5,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "with ENV.universal_binary" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ if build?
+ ENV.x11
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: 'Use "depends_on :x11" instead of "ENV.x11"',
+ severity: :convention,
+ line: 5,
+ column: 5,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "with ruby-macho alternatives" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ system "install_name_tool", "-id"
+ end
+ EOS
+
+ expected_offenses = [{ message: 'Use ruby-macho instead of calling "install_name_tool"',
+ severity: :convention,
+ line: 4,
+ column: 10,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "with npm install without language::Node args" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ system "npm", "install"
+ end
+ EOS
+
+ expected_offenses = [{ message: "Use Language::Node for npm install args",
+ severity: :convention,
+ line: 4,
+ column: 2,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
end
end | true |
Other | Homebrew | brew | 6e3acddc44379eb5d13c923ec08d2f51f0475af9.json | docs: Clarify availability of analytics
This commit tweaks the language in Analytics.md to make it clear
that summaries of install/error data are publicly available,
while only Homebrew maintainers can access the full analytics
(as specified above in the document). | docs/Analytics.md | @@ -37,7 +37,9 @@ As far as we can tell it would be impossible for Google to match the randomly ge
Homebrew's analytics are sent throughout Homebrew's execution to Google Analytics over HTTPS.
## Who?
-Homebrew's analytics are accessible to Homebrew's current maintainers. Contact @MikeMcQuaid if you are a maintainer and need access.
+Homebrew's detailed analytics are accessible to Homebrew's current maintainers. Contact @MikeMcQuaid if you are a maintainer and need access.
+
+Summaries of installation and error analytics are publicly available [here](https://brew.sh/analytics/).
## How?
The code is viewable in [analytics.rb](https://github.com/Homebrew/brew/blob/master/Library/Homebrew/utils/analytics.rb) and [analytics.sh](https://github.com/Homebrew/brew/blob/master/Library/Homebrew/utils/analytics.sh). They are done in a separate background process and fail fast to avoid delaying any execution. They will fail immediately and silently if you have no network connection. | false |
Other | Homebrew | brew | bbf71921eb2b2cce5072bb615fac3a2bc96fcfc7.json | audit: fix subversion remote check logic.
Stop flagging invalid URLs as valid and vice-versa.
Fixes #3118. | Library/Homebrew/dev-cmd/audit.rb | @@ -1233,7 +1233,7 @@ def audit_urls
elsif strategy <= SubversionDownloadStrategy
next unless DevelopmentTools.subversion_handles_most_https_certificates?
next unless Utils.svn_available?
- if Utils.svn_remote_exists url
+ unless Utils.svn_remote_exists url
problem "The URL #{url} is not a valid svn URL"
end
end | false |
Other | Homebrew | brew | 6d726e1bd6676d97bf41bc800942881cf8c3e78f.json | gpg: create unified test helper | Library/Homebrew/gpg.rb | @@ -54,4 +54,13 @@ def self.cleanup_test_processes!
system gpgconf, "--homedir", "keyrings/live", "--kill",
"gpg-agent"
end
+
+ def self.test(path)
+ create_test_key(path)
+ begin
+ yield
+ ensure
+ cleanup_test_processes!
+ end
+ end
end | false |
Other | Homebrew | brew | c75a8221a5115dc45634ece380266a8a63c0458d.json | gpg2_requirement: update code comments | Library/Homebrew/requirements/gpg2_requirement.rb | @@ -5,8 +5,8 @@ class GPG2Requirement < Requirement
fatal true
default_formula "gnupg"
- # GPGTools installs GnuPG 2.0.x as a vanilla `gpg` symlink
- # pointing to `gpg2`. Homebrew install 2.1.x as a non-symlink `gpg`.
- # We support both the 2.0.x "stable" and 2.1.x "modern" series here.
+ # GPGTools installs GnuPG 2.0.x as a `gpg` symlink pointing
+ # to `gpg2`. Our `gnupg` installs only a non-symlink `gpg`.
+ # The aim is to retain support for any version above 2.0.
satisfy(build_env: false) { Gpg.gpg || Gpg.gpg2 }
end | false |
Other | Homebrew | brew | f301e5c4f4a3094aa9a1a1cf76a34efbd04b838d.json | audit: add a nudge to remove ENV.java_cache | Library/Homebrew/dev-cmd/audit.rb | @@ -869,6 +869,10 @@ def line_problems(line, _lineno)
problem "Use \"depends_on :x11\" instead of \"ENV.x11\""
end
+ if line.include?("ENV.java_cache")
+ problem "In-formula ENV.java_cache usage has been deprecated & should be removed."
+ end
+
# Avoid hard-coding compilers
if line =~ %r{(system|ENV\[.+\]\s?=)\s?['"](/usr/bin/)?(gcc|llvm-gcc|clang)['" ]}
problem "Use \"\#{ENV.cc}\" instead of hard-coding \"#{Regexp.last_match(3)}\"" | false |
Other | Homebrew | brew | 775245262d02017cbc10cf842f7a09fd464d30a4.json | add zsh completion for switch <formula> <version> | completions/zsh/_brew | @@ -592,8 +592,14 @@ _brew_style() {
# brew switch name version:
_brew_switch() {
- _message "name version"
- return 1
+ local -a versions
+ if [[ -n ${words[2]} ]]; then
+ versions=(${$(brew ls "${words[2]}" --versions)#${words[2]}})
+ fi
+ _arguments -S \
+ '1::formula:__brew_formulae' \
+ "2:: :(${versions[*]})" \
+ && ret=0
}
# brew tap: | false |
Other | Homebrew | brew | 4cfd333c5a9fd32f1d9870b3e4987c7dad76a88a.json | pour_bottle?: Pour local bottles without sha256
Pouring a local bottle for a formula without a bottle sha256
in the formula for that OS would unexpectedly install from
source instead. | Library/Homebrew/formula_installer.rb | @@ -85,7 +85,7 @@ def pour_bottle?(install_bottle_options = { warn: false })
return false if @pour_failed
bottle = formula.bottle
- return false unless bottle
+ return false if !bottle && !formula.local_bottle_path
return true if force_bottle?
return false if build_from_source? || build_bottle? || interactive?
return false if ARGV.cc | false |
Other | Homebrew | brew | 56ccf10efaac5f97bae6b2e5aef9ef87d7529328.json | limit some heuristics to strict mode | Library/Homebrew/dev-cmd/audit.rb | @@ -201,7 +201,7 @@ def initialize(formula, options = {})
@specs = %w[stable devel head].map { |s| formula.send(s) }.compact
end
- def self.check_http_content(url, name, user_agents: [:default], check_content: false)
+ def self.check_http_content(url, name, user_agents: [:default], check_content: false, strict: false)
return unless url.start_with? "http"
details = nil
@@ -251,6 +251,8 @@ def self.check_http_content(url, name, user_agents: [:default], check_content: f
return "The URL #{url} should use HTTPS rather than HTTP"
end
+ return unless strict
+
# Same size, different content after normalization
# (typical causes: Generated ID, Timestamp, Unix time)
if details[:file].length == secure_details[:file].length
@@ -590,7 +592,8 @@ def audit_homepage
if http_content_problem = FormulaAuditor.check_http_content(homepage,
formula.name,
user_agents: [:browser, :default],
- check_content: true)
+ check_content: true,
+ strict: @strict)
problem http_content_problem
end
end | false |
Other | Homebrew | brew | f8d5b20512700c9458c51523bda2da24f4212b0c.json | missing_formula: use pip2 instead of pip | Library/Homebrew/missing_formula.rb | @@ -31,7 +31,7 @@ def blacklisted_reason(name)
#{Formatter.url("https://pip.readthedocs.io/en/stable/installing/")}
EOS
when "pil" then <<-EOS.undent
- Instead of PIL, consider `pip install pillow`.
+ Instead of PIL, consider `pip2 install pillow`.
EOS
when "macruby" then <<-EOS.undent
MacRuby is not packaged and is on an indefinite development hiatus.
@@ -53,7 +53,7 @@ def blacklisted_reason(name)
ruin SSH's security.
EOS
when "gsutil" then <<-EOS.undent
- Install gsutil with `pip install gsutil`
+ Install gsutil with `pip2 install gsutil`
EOS
when "gfortran" then <<-EOS.undent
GNU Fortran is now provided as part of GCC, and can be installed with: | false |
Other | Homebrew | brew | 923c84d4f7c4e0cf09bfb417deb83bff2364c199.json | add some heuristics to https upgrade check | Library/Homebrew/dev-cmd/audit.rb | @@ -201,7 +201,7 @@ def initialize(formula, options = {})
@specs = %w[stable devel head].map { |s| formula.send(s) }.compact
end
- def self.check_http_content(url, name, user_agents: [:default])
+ def self.check_http_content(type, url, name, user_agents: [:default])
return unless url.start_with? "http"
details = nil
@@ -236,8 +236,31 @@ def self.check_http_content(url, name, user_agents: [:default])
details[:content_length] == secure_details[:content_length]
file_match = details[:file_hash] == secure_details[:file_hash]
- return if !etag_match && !content_length_match && !file_match
- "The URL #{url} could use HTTPS rather than HTTP"
+ if etag_match || content_length_match || file_match
+ return "The URL #{url} could use HTTPS rather than HTTP"
+ end
+
+ if type == "homepage"
+
+ details[:file] = details[:file].gsub(/https?:\\?\/\\?\//, '/')
+ secure_details[:file] = secure_details[:file].gsub(/https?:\\?\/\\?\//, '/')
+
+ # Same content after normalization
+ if details[:file] == secure_details[:file]
+ return "The URL #{url} could use HTTPS rather than HTTP"
+ end
+
+ # Same size, different content after normalization
+ # (typical causes: Generated ID, Timestamp, Unix time)
+ if details[:file].length == secure_details[:file].length
+ return "The URL #{url} could use HTTPS rather than HTTP"
+ end
+
+ lenratio = (100 * secure_details[:file].length / details[:file].length).to_i
+ if lenratio >= 90 && lenratio <= 120
+ return "The URL #{url} may be able to use HTTPS rather than HTTP. Please verify it in a browser."
+ end
+ end
end
def self.http_content_headers_and_checksum(url, hash_needed: false, user_agent: :default)
@@ -260,6 +283,7 @@ def self.http_content_headers_and_checksum(url, hash_needed: false, user_agent:
etag: headers[%r{ETag: ([wW]\/)?"(([^"]|\\")*)"}, 2],
content_length: headers[/Content-Length: (\d+)/, 1],
file_hash: output_hash,
+ file: output,
}
end
@@ -564,7 +588,8 @@ def audit_homepage
return unless @online
return unless DevelopmentTools.curl_handles_most_https_homepages?
- if http_content_problem = FormulaAuditor.check_http_content(homepage,
+ if http_content_problem = FormulaAuditor.check_http_content("homepage",
+ homepage,
formula.name,
user_agents: [:browser, :default])
problem http_content_problem
@@ -1219,7 +1244,8 @@ def audit_urls
# A `brew mirror`'ed URL is usually not yet reachable at the time of
# pull request.
next if url =~ %r{^https://dl.bintray.com/homebrew/mirror/}
- if http_content_problem = FormulaAuditor.check_http_content(url, name)
+ if http_content_problem = FormulaAuditor.check_http_content("url",
+ url, name)
problem http_content_problem
end
elsif strategy <= GitDownloadStrategy | false |
Other | Homebrew | brew | abe47b79c898c49d762df5d0f52541722e8e202c.json | Add check for HEAD ref in diagnostics | Library/Homebrew/diagnostic.rb | @@ -756,7 +756,7 @@ def check_brew_git_origin
end
end
- def check_coretap_git_origin
+ def check_coretap_git_config
coretap_path = CoreTap.instance.path
return if !Utils.git_available? || !(coretap_path/".git").exist?
@@ -785,6 +785,22 @@ def check_coretap_git_origin
git -C "#{coretap_path}" remote set-url origin #{Formatter.url("https://github.com/Homebrew/homebrew-core.git")}
EOS
end
+
+ head = coretap_path.head
+ return unless head && head !~ %r{refs/heads/master}
+
+ <<-EOS.undent
+ Suspicious #{CoreTap.instance} git head found.
+
+ With a non-standard head, your local version of Homebrew might not
+ have all of the changes intended for the most recent release. The
+ current git head is:
+ #{head}
+
+ Unless you have compelling reasons, consider setting the head to
+ point at the master branch by running:
+ git checkout master
+ EOS
end
def __check_linked_brew(f) | false |
Other | Homebrew | brew | 7b96fd008e332949b9d53ffe08e9de20dbff0e2d.json | safe_fork: Improve the error message | Library/Homebrew/utils/fork.rb | @@ -38,7 +38,7 @@ def self.safe_fork(&_block)
Process.wait(pid) unless socket.nil?
raise Marshal.load(data) unless data.nil? || data.empty?
raise Interrupt if $CHILD_STATUS.exitstatus == 130
- raise "Suspicious failure" unless $CHILD_STATUS.success?
+ raise "Forked child process failed: #{$CHILD_STATUS}" unless $CHILD_STATUS.success?
end
end
end | false |
Other | Homebrew | brew | 00eb4324de2035e417344b7b7a2cac6e5a8f29a5.json | Update FAQ entry | docs/FAQ.md | @@ -68,13 +68,15 @@ Be careful as this is a destructive operation.
Which is usually: `~/Library/Caches/Homebrew`
## My Mac `.app`s don’t find `/usr/local/bin` utilities!
-GUI apps on macOS don’t have `/usr/local/bin` in their `PATH` by default.
-If you’re on Mountain Lion, you can fix this by running
-`launchctl setenv PATH "/usr/local/bin:$PATH"`. [More details
-here](https://stackoverflow.com/questions/135688/setting-environment-variables-in-os-x/5444960#5444960),
-including how to set this across reboots. If you’re pre-Mountain Lion,
-[here’s an official
-alternative](https://developer.apple.com/legacy/library/qa/qa1067/_index.html).
+GUI apps on macOS don’t have `/usr/local/bin` in their `PATH` by
+default. If you're on Mountain Lion or later, you can fix this by
+running `sudo launchctl config user path "/usr/local/bin:$PATH"` and
+then rebooting. Note that this sets the launchctl PATH for _all users_
+([more details here](https://apple.stackexchange.com/a/198282)). For
+earlier versions,
+see [this page](https://stackoverflow.com/a/5444960/7869253),
+or
+[this page](https://developer.apple.com/legacy/library/qa/qa1067/_index.html).
## How do I contribute to Homebrew?
Read [CONTRIBUTING.md](https://github.com/Homebrew/brew/blob/master/CONTRIBUTING.md). | false |
Other | Homebrew | brew | b44c7a1022976a4fcd9e7ea9b6069ec971d6b235.json | upgrade more urls to https | Library/Homebrew/cmd/search.rb | @@ -36,7 +36,7 @@ def search
elsif ARGV.include? "--fedora"
exec_browser "https://apps.fedoraproject.org/packages/s/#{ARGV.next}"
elsif ARGV.include? "--ubuntu"
- exec_browser "http://packages.ubuntu.com/search?keywords=#{ARGV.next}&searchon=names&suite=all§ion=all"
+ exec_browser "https://packages.ubuntu.com/search?keywords=#{ARGV.next}&searchon=names&suite=all§ion=all"
elsif ARGV.include? "--desc"
query = ARGV.next
regex = query_regexp(query) | true |
Other | Homebrew | brew | b44c7a1022976a4fcd9e7ea9b6069ec971d6b235.json | upgrade more urls to https | Library/Homebrew/extend/fileutils.rb | @@ -3,7 +3,7 @@
require "etc"
# Homebrew extends Ruby's `FileUtils` to make our code more readable.
-# @see http://ruby-doc.org/stdlib-2.0.0/libdoc/fileutils/rdoc/FileUtils.html Ruby's FileUtils API
+# @see https://ruby-doc.org/stdlib-2.0.0/libdoc/fileutils/rdoc/FileUtils.html Ruby's FileUtils API
module FileUtils
# Create a temporary directory then yield. When the block returns,
# recursively delete the temporary directory. Passing opts[:retain] | true |
Other | Homebrew | brew | b44c7a1022976a4fcd9e7ea9b6069ec971d6b235.json | upgrade more urls to https | Library/Homebrew/extend/pathname.rb | @@ -59,7 +59,7 @@ def compute_disk_usage
end
# Homebrew extends Ruby's `Pathname` to make our code more readable.
-# @see http://ruby-doc.org/stdlib-1.8.7/libdoc/pathname/rdoc/Pathname.html Ruby's Pathname API
+# @see https://ruby-doc.org/stdlib-1.8.7/libdoc/pathname/rdoc/Pathname.html Ruby's Pathname API
class Pathname
include DiskUsageExtension
| true |
Other | Homebrew | brew | b44c7a1022976a4fcd9e7ea9b6069ec971d6b235.json | upgrade more urls to https | Library/Homebrew/test/cmd/search_spec.rb | @@ -53,7 +53,7 @@
"debian" => "https://packages.debian.org/search?keywords=testball&searchon=names&suite=all§ion=all",
"opensuse" => "https://software.opensuse.org/search?q=testball",
"fedora" => "https://apps.fedoraproject.org/packages/s/testball",
- "ubuntu" => "http://packages.ubuntu.com/search?keywords=testball&searchon=names&suite=all§ion=all",
+ "ubuntu" => "https://packages.ubuntu.com/search?keywords=testball&searchon=names&suite=all§ion=all",
}.each do |flag, url|
specify "--#{flag}" do
expect { brew "search", "--#{flag}", "testball", "HOMEBREW_BROWSER" => "echo" } | true |
Other | Homebrew | brew | b44c7a1022976a4fcd9e7ea9b6069ec971d6b235.json | upgrade more urls to https | docs/Formula-Cookbook.md | @@ -693,7 +693,7 @@ Note that [`option`](http://www.rubydoc.info/github/Homebrew/brew/master/Formula
### File level operations
-You can use the file utilities provided by Ruby's [`FileUtils`](http://www.ruby-doc.org/stdlib/libdoc/fileutils/rdoc/index.html). These are included in the `Formula` class, so you do not need the `FileUtils.` prefix to use them.
+You can use the file utilities provided by Ruby's [`FileUtils`](https://www.ruby-doc.org/stdlib/libdoc/fileutils/rdoc/index.html). These are included in the `Formula` class, so you do not need the `FileUtils.` prefix to use them.
When creating symlinks, take special care to ensure they are *relative* symlinks. This makes it easier to create a relocatable bottle. For example, to create a symlink in `bin` to an executable in `libexec`, use
| true |
Other | Homebrew | brew | b44c7a1022976a4fcd9e7ea9b6069ec971d6b235.json | upgrade more urls to https | docs/Prose-Style-Guidelines.md | @@ -16,7 +16,7 @@ Homebrew's audience includes users with a wide range of education and experience
We strive for "correct" but not "fancy" usage. Think newspaper article, not academic paper.
-This is a set of guidelines to be applied using human judgment, not a set of hard and fast rules. It is like [The Economist's Style Guide](http://www.economist.com/styleguide/introduction) or [Garner's Modern American Usage](https://en.wikipedia.org/wiki/Garner's_Modern_American_Usage). It is less like the [Ruby Style Guide](https://github.com/bbatsov/ruby-style-guide). All guidelines here are open to interpretation and discussion. 100% conformance to these guidelines is *not* a goal.
+This is a set of guidelines to be applied using human judgment, not a set of hard and fast rules. It is like [The Economist's Style Guide](https://www.economist.com/styleguide/introduction) or [Garner's Modern American Usage](https://en.wikipedia.org/wiki/Garner's_Modern_American_Usage). It is less like the [Ruby Style Guide](https://github.com/bbatsov/ruby-style-guide). All guidelines here are open to interpretation and discussion. 100% conformance to these guidelines is *not* a goal.
The intent of this document is to help authors make decisions about clarity, style, and consistency. It is not to help settle arguments about who knows English better. Don't use this document to be a jerk.
| true |
Other | Homebrew | brew | 56ef168e7088962ba7b1cdc3da89d30842a8eb69.json | Move fix from #3070 inside `GitHub` module. | Library/Homebrew/cask/lib/hbc/cli/search.rb | @@ -15,7 +15,6 @@ def self.extract_regexp(string)
end
def self.search_remote(query)
- return [] if ENV["HOMEBREW_NO_GITHUB_API"]
matches = GitHub.search_code(user: "caskroom", path: "Casks",
filename: query, extension: "rb")
matches.map do |match| | true |
Other | Homebrew | brew | 56ef168e7088962ba7b1cdc3da89d30842a8eb69.json | Move fix from #3070 inside `GitHub` module. | Library/Homebrew/utils/github.rb | @@ -133,7 +133,7 @@ def api_credentials_error_message(response_headers, needed_scopes)
def open(url, data: nil, scopes: [].freeze)
# This is a no-op if the user is opting out of using the GitHub API.
- return if ENV["HOMEBREW_NO_GITHUB_API"]
+ return block_given? ? yield({}) : {} if ENV["HOMEBREW_NO_GITHUB_API"]
args = %W[--header application/vnd.github.v3+json --write-out \n%{http_code}]
args += curl_args
@@ -245,8 +245,6 @@ def issues_for_formula(name, options = {})
end
def print_pull_requests_matching(query)
- return [] if ENV["HOMEBREW_NO_GITHUB_API"]
-
open_or_closed_prs = search_issues(query, type: "pr")
open_prs = open_or_closed_prs.select { |i| i["state"] == "open" }
@@ -283,6 +281,6 @@ def url_to(*subroutes)
def search(entity, *queries, **qualifiers)
uri = url_to "search", entity
uri.query = query_string(*queries, **qualifiers)
- open(uri) { |json| Array(json["items"]) }
+ open(uri) { |json| json.fetch("items", []) }
end
end | true |
Other | Homebrew | brew | 564a06dfbb711a995558c64c55b353d1fdfcb473.json | Fix typo in spec | Library/Homebrew/test/utils/github_spec.rb | @@ -32,7 +32,7 @@
describe "::search_issues", :needs_network do
it "queries GitHub issues with the passed parameters" do
results = subject.search_issues("brew search", repo: "Homebrew/brew", author: "avetamine", is: "closed")
- expect(results.count).not_to be_empty
+ expect(results).not_to be_empty
expect(results.last["title"]).to eq("brew search : 422 Unprocessable Entity")
end
end | false |
Other | Homebrew | brew | e096836b7b46e605fb4d1c10c632157dd6b11186.json | Improve rspec readability | Library/Homebrew/test/utils/github_spec.rb | @@ -32,7 +32,7 @@
describe "::search_issues", :needs_network do
it "queries GitHub issues with the passed parameters" do
results = subject.search_issues("brew search", repo: "Homebrew/brew", author: "avetamine", is: "closed")
- expect(results.count).to be > 1
+ expect(results.count).not_to be_empty
expect(results.last["title"]).to eq("brew search : 422 Unprocessable Entity")
end
end | false |
Other | Homebrew | brew | afdd0e2437426ec85ff86e5b7562d3a6a69ba3e5.json | add tests for condition dependencies | Library/Homebrew/rubocops/lines_cop.rb | @@ -181,27 +181,22 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
problem "Use MacOS.full_version instead of MACOS_FULL_VERSION"
end
- # dependency(body_node) do |m|
- # # handle symbols and shit: WIP
- # next unless modifier?(m.parent)
- # dep = parameters(m).first
- # condition = m.parent.condition
- # if (condition.if? && condition.method_name == :include? && parameters_passed(condition, /with-#{string_content(dep)}$/))||
- # (condition.if? && condition.method_name == :with? && parameters_passed?(condition, /#{string_content(dep)}$/))
- # problem "Replace #{m.parent.source} with #{dep.source} => :optional"
- # end
- # if (condition.unless? && condition.method_name == :include? && parameters_passed?(condition, /without-#{string_content(dep)}$/))||
- # (condition.unless? && condition.method_name == :without? && parameters_passed?(condition, /#{string_content(dep)}$/))
- # problem "Replace #{m.parent.source} with #{dep.source} => :recommended"
- # end
- # end
- #
- # find_every_method_call_by_name(body_node, :depends_on).each do |m|
- # next unless modifier?(m.parent)
- # dep = parameters(m).first
- # next if dep.hash_type?
- # condition = m.parent.node_parts
- # end
+ conditional_dependencies(body_node) do |node, method, param, dep_node|
+ dep = string_content(dep_node)
+ if node.if?
+ if (method == :include? && regex_match_group(param, /with-#{dep}$/)) ||
+ (method == :with? && regex_match_group(param, /#{dep}$/))
+ offending_node(dep_node.parent)
+ problem "Replace #{node.source} with #{dep_node.parent.source} => :optional"
+ end
+ elsif node.unless?
+ if (method == :include? && regex_match_group(param, /without-#{dep}$/)) ||
+ (method == :without? && regex_match_group(param, /#{dep}$/))
+ offending_node(dep_node.parent)
+ problem "Replace #{node.source} with #{dep_node.parent.source} => :recommended"
+ end
+ end
+ end
find_method_with_args(body_node, :fails_with, :llvm) do
problem "'fails_with :llvm' is now a no-op so should be removed"
@@ -334,12 +329,12 @@ def modifier?(node)
node.modifier_form?
end
- def_node_search :condition, <<-EOS.undent
- (send (send nil :build) $_ $({str sym} _))
- EOS
+ def_node_search :conditional_dependencies, <<-EOS.undent
+ {$(if (send (send nil :build) ${:include? :with? :without?} $(str _))
+ (send nil :depends_on $({str sym} _)) nil)
- def_node_search :dependency, <<-EOS.undent
- (send nil :depends_on ({str sym} _))
+ $(if (send (send nil :build) ${:include? :with? :without?} $(str _)) nil
+ (send nil :depends_on $({str sym} _)))}
EOS
# Match depends_on with hash as argument
@@ -357,17 +352,13 @@ def modifier?(node)
(dstr _ (begin (send nil %1)) $(str _ ))}
EOS
- def_node_matcher :negation?, '(send ... :!)'
# This is Pattern Matching method for AST
# Takes the AST node as argument and yields matching node if block given
# Else returns boolean for the match
def_node_search :languageNode?, <<-PATTERN
(const (const nil :Language) :Node)
PATTERN
- def_node_search :dirPattern, <<-PATTERN
- (send (const nil :Dir) :[] (str $_))
- PATTERN
end
end
end | true |
Other | Homebrew | brew | afdd0e2437426ec85ff86e5b7562d3a6a69ba3e5.json | add tests for condition dependencies | Library/Homebrew/test/rubocops/lines_cop_spec.rb | @@ -1213,6 +1213,72 @@ class Foo < Formula
end
end
+ it "with if conditional dep" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ depends_on "foo" if build.with? "with-foo"
+ end
+ EOS
+
+ expected_offenses = [{ message: 'Replace depends_on "foo" if build.with? "with-foo" with depends_on "foo" => :optional',
+ severity: :convention,
+ line: 4,
+ column: 2,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "with unless conditional dep and symbol" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ depends_on :foo unless build.without? "foo"
+ end
+ EOS
+
+ expected_offenses = [{ message: 'Replace depends_on :foo unless build.without? "foo" with depends_on :foo => :recommended',
+ severity: :convention,
+ line: 4,
+ column: 2,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "with unless conditional dep with build.include?" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ depends_on :foo unless build.include? "without-foo"
+ end
+ EOS
+
+ expected_offenses = [{ message: 'Replace depends_on :foo unless build.include? "without-foo" with depends_on :foo => :recommended',
+ severity: :convention,
+ line: 4,
+ column: 2,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
end
def expect_offense(expected, actual)
expect(actual.message).to eq(expected[:message]) | true |
Other | Homebrew | brew | efabd4b5c2beadecf3282dbe730b1b6f779571e0.json | Add tests for MACOS version consts usage | Library/Homebrew/rubocops/extend/formula_cop.rb | @@ -173,8 +173,8 @@ def depends_on_name_type?(node, name = nil, type = :required)
# if block given, yield matching nodes
def find_const(node, const_name)
return if node.nil?
- node.each_child_node(:const) do |const_node|
- next if const_node.const_name != const_name
+ node.each_descendant(:const) do |const_node|
+ next unless const_node.const_name == const_name
@offensive_node = const_node
@offense_source_range = const_node.source_range
yield const_node if block_given? | true |
Other | Homebrew | brew | efabd4b5c2beadecf3282dbe730b1b6f779571e0.json | Add tests for MACOS version consts usage | Library/Homebrew/rubocops/lines_cop.rb | @@ -173,14 +173,14 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
problem "Use \"if build.#{match[1].downcase}?\" instead"
end
- # find_const(body_node, :MACOS_VERSION) do
- # problem "Use MacOS.version instead of MACOS_VERSION"
- # end
- #
- # find_const(body_node, :MACOS_FULL_VERSION) do
- # problem "Use MacOS.full_version instead of MACOS_FULL_VERSION"
- # end
- #
+ find_const(body_node, "MACOS_VERSION") do
+ problem "Use MacOS.version instead of MACOS_VERSION"
+ end
+
+ find_const(body_node, "MACOS_FULL_VERSION") do
+ problem "Use MacOS.full_version instead of MACOS_FULL_VERSION"
+ end
+
# dependency(body_node) do |m|
# # handle symbols and shit: WIP
# next unless modifier?(m.parent) | true |
Other | Homebrew | brew | efabd4b5c2beadecf3282dbe730b1b6f779571e0.json | Add tests for MACOS version consts usage | Library/Homebrew/test/rubocops/lines_cop_spec.rb | @@ -1189,6 +1189,30 @@ class Foo < Formula
end
end
+ it "with MACOS_VERSION const" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ test do
+ version = MACOS_VERSION
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "Use MacOS.version instead of MACOS_VERSION",
+ severity: :convention,
+ line: 5,
+ column: 14,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
end
def expect_offense(expected, actual)
expect(actual.message).to eq(expected[:message]) | true |
Other | Homebrew | brew | 2f94d5f499bca6bbab238bb6536f05195b358159.json | add test for ARGV.include? | Library/Homebrew/rubocops/lines_cop.rb | @@ -167,12 +167,12 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
problem "Use `depends_on :fortran` instead of `ENV.fortran`"
end
- # find_instance_method_call(body_node, :ARGV, :include?) do |m|
- # param = parameters(m).first
- # next unless match = regex_match_group(param, %r{--(HEAD|devel)})
- # problem "Use \"if build.#{match[1].downcase}?\" instead"
- # end
- #
+ find_instance_method_call(body_node, "ARGV", :include?) do |m|
+ param = parameters(m).first
+ next unless match = regex_match_group(param, %r{--(HEAD|devel)})
+ problem "Use \"if build.#{match[1].downcase}?\" instead"
+ end
+
# find_const(body_node, :MACOS_VERSION) do
# problem "Use MacOS.version instead of MACOS_VERSION"
# end | true |
Other | Homebrew | brew | 2f94d5f499bca6bbab238bb6536f05195b358159.json | add test for ARGV.include? | Library/Homebrew/test/rubocops/lines_cop_spec.rb | @@ -1165,6 +1165,30 @@ class Foo < Formula
end
end
+ it "with ARGV.include? (--HEAD)" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ test do
+ head = ARGV.include? "--HEAD"
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "Use \"if build.head?\" instead",
+ severity: :convention,
+ line: 5,
+ column: 26,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
end
def expect_offense(expected, actual)
expect(actual.message).to eq(expected[:message]) | true |
Other | Homebrew | brew | 3fc6cc1a3a4b8f1b7ca42dc0a7dd7cf8fad91b18.json | add test for ENV.fortran | Library/Homebrew/rubocops/lines_cop.rb | @@ -162,11 +162,11 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
problem "Use 'build.head?' instead of inspecting 'version'"
end
- # find_instance_method_call(body_node, :ENV, :fortran) do
- # next if depends_on?(:fortran)
- # problem "Use `depends_on :fortran` instead of `ENV.fortran`"
- # end
- #
+ find_instance_method_call(body_node, "ENV", :fortran) do
+ next if depends_on?(:fortran)
+ problem "Use `depends_on :fortran` instead of `ENV.fortran`"
+ end
+
# find_instance_method_call(body_node, :ARGV, :include?) do |m|
# param = parameters(m).first
# next unless match = regex_match_group(param, %r{--(HEAD|devel)}) | true |
Other | Homebrew | brew | 3fc6cc1a3a4b8f1b7ca42dc0a7dd7cf8fad91b18.json | add test for ENV.fortran | Library/Homebrew/test/rubocops/lines_cop_spec.rb | @@ -1141,6 +1141,30 @@ class Foo < Formula
end
end
+ it "with ENV.fortran" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ test do
+ ENV.fortran
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "Use `depends_on :fortran` instead of `ENV.fortran`",
+ severity: :convention,
+ line: 5,
+ column: 4,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
end
def expect_offense(expected, actual)
expect(actual.message).to eq(expected[:message]) | true |
Other | Homebrew | brew | 5744cd9066bbdfc4db5332a202ddb962d5359ee5.json | add test for inspecting version | Library/Homebrew/rubocops/lines_cop.rb | @@ -157,11 +157,11 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
problem "Dependency #{string_content(dep)} should not use option #{string_content(option)}"
end
- # find_instance_method_call(body_node, :version, :==) do |m|
- # next unless parameters_passed?(m, "HEAD")
- # problem "Use 'build.head?' instead of inspecting 'version'"
- # end
- #
+ find_instance_method_call(body_node, :version, :==) do |m|
+ next unless parameters_passed?(m, "HEAD")
+ problem "Use 'build.head?' instead of inspecting 'version'"
+ end
+
# find_instance_method_call(body_node, :ENV, :fortran) do
# next if depends_on?(:fortran)
# problem "Use `depends_on :fortran` instead of `ENV.fortran`" | true |
Other | Homebrew | brew | 5744cd9066bbdfc4db5332a202ddb962d5359ee5.json | add test for inspecting version | Library/Homebrew/test/rubocops/lines_cop_spec.rb | @@ -1117,6 +1117,30 @@ class Foo < Formula
end
end
+ it "with inspecting version" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ if version == "HEAD"
+ foo()
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "Use 'build.head?' instead of inspecting 'version'",
+ severity: :convention,
+ line: 4,
+ column: 5,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
end
def expect_offense(expected, actual)
expect(actual.message).to eq(expected[:message]) | true |
Other | Homebrew | brew | cfc423e1839442f605072db14aac42f6f5fa6174.json | add tests for dependencies | Library/Homebrew/rubocops/lines_cop.rb | @@ -148,13 +148,15 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
problem "Use ENV instead of invoking '#{match[1]}' to modify the environment"
end
- # find_every_method_call_by_name(body_node, :depends_on).each do |m|
- # next unless modifier?(m)
- # dep, option = hash_dep(m)
- # next if dep.nil? || option.nil?
- # problem "Dependency #{string_content(dep)} should not use option #{string_content(option)}"
- # end
- #
+ find_every_method_call_by_name(body_node, :depends_on).each do |m|
+ next if modifier?(m.parent)
+ param = parameters(m).first
+ dep, option = hash_dep(param)
+ next if dep.nil? || option.nil?
+ offending_node(param)
+ problem "Dependency #{string_content(dep)} should not use option #{string_content(option)}"
+ end
+
# find_instance_method_call(body_node, :version, :==) do |m|
# next unless parameters_passed?(m, "HEAD")
# problem "Use 'build.head?' instead of inspecting 'version'"
@@ -328,6 +330,7 @@ def unless_modifier?(node)
end
def modifier?(node)
+ return false unless node.if_type?
node.modifier_form?
end
@@ -340,9 +343,9 @@ def modifier?(node)
EOS
# Match depends_on with hash as argument
- def_node_search :hash_dep, <<-EOS.undent
- {$(hash (pair $(str _) $(str _)))
- $(hash (pair $(str _) (array $(str _) ...)))}
+ def_node_matcher :hash_dep, <<-EOS.undent
+ {(hash (pair $(str _) $(str _)))
+ (hash (pair $(str _) (array $(str _) ...)))}
EOS
def_node_matcher :destructure_hash, <<-EOS.undent | true |
Other | Homebrew | brew | cfc423e1839442f605072db14aac42f6f5fa6174.json | add tests for dependencies | Library/Homebrew/test/rubocops/lines_cop_spec.rb | @@ -1095,6 +1095,28 @@ class Foo < Formula
end
end
+ it "with dependencies with invalid options" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ depends_on "foo" => "with-bar"
+ end
+ EOS
+
+ expected_offenses = [{ message: "Dependency foo should not use option with-bar",
+ severity: :convention,
+ line: 4,
+ column: 13,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
end
def expect_offense(expected, actual)
expect(actual.message).to eq(expected[:message]) | true |
Other | Homebrew | brew | d2a7314f538f919e9b09e4b27c1f86b7d3d2eda2.json | add test for env mod through system call | Library/Homebrew/rubocops/lines_cop.rb | @@ -135,18 +135,19 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[2].downcase}}\""
end
end
+
find_every_method_call_by_name(body_node, :depends_on).each do |m|
key, value = destructure_hash(parameters(m).first)
next if (key.nil? || value.nil?)
next unless match = regex_match_group(value, %r{(lua|perl|python|ruby)(\d*)})
problem "#{match[1]} modules should be vendored rather than use deprecated #{m.source}`"
end
- # find_every_method_call_by_name(body_node, :system).each do |m|
- # next unless match = regex_match_group(parameters(m).first, %r{(env|export)(\s+)?})
- # problem "Use ENV instead of invoking '#{match[1]}' to modify the environment"
- # end
- #
+ find_every_method_call_by_name(body_node, :system).each do |m|
+ next unless match = regex_match_group(parameters(m).first, %r{(env|export)(\s+)?})
+ problem "Use ENV instead of invoking '#{match[1]}' to modify the environment"
+ end
+
# find_every_method_call_by_name(body_node, :depends_on).each do |m|
# next unless modifier?(m)
# dep, option = hash_dep(m) | true |
Other | Homebrew | brew | d2a7314f538f919e9b09e4b27c1f86b7d3d2eda2.json | add test for env mod through system call | Library/Homebrew/test/rubocops/lines_cop_spec.rb | @@ -1073,6 +1073,28 @@ class Foo < Formula
end
end
+ it "with setting env manually" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ system "export", "var=value"
+ end
+ EOS
+
+ expected_offenses = [{ message: "Use ENV instead of invoking 'export' to modify the environment",
+ severity: :convention,
+ line: 4,
+ column: 10,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
end
def expect_offense(expected, actual)
expect(actual.message).to eq(expected[:message]) | true |
Other | Homebrew | brew | 64a929184a45f530a49af7b047d5b6605b50b1f8.json | add tests for vendored deps | Library/Homebrew/rubocops/lines_cop.rb | @@ -135,14 +135,13 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[2].downcase}}\""
end
end
+ find_every_method_call_by_name(body_node, :depends_on).each do |m|
+ key, value = destructure_hash(parameters(m).first)
+ next if (key.nil? || value.nil?)
+ next unless match = regex_match_group(value, %r{(lua|perl|python|ruby)(\d*)})
+ problem "#{match[1]} modules should be vendored rather than use deprecated #{m.source}`"
+ end
- # find_every_method_call_by_name(body_node, :depends_on) do |m|
- # key, value = destructure_hash(paramters(m).first)
- # next unless key.str_type?
- # next unless match = regex_match_group(value, %r{(lua|perl|python|ruby)(\d*)})
- # problem "#{match[1]} modules should be vendored rather than use deprecated #{m.source}`"
- # end
- #
# find_every_method_call_by_name(body_node, :system).each do |m|
# next unless match = regex_match_group(parameters(m).first, %r{(env|export)(\s+)?})
# problem "Use ENV instead of invoking '#{match[1]}' to modify the environment"
@@ -345,8 +344,8 @@ def modifier?(node)
$(hash (pair $(str _) (array $(str _) ...)))}
EOS
- def_node_search :destructure_hash, <<-EOS.undent
- (hash (pair $_ $_))
+ def_node_matcher :destructure_hash, <<-EOS.undent
+ (hash (pair $(str _) $(sym _)))
EOS
def_node_search :formula_path_strings, <<-EOS.undent | true |
Other | Homebrew | brew | 64a929184a45f530a49af7b047d5b6605b50b1f8.json | add tests for vendored deps | Library/Homebrew/test/rubocops/lines_cop_spec.rb | @@ -1051,6 +1051,28 @@ def install
end
end
+ it "with dependecies which have to vendored" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ depends_on "lpeg" => :lua51
+ end
+ EOS
+
+ expected_offenses = [{ message: "lua modules should be vendored rather than use deprecated depends_on \"lpeg\" => :lua51`",
+ severity: :convention,
+ line: 4,
+ column: 24,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
end
def expect_offense(expected, actual)
expect(actual.message).to eq(expected[:message]) | true |
Other | Homebrew | brew | 063cbe7acdb0af0a4cd9bd35f29f89bc0d638d4a.json | add tests for formula path shortucut 3 | Library/Homebrew/rubocops/lines_cop.rb | @@ -124,15 +124,15 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
problem "\"\#\{share}#{match[1]}\" should be \"\#{#{match[2]}}\""
end
- formula_path_strings(body_node, :share) do |p|
- if match = regex_match_group(p, %r{/(bin|include|libexec|lib|sbin|share|Frameworks)}i)
- problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[1].downcase}}\""
+ formula_path_strings(body_node, :prefix) do |p|
+ if match = regex_match_group(p, %r{(/share/(info|man))$})
+ problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[2]}}\""
end
- if match = regex_match_group(p, %r{((/share/man/|\#\{man\}/)(man[1-8]))})
+ if match = regex_match_group(p, %r{((/share/man/)(man[1-8]))})
problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[3]}}\""
end
- if match = regex_match_group(p, %r{(/share/(info|man))})
- problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[2]}}\""
+ if match = regex_match_group(p, %r{(/(bin|include|libexec|lib|sbin|share|Frameworks))}i)
+ problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[2].downcase}}\""
end
end
@@ -350,7 +350,8 @@ def modifier?(node)
EOS
def_node_search :formula_path_strings, <<-EOS.undent
- (dstr (begin (send nil %1)) $(str _ ))
+ {(dstr (begin (send nil %1)) $(str _ ))
+ (dstr _ (begin (send nil %1)) $(str _ ))}
EOS
def_node_matcher :negation?, '(send ... :!)' | true |
Other | Homebrew | brew | 063cbe7acdb0af0a4cd9bd35f29f89bc0d638d4a.json | add tests for formula path shortucut 3 | Library/Homebrew/test/rubocops/lines_cop_spec.rb | @@ -979,6 +979,78 @@ def install
expect_offense(expected, actual)
end
end
+
+ it "with formula path shortcut long form 1" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ def install
+ mv "\#{prefix}/libexec", share
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "\"\#\{prefix}/libexec\" should be \"\#{libexec}\"",
+ severity: :convention,
+ line: 5,
+ column: 18,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "with formula path shortcut long form 2" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ def install
+ system "./configure", "--INFODIR=\#{prefix}/share/info"
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "\"\#\{prefix}/share/info\" should be \"\#{info}\"",
+ severity: :convention,
+ line: 5,
+ column: 47,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+ it "with formula path shortcut long form 3" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ def install
+ system "./configure", "--MANDIR=\#{prefix}/share/man/man8"
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "\"\#\{prefix}/share/man/man8\" should be \"\#{man8}\"",
+ severity: :convention,
+ line: 5,
+ column: 46,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
end
def expect_offense(expected, actual)
expect(actual.message).to eq(expected[:message]) | true |
Other | Homebrew | brew | 9c9c280c8aeb97a6ec8956242727208d80247826.json | add tests for formula path string 1 | Library/Homebrew/rubocops/lines_cop.rb | @@ -118,24 +118,24 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
end
end
- # # Prefer formula path shortcuts in strings
- # formula_path_strings(body_node, :prefix) do |p|
- # next unless match = regex_match_group(p, %r{(/(man))[/'"]})
- # problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[3]}}\""
- # end
- #
- # formula_path_strings(body_node, :share) do |p|
- # if match = regex_match_group(p, %r{/(bin|include|libexec|lib|sbin|share|Frameworks)}i)
- # problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[1].downcase}}\""
- # end
- # if match = regex_match_group(p, %r{((/share/man/|\#\{man\}/)(man[1-8]))})
- # problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[3]}}\""
- # end
- # if match = regex_match_group(p, %r{(/share/(info|man))})
- # problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[2]}}\""
- # end
- # end
- #
+ # Prefer formula path shortcuts in strings
+ formula_path_strings(body_node, :share) do |p|
+ next unless match = regex_match_group(p, %r{(/(man))/?})
+ problem "\"\#\{share}#{match[1]}\" should be \"\#{#{match[2]}}\""
+ end
+
+ formula_path_strings(body_node, :share) do |p|
+ if match = regex_match_group(p, %r{/(bin|include|libexec|lib|sbin|share|Frameworks)}i)
+ problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[1].downcase}}\""
+ end
+ if match = regex_match_group(p, %r{((/share/man/|\#\{man\}/)(man[1-8]))})
+ problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[3]}}\""
+ end
+ if match = regex_match_group(p, %r{(/share/(info|man))})
+ problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[2]}}\""
+ end
+ end
+
# find_every_method_call_by_name(body_node, :depends_on) do |m|
# key, value = destructure_hash(paramters(m).first)
# next unless key.str_type?
@@ -349,7 +349,7 @@ def modifier?(node)
(hash (pair $_ $_))
EOS
- def_node_matcher :formula_path_strings, <<-EOS.undent
+ def_node_search :formula_path_strings, <<-EOS.undent
(dstr (begin (send nil %1)) $(str _ ))
EOS
| true |
Other | Homebrew | brew | 9c9c280c8aeb97a6ec8956242727208d80247826.json | add tests for formula path string 1 | Library/Homebrew/test/rubocops/lines_cop_spec.rb | @@ -955,6 +955,30 @@ def install
expect_offense(expected, actual)
end
end
+
+ it "with formula path shortcut long form" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ def install
+ mv "\#{share}/man", share
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "\"\#\{share}/man\" should be \"\#{man}\"",
+ severity: :convention,
+ line: 5,
+ column: 17,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
end
def expect_offense(expected, actual)
expect(actual.message).to eq(expected[:message]) | true |
Other | Homebrew | brew | 603bdd01a81e62d6b97a5da26d75d409e839a8fa.json | Implement PR feedback | Library/Homebrew/cask/lib/hbc/cli/search.rb | @@ -17,7 +17,7 @@ def self.extract_regexp(string)
def self.search_remote(query)
matches = GitHub.search_code(user: "caskroom", path: "Casks",
filename: query, extension: "rb")
- Array(matches).map do |match|
+ matches.map do |match|
tap = Tap.fetch(match["repository"]["full_name"])
next if tap.installed?
"#{tap.name}/#{File.basename(match["path"], ".rb")}" | true |
Other | Homebrew | brew | 603bdd01a81e62d6b97a5da26d75d409e839a8fa.json | Implement PR feedback | Library/Homebrew/cmd/search.rb | @@ -104,7 +104,7 @@ def search_taps(query)
valid_dirnames = ["Formula", "HomebrewFormula", "Casks", "."].freeze
matches = GitHub.search_code(user: ["Homebrew", "caskroom"], filename: query, extension: "rb")
- Array(matches).map do |match|
+ matches.map do |match|
dirname, filename = File.split(match["path"])
next unless valid_dirnames.include?(dirname)
tap = Tap.fetch(match["repository"]["full_name"]) | true |
Other | Homebrew | brew | 603bdd01a81e62d6b97a5da26d75d409e839a8fa.json | Implement PR feedback | Library/Homebrew/test/utils/github_spec.rb | @@ -14,8 +14,8 @@
describe "::query_string" do
it "builds a query with the given hash parameters formatted as key:value" do
- query = subject.query_string(user: "Homebrew", repo: "Brew")
- expect(query).to eq("q=user%3AHomebrew+repo%3ABrew&per_page=100")
+ query = subject.query_string(user: "Homebrew", repo: "brew")
+ expect(query).to eq("q=user%3AHomebrew+repo%3Abrew&per_page=100")
end
it "adds a variable number of top-level string parameters to the query when provided" do | true |
Other | Homebrew | brew | 603bdd01a81e62d6b97a5da26d75d409e839a8fa.json | Implement PR feedback | Library/Homebrew/utils/github.rb | @@ -296,12 +296,12 @@ def format_parameter(key, value)
end
def url_to(*subroutes)
- URI.parse(File.join(API_URL, *subroutes))
+ URI.parse([API_URL, *subroutes].join("/"))
end
def search(entity, *queries, **qualifiers)
uri = url_to "search", entity
uri.query = query_string(*queries, **qualifiers)
- open(uri) { |json| json["items"] }
+ open(uri) { |json| Array(json["items"]) }
end
end | true |
Other | Homebrew | brew | 65ae6bacd8c92d718b259f7efd50fc3fe9f0838b.json | add tests for hardcoded compilers in ENV | Library/Homebrew/rubocops/lines_cop.rb | @@ -108,16 +108,16 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
problem "Use \"\#{ENV.cxx}\" instead of hard-coding \"#{match[2]}\""
end
end
- #
- # find_instance_method_call(body_node, :ENV, :[]=) do |m|
- # param = parameters(m)[1]
- # if match = regex_match_group(param, %r{(/usr/bin/)?(gcc|llvm-gcc|clang)\s?})
- # problem "Use \"\#{ENV.cc}\" instead of hard-coding \"#{match[3]}\""
- # elsif match = regex_match_group(param, %r{(/usr/bin/)?((g|llvm-g|clang)\+\+)\s?})
- # problem "Use \"\#{ENV.cxx}\" instead of hard-coding \"#{match[3]}\""
- # end
- # end
- #
+
+ find_instance_method_call(body_node, "ENV", :[]=) do |m|
+ param = parameters(m)[1]
+ if match = regex_match_group(param, %r{(/usr/bin/)?(gcc|llvm-gcc|clang)\s?})
+ problem "Use \"\#{ENV.cc}\" instead of hard-coding \"#{match[2]}\""
+ elsif match = regex_match_group(param, %r{(/usr/bin/)?((g|llvm-g|clang)\+\+)\s?})
+ problem "Use \"\#{ENV.cxx}\" instead of hard-coding \"#{match[2]}\""
+ end
+ end
+
# # Prefer formula path shortcuts in strings
# formula_path_strings(body_node, :prefix) do |p|
# next unless match = regex_match_group(p, %r{(/(man))[/'"]}) | true |
Other | Homebrew | brew | 65ae6bacd8c92d718b259f7efd50fc3fe9f0838b.json | add tests for hardcoded compilers in ENV | Library/Homebrew/test/rubocops/lines_cop_spec.rb | @@ -817,7 +817,7 @@ def post_install
class Foo < Formula
desc "foo"
url 'http://example.com/foo-1.0.tgz'
- def test
+ def install
verbose = ARGV.verbose?
end
end
@@ -841,7 +841,7 @@ def test
class Foo < Formula
desc "foo"
url 'http://example.com/foo-1.0.tgz'
- def test
+ def install
man1.install man+"man8" => "faad.1"
end
end
@@ -865,7 +865,7 @@ def test
class Foo < Formula
desc "foo"
url 'http://example.com/foo-1.0.tgz'
- def test
+ def install
system "/usr/bin/gcc", "foo"
end
end
@@ -889,7 +889,7 @@ def test
class Foo < Formula
desc "foo"
url 'http://example.com/foo-1.0.tgz'
- def test
+ def install
system "/usr/bin/g++", "-o", "foo", "foo.cc"
end
end
@@ -907,6 +907,54 @@ def test
expect_offense(expected, actual)
end
end
+
+ it "with hardcoded compiler 3 " do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ def install
+ ENV["COMPILER_PATH"] = "/usr/bin/llvm-g++"
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "Use \"\#{ENV.cxx}\" instead of hard-coding \"llvm-g++\"",
+ severity: :convention,
+ line: 5,
+ column: 28,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "with hardcoded compiler 4 " do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ def install
+ ENV["COMPILER_PATH"] = "/usr/bin/gcc"
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "Use \"\#{ENV.cc}\" instead of hard-coding \"gcc\"",
+ severity: :convention,
+ line: 5,
+ column: 28,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
end
def expect_offense(expected, actual)
expect(actual.message).to eq(expected[:message]) | true |
Other | Homebrew | brew | 77468fdae36ee58580a643d8bc0fdd9f8b6e61c3.json | add tests for hard coded compilers in system calls | Library/Homebrew/rubocops/lines_cop.rb | @@ -99,15 +99,15 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
problem "\"#{m.source}\" should be \"#{match[0]}\""
end
- # # Avoid hard-coding compilers
- # find_every_method_call_by_name(body_node, :system).each do |m|
- # param = parameters(m).first
- # if match = regex_match_group(param, %r{(/usr/bin/)?(gcc|llvm-gcc|clang)\s?})
- # problem "Use \"\#{ENV.cc}\" instead of hard-coding \"#{match[3]}\""
- # elsif match = regex_match_group(param, %r{(/usr/bin/)?((g|llvm-g|clang)\+\+)\s?})
- # problem "Use \"\#{ENV.cxx}\" instead of hard-coding \"#{match[3]}\""
- # end
- # end
+ # Avoid hard-coding compilers
+ find_every_method_call_by_name(body_node, :system).each do |m|
+ param = parameters(m).first
+ if match = regex_match_group(param, %r{(/usr/bin/)?(gcc|llvm-gcc|clang)\s?})
+ problem "Use \"\#{ENV.cc}\" instead of hard-coding \"#{match[2]}\""
+ elsif match = regex_match_group(param, %r{(/usr/bin/)?((g|llvm-g|clang)\+\+)\s?})
+ problem "Use \"\#{ENV.cxx}\" instead of hard-coding \"#{match[2]}\""
+ end
+ end
#
# find_instance_method_call(body_node, :ENV, :[]=) do |m|
# param = parameters(m)[1] | true |
Other | Homebrew | brew | 77468fdae36ee58580a643d8bc0fdd9f8b6e61c3.json | add tests for hard coded compilers in system calls | Library/Homebrew/test/rubocops/lines_cop_spec.rb | @@ -859,6 +859,54 @@ def test
expect_offense(expected, actual)
end
end
+
+ it "with hardcoded compiler 1 " do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ def test
+ system "/usr/bin/gcc", "foo"
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "Use \"\#{ENV.cc}\" instead of hard-coding \"gcc\"",
+ severity: :convention,
+ line: 5,
+ column: 12,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "with hardcoded compiler 2 " do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ def test
+ system "/usr/bin/g++", "-o", "foo", "foo.cc"
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "Use \"\#{ENV.cxx}\" instead of hard-coding \"g++\"",
+ severity: :convention,
+ line: 5,
+ column: 12,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
end
def expect_offense(expected, actual)
expect(actual.message).to eq(expected[:message]) | true |
Other | Homebrew | brew | af5cd1a1da0e1b87696ae72b8a5f1c174e83e94e.json | add tests for man+'man[1-8]' | Library/Homebrew/rubocops/lines_cop.rb | @@ -93,12 +93,12 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
problem "Use build instead of ARGV to check options"
end
end
- #
- # find_instance_method_call(body_node, :man, :+) do |m|
- # next unless match = regex_match_group(parameters(m).first, %r{man[1-8]})
- # problem "\"#{m.source}\" should be \"#{match[1]}\""
- # end
- #
+
+ find_instance_method_call(body_node, :man, :+) do |m|
+ next unless match = regex_match_group(parameters(m).first, %r{man[1-8]})
+ problem "\"#{m.source}\" should be \"#{match[0]}\""
+ end
+
# # Avoid hard-coding compilers
# find_every_method_call_by_name(body_node, :system).each do |m|
# param = parameters(m).first | true |
Other | Homebrew | brew | af5cd1a1da0e1b87696ae72b8a5f1c174e83e94e.json | add tests for man+'man[1-8]' | Library/Homebrew/test/rubocops/lines_cop_spec.rb | @@ -835,6 +835,30 @@ def test
expect_offense(expected, actual)
end
end
+
+ it "with man+ " do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ def test
+ man1.install man+"man8" => "faad.1"
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "\"man+\"man8\"\" should be \"man8\"",
+ severity: :convention,
+ line: 5,
+ column: 22,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
end
def expect_offense(expected, actual)
expect(actual.message).to eq(expected[:message]) | true |
Other | Homebrew | brew | 76f4eccdceb5b3fb4e88b56e077234a6a3e56b08.json | add test for using ARGV to check options | Library/Homebrew/rubocops/lines_cop.rb | @@ -88,11 +88,11 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
end
end
- # [:debug?, :verbose?, :value].each do |m|
- # find_instance_method_call(body_node, :ARGV, m) do
- # problem "Use build instead of ARGV to check options"
- # end
- # end
+ [:debug?, :verbose?, :value].each do |m|
+ find_instance_method_call(body_node, "ARGV", m) do
+ problem "Use build instead of ARGV to check options"
+ end
+ end
#
# find_instance_method_call(body_node, :man, :+) do |m|
# next unless match = regex_match_group(parameters(m).first, %r{man[1-8]})
@@ -320,7 +320,6 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
next unless match = regex_match_group(arg, %r{\-\-(.*)})
problem "Reference '#{match[1]}' without dashes"
end
-
end
def unless_modifier?(node) | true |
Other | Homebrew | brew | 76f4eccdceb5b3fb4e88b56e077234a6a3e56b08.json | add test for using ARGV to check options | Library/Homebrew/test/rubocops/lines_cop_spec.rb | @@ -811,6 +811,30 @@ def post_install
expect_offense(expected, actual)
end
end
+
+ it "with using ARGV to check options" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ def test
+ verbose = ARGV.verbose?
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "Use build instead of ARGV to check options",
+ severity: :convention,
+ line: 5,
+ column: 14,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
end
def expect_offense(expected, actual)
expect(actual.message).to eq(expected[:message]) | true |
Other | Homebrew | brew | dc4d10ff6a59ce0da1bfc7bc06dd819c442813ab.json | add test for build.include? having dashed args | Library/Homebrew/rubocops/lines_cop.rb | @@ -314,12 +314,12 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
next unless match = regex_match_group(arg, %r{with(out)?-(.*)})
problem "Use build.with#{match[1]}? \"#{match[2]}\" instead of build.include? 'with#{match[1]}-#{match[2]}'"
end
- #
- # find_instance_method_call(body_node, :build, :include?) do |m|
- # arg = parameters(m).first
- # next unless match = regex_match_group(arg, %r{\-\-(.*)})
- # problem "Reference '#{match[1]}' without dashes"
- # end
+
+ find_instance_method_call(body_node, :build, :include?) do |m|
+ arg = parameters(m).first
+ next unless match = regex_match_group(arg, %r{\-\-(.*)})
+ problem "Reference '#{match[1]}' without dashes"
+ end
end
| true |
Other | Homebrew | brew | dc4d10ff6a59ce0da1bfc7bc06dd819c442813ab.json | add test for build.include? having dashed args | Library/Homebrew/test/rubocops/lines_cop_spec.rb | @@ -787,6 +787,30 @@ def post_install
expect_offense(expected, actual)
end
end
+
+ it "with build.include? with dashed args" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ def post_install
+ return if build.include? "--bar"
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "Reference 'bar' without dashes",
+ severity: :convention,
+ line: 5,
+ column: 30,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
end
def expect_offense(expected, actual)
expect(actual.message).to eq(expected[:message]) | true |
Other | Homebrew | brew | 3ff8be1216388817dda2b4bb95aeaa5c3d3d5a6b.json | add test for build.include? | Library/Homebrew/rubocops/lines_cop.rb | @@ -309,11 +309,11 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
problem "Don't duplicate 'with': Use `build.with? \"#{match[1]}\"` to check for \"--with-#{match[1]}\""
end
- # find_instance_method_call(body_node, :build, :include?) do |m|
- # arg = parameters(m).first
- # next unless match = regex_match_group(arg, %r{with(out)?-(.*)})
- # problem "Use build.with#{match[1]}? \"#{match[2]}\" instead of build.include? 'with#{match[1]}-#{match[2]}'"
- # end
+ find_instance_method_call(body_node, :build, :include?) do |m|
+ arg = parameters(m).first
+ next unless match = regex_match_group(arg, %r{with(out)?-(.*)})
+ problem "Use build.with#{match[1]}? \"#{match[2]}\" instead of build.include? 'with#{match[1]}-#{match[2]}'"
+ end
#
# find_instance_method_call(body_node, :build, :include?) do |m|
# arg = parameters(m).first | true |
Other | Homebrew | brew | 3ff8be1216388817dda2b4bb95aeaa5c3d3d5a6b.json | add test for build.include? | Library/Homebrew/test/rubocops/lines_cop_spec.rb | @@ -763,6 +763,30 @@ def post_install
expect_offense(expected, actual)
end
end
+
+ it "with build.include?" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ def post_install
+ return if build.include? "without-bar"
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "Use build.without? \"bar\" instead of build.include? 'without-bar'",
+ severity: :convention,
+ line: 5,
+ column: 30,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
end
def expect_offense(expected, actual)
expect(actual.message).to eq(expected[:message]) | true |
Other | Homebrew | brew | 24da1ecd3de86177f669072c542c9a01e6d6649d.json | Fix url encoded in expected values | Library/Homebrew/test/utils/github_spec.rb | @@ -15,17 +15,17 @@
describe "::query_string" do
it "builds a query with the given hash parameters formatted as key:value" do
query = subject.query_string(user: "Homebrew", repo: "Brew")
- expect(query).to eq("q=user%3aHomebrew+repo%3aTest&per_page=100")
+ expect(query).to eq("q=user%3AHomebrew+repo%3ABrew&per_page=100")
end
it "adds a variable number of top-level string parameters to the query when provided" do
query = subject.query_string("value1", "value2", user: "Homebrew")
- expect(query).to eq("q=value1+value2+user%3aHomebrew&per_page=100")
+ expect(query).to eq("q=value1+value2+user%3AHomebrew&per_page=100")
end
it "turns array values into multiple key:value parameters" do
query = subject.query_string(user: ["Homebrew", "caskroom"])
- expect(query).to eq("q=user%3aHomebrew+user%3acaskroom&per_page=100")
+ expect(query).to eq("q=user%3AHomebrew+user%3Acaskroom&per_page=100")
end
end
end | false |
Other | Homebrew | brew | 5a7cbb762f1a9e715ae03e82eb6cb8ef4ac4a0bb.json | add test for build.with? "--with-foo" | Library/Homebrew/rubocops/lines_cop.rb | @@ -303,12 +303,12 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
problem "Don't duplicate 'without': Use `build.without? \"#{match[1]}\"` to check for \"--without-#{match[1]}\""
end
- # find_instance_method_call(body_node, :build, :with?) do |m|
- # arg = parameters(m).first
- # next unless match = regex_match_group(arg, %r{-?-?with-(.*)})
- # problem "Don't duplicate 'with': Use `build.with? \"#{match[1]}\"` to check for \"--with-#{match[1]}\""
- # end
- #
+ find_instance_method_call(body_node, :build, :with?) do |m|
+ arg = parameters(m).first
+ next unless match = regex_match_group(arg, %r{-?-?with-(.*)})
+ problem "Don't duplicate 'with': Use `build.with? \"#{match[1]}\"` to check for \"--with-#{match[1]}\""
+ end
+
# find_instance_method_call(body_node, :build, :include?) do |m|
# arg = parameters(m).first
# next unless match = regex_match_group(arg, %r{with(out)?-(.*)}) | true |
Other | Homebrew | brew | 5a7cbb762f1a9e715ae03e82eb6cb8ef4ac4a0bb.json | add test for build.with? "--with-foo" | Library/Homebrew/test/rubocops/lines_cop_spec.rb | @@ -716,7 +716,7 @@ def post_install
end
end
- it "with negated build.with?" do
+ it "with duplicated build.without?" do
source = <<-EOS.undent
class Foo < Formula
desc "foo"
@@ -739,6 +739,30 @@ def post_install
expect_offense(expected, actual)
end
end
+
+ it "with duplicated build.with?" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ def post_install
+ return if build.with? "--with-bar"
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "Don't duplicate 'with': Use `build.with? \"bar\"` to check for \"--with-bar\"",
+ severity: :convention,
+ line: 5,
+ column: 27,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
end
def expect_offense(expected, actual)
expect(actual.message).to eq(expected[:message]) | true |
Other | Homebrew | brew | 02a1406a2e4c2d0506861248eb767d99f5ce4515.json | add test for build.without --without-foo | Library/Homebrew/rubocops/lines_cop.rb | @@ -297,12 +297,12 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
problem "Don't negate 'build.without?': use 'build.with?'"
end
- # find_instance_method_call(body_node, :build, :without?) do |m|
- # arg = parameters(m).first
- # next unless match = regex_match_group(arg, %r{-?-?without-(.*)})
- # problem "Don't duplicate 'without': Use `build.without? \"#{match[1]}\"` to check for \"--without-#{match[1]}\""
- # end
- #
+ find_instance_method_call(body_node, :build, :without?) do |m|
+ arg = parameters(m).first
+ next unless match = regex_match_group(arg, %r{-?-?without-(.*)})
+ problem "Don't duplicate 'without': Use `build.without? \"#{match[1]}\"` to check for \"--without-#{match[1]}\""
+ end
+
# find_instance_method_call(body_node, :build, :with?) do |m|
# arg = parameters(m).first
# next unless match = regex_match_group(arg, %r{-?-?with-(.*)}) | true |
Other | Homebrew | brew | 02a1406a2e4c2d0506861248eb767d99f5ce4515.json | add test for build.without --without-foo | Library/Homebrew/test/rubocops/lines_cop_spec.rb | @@ -715,6 +715,30 @@ def post_install
expect_offense(expected, actual)
end
end
+
+ it "with negated build.with?" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ def post_install
+ return if build.without? "--without-bar"
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "Don't duplicate 'without': Use `build.without? \"bar\"` to check for \"--without-bar\"",
+ severity: :convention,
+ line: 5,
+ column: 30,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
end
def expect_offense(expected, actual)
expect(actual.message).to eq(expected[:message]) | true |
Other | Homebrew | brew | e14fedd1b35480ea3707689db044140d18662b9c.json | Add test for negated build.with? | Library/Homebrew/rubocops/extend/formula_cop.rb | @@ -252,11 +252,15 @@ def method_called_in_block?(node, method_name)
end
# Check if method_name is called among the direct children nodes in the given node
+ # Check if the node itself is the method
def method_called?(node, method_name)
+ if node.send_type? && node.method_name == method_name
+ offending_node(node)
+ return true
+ end
node.each_child_node(:send) do |call_node|
next unless call_node.method_name == method_name
- @offensive_node = call_node
- @offense_source_range = call_node.source_range
+ offending_node(call_node)
return true
end
false | true |
Other | Homebrew | brew | e14fedd1b35480ea3707689db044140d18662b9c.json | Add test for negated build.with? | Library/Homebrew/rubocops/lines_cop.rb | @@ -287,11 +287,11 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
problem "Use if #{correct} instead of unless #{m.source}"
end
- # find_instance_method_call(body_node, :build, :with?) do |m|
- # next unless negation?(m)
- # problem "Don't negate 'build.with?': use 'build.without?'"
- # end
- #
+ find_instance_method_call(body_node, :build, :with?) do |m|
+ next unless method_called?(m.parent, :!)
+ problem "Don't negate 'build.with?': use 'build.without?'"
+ end
+
# find_instance_method_call(body_node, :build, :without?) do |m|
# next unless negation?(m)
# problem "Don't negate 'build.without?': use 'build.with?'"
@@ -324,6 +324,7 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
end
def unless_modifier?(node)
+ return false unless node.if_type?
node.modifier_form? && node.unless?
end
| true |
Other | Homebrew | brew | e14fedd1b35480ea3707689db044140d18662b9c.json | Add test for negated build.with? | Library/Homebrew/test/rubocops/lines_cop_spec.rb | @@ -667,6 +667,30 @@ def post_install
expect_offense(expected, actual)
end
end
+
+ it "with negated build.with?" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ def post_install
+ return if !build.with? "bar"
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "Don't negate 'build.with?': use 'build.without?'",
+ severity: :convention,
+ line: 5,
+ column: 14,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
end
def expect_offense(expected, actual)
expect(actual.message).to eq(expected[:message]) | true |
Other | Homebrew | brew | ec2b0df10e62152529386cf2a696f9aaece405ea.json | Add tests for unless build.with? | Library/Homebrew/rubocops/lines_cop.rb | @@ -281,12 +281,12 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
problem "Use if #{correct} instead of unless #{m.source}"
end
- # find_instance_method_call(body_node, :build, :with?) do |m|
- # next unless unless_modifier?(m.parent)
- # correct = m.source.gsub("?", "out?").gsub("unless", "if")
- # problem "Use #{correct} instead of unless #{m.source}"
- # end
- #
+ find_instance_method_call(body_node, :build, :with?) do |m|
+ next unless unless_modifier?(m.parent)
+ correct = m.source.gsub("?", "out?")
+ problem "Use if #{correct} instead of unless #{m.source}"
+ end
+
# find_instance_method_call(body_node, :build, :with?) do |m|
# next unless negation?(m)
# problem "Don't negate 'build.with?': use 'build.without?'" | true |
Other | Homebrew | brew | ec2b0df10e62152529386cf2a696f9aaece405ea.json | Add tests for unless build.with? | Library/Homebrew/test/rubocops/lines_cop_spec.rb | @@ -643,6 +643,30 @@ def post_install
expect_offense(expected, actual)
end
end
+
+ it "with unless build.with?" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ def post_install
+ return unless build.with? "bar"
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: 'Use if build.without? "bar" instead of unless build.with? "bar"',
+ severity: :convention,
+ line: 5,
+ column: 18,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
end
def expect_offense(expected, actual)
expect(actual.message).to eq(expected[:message]) | true |
Other | Homebrew | brew | f968776e8460d7b6a0a3199d9c92c945cda0738d.json | Add tests for unless build.without? | Library/Homebrew/rubocops/lines_cop.rb | @@ -274,13 +274,13 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
if find_method_def(@processed_source.ast)
problem "Define method #{method_name(@offensive_node)} in the class body, not at the top-level"
end
- #
- # find_instance_method_call(body_node, :build, :without?) do |m|
- # next unless unless_modifier?(m.parent)
- # correct = m.source.gsub("out?", "?").gsub("unless", "if")
- # problem "Use #{correct} instead of unless #{m.source}"
- # end
- #
+
+ find_instance_method_call(body_node, :build, :without?) do |m|
+ next unless unless_modifier?(m.parent)
+ correct = m.source.gsub("out?", "?")
+ problem "Use if #{correct} instead of unless #{m.source}"
+ end
+
# find_instance_method_call(body_node, :build, :with?) do |m|
# next unless unless_modifier?(m.parent)
# correct = m.source.gsub("?", "out?").gsub("unless", "if") | true |
Other | Homebrew | brew | f968776e8460d7b6a0a3199d9c92c945cda0738d.json | Add tests for unless build.without? | Library/Homebrew/test/rubocops/lines_cop_spec.rb | @@ -619,6 +619,30 @@ class Foo < Formula
expect_offense(expected, actual)
end
end
+
+ it "with unless build.without?" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ def post_install
+ return unless build.without? "bar"
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: 'Use if build.with? "bar" instead of unless build.without? "bar"',
+ severity: :convention,
+ line: 5,
+ column: 18,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
end
def expect_offense(expected, actual)
expect(actual.message).to eq(expected[:message]) | true |
Other | Homebrew | brew | 91b139aca293bea1aa926c5301754e8603c9275e.json | Fix syntax error | Library/Homebrew/utils/github.rb | @@ -284,7 +284,7 @@ def query_string(*main_params, **qualifiers)
if value.is_a? Array
value.each { |v| params_list << format_parameter(key, v) }
else
- params_list << format_parameter(key, v)
+ params_list << format_parameter(key, value)
end
end
| false |
Other | Homebrew | brew | 6dad9d8b44e22f2729a2db95a1c2d14b3e84d477.json | Add test for top level method def | Library/Homebrew/rubocops/extend/formula_cop.rb | @@ -232,6 +232,7 @@ def find_method_def(node, method_name = nil)
@offense_source_range = def_node.source_range
return def_node
end
+ return if node.parent.nil?
# If not found then, parent node becomes the offensive node
@offensive_node = node.parent
@offense_source_range = node.parent.source_range | true |
Other | Homebrew | brew | 6dad9d8b44e22f2729a2db95a1c2d14b3e84d477.json | Add test for top level method def | Library/Homebrew/rubocops/lines_cop.rb | @@ -271,9 +271,9 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
problem "Use the `#{match}` Ruby method instead of `#{m.source}`"
end
- # if find_method_def(@processed_source.ast)
- # problem "Define method #{method_name(@offensive_node)} in the class body, not at the top-level"
- # end
+ if find_method_def(@processed_source.ast)
+ problem "Define method #{method_name(@offensive_node)} in the class body, not at the top-level"
+ end
#
# find_instance_method_call(body_node, :build, :without?) do |m|
# next unless unless_modifier?(m.parent) | true |
Other | Homebrew | brew | 6dad9d8b44e22f2729a2db95a1c2d14b3e84d477.json | Add test for top level method def | Library/Homebrew/test/rubocops/lines_cop_spec.rb | @@ -592,6 +592,29 @@ class Foo < Formula
inspect_source(cop, source)
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+ it "with a top-level function def " do
+ source = <<-EOS.undent
+ def test
+ nil
+ end
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ end
+ EOS
+
+ expected_offenses = [{ message: "Define method test in the class body, not at the top-level",
+ severity: :convention,
+ line: 1,
+ column: 0,
+ source: source }]
+
+ inspect_source(cop, source)
+
expected_offenses.zip(cop.offenses).each do |expected, actual|
expect_offense(expected, actual)
end | true |
Other | Homebrew | brew | 7dfe09ccae5b1a8309326e5a5cb3172fbcd795d3.json | Add tests for fileUtils call in system | Library/Homebrew/rubocops/lines_cop.rb | @@ -263,13 +263,14 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
problem "Dir([\"#{string_content(path)}\"]) is unnecessary; just use \"#{match[0]}\""
end
- #
- # fileUtils_methods= FileUtils.singleton_methods(false).map { |m| Regexp.escape(m) }.join "|"
- # find_method_with_args(body_node, :system, /fileUtils_methods/) do |m|
- # method = string_content(@offensive_node)
- # problem "Use the `#{method}` Ruby method instead of `#{m.source}`"
- # end
- #
+
+ fileUtils_methods= Regexp.new(FileUtils.singleton_methods(false).map { |m| Regexp.escape(m) }.join "|")
+ find_every_method_call_by_name(body_node, :system).each do |m|
+ param = parameters(m).first
+ next unless match = regex_match_group(param, fileUtils_methods)
+ problem "Use the `#{match}` Ruby method instead of `#{m.source}`"
+ end
+
# if find_method_def(@processed_source.ast)
# problem "Define method #{method_name(@offensive_node)} in the class body, not at the top-level"
# end | true |
Other | Homebrew | brew | 7dfe09ccae5b1a8309326e5a5cb3172fbcd795d3.json | Add tests for fileUtils call in system | Library/Homebrew/test/rubocops/lines_cop_spec.rb | @@ -571,6 +571,27 @@ class Foo < Formula
inspect_source(cop, source)
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+ it "with system call to fileUtils Method" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ system "mkdir", "foo"
+ end
+ EOS
+
+ expected_offenses = [{ message: "Use the `mkdir` Ruby method instead of `system \"mkdir\", \"foo\"`",
+ severity: :convention,
+ line: 4,
+ column: 10,
+ source: source }]
+
+ inspect_source(cop, source)
+
expected_offenses.zip(cop.offenses).each do |expected, actual|
expect_offense(expected, actual)
end | true |
Other | Homebrew | brew | a73c29fef21ccb7f45243500f04f1ed9965fdf38.json | add tests for non glob dirs audit | Library/Homebrew/rubocops/lines_cop.rb | @@ -255,11 +255,14 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
problem "\"#{m.source}\" is deprecated, use a comparison to MacOS.version instead"
end
end
- #
- # dirPattern(body_node) do |m|
- # next unless m =~ /\[("[^\*{},]+")\]/
- # problem "Dir(#{Regexp.last_match(1)}) is unnecessary; just use #{Regexp.last_match(1)}"
- # end
+
+ find_instance_method_call(body_node, "Dir", :[]) do |m|
+ path = parameters(m).first
+ next if !path.str_type?
+ next unless match = regex_match_group(path, /^[^\*{},]+$/)
+ problem "Dir([\"#{string_content(path)}\"]) is unnecessary; just use \"#{match[0]}\""
+ end
+
#
# fileUtils_methods= FileUtils.singleton_methods(false).map { |m| Regexp.escape(m) }.join "|"
# find_method_with_args(body_node, :system, /fileUtils_methods/) do |m| | true |
Other | Homebrew | brew | a73c29fef21ccb7f45243500f04f1ed9965fdf38.json | add tests for non glob dirs audit | Library/Homebrew/test/rubocops/lines_cop_spec.rb | @@ -552,6 +552,29 @@ class Foo < Formula
expect_offense(expected, actual)
end
end
+
+ it "with non glob DIR" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ rm_rf Dir["src/{llvm,test,librustdoc,etc/snapshot.pyc}"]
+ rm_rf Dir["src/snapshot.pyc"]
+ end
+ EOS
+
+ expected_offenses = [{ message: "Dir([\"src/snapshot.pyc\"]) is unnecessary; just use \"src/snapshot.pyc\"",
+ severity: :convention,
+ line: 5,
+ column: 13,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
end
def expect_offense(expected, actual)
expect(actual.message).to eq(expected[:message]) | true |
Other | Homebrew | brew | 77105b809a83583e3da5726105dc9cd913112913.json | Add tests for macOS check | Library/Homebrew/rubocops/lines_cop.rb | @@ -248,13 +248,13 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
next unless method_called?(m, :new)
problem "`depends_on` can take requirement classes instead of instances"
end
- #
- # os = [:leopard?, :snow_leopard?, :lion?, :mountain_lion?]
- # os.each do |version|
- # find_instance_method_call(body_node, :MacOS, version) do |m|
- # problem "\"#{m.source}\" is deprecated, use a comparison to MacOS.version instead"
- # end
- # end
+
+ os = [:leopard?, :snow_leopard?, :lion?, :mountain_lion?]
+ os.each do |version|
+ find_instance_method_call(body_node, "MacOS", version) do |m|
+ problem "\"#{m.source}\" is deprecated, use a comparison to MacOS.version instead"
+ end
+ end
#
# dirPattern(body_node) do |m|
# next unless m =~ /\[("[^\*{},]+")\]/ | true |
Other | Homebrew | brew | 77105b809a83583e3da5726105dc9cd913112913.json | Add tests for macOS check | Library/Homebrew/test/rubocops/lines_cop_spec.rb | @@ -527,6 +527,27 @@ class Foo < Formula
inspect_source(cop, source)
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+ it "with old style OS check" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ depends_on :foo if MacOS.snow_leopard?
+ end
+ EOS
+
+ expected_offenses = [{ message: "\"MacOS.snow_leopard?\" is deprecated, use a comparison to MacOS.version instead",
+ severity: :convention,
+ line: 4,
+ column: 21,
+ source: source }]
+
+ inspect_source(cop, source)
+
expected_offenses.zip(cop.offenses).each do |expected, actual|
expect_offense(expected, actual)
end | true |
Other | Homebrew | brew | 1939952dc46eab137a52170da407218fd8db0434.json | Remove some hedge words. | docs/Python-for-Formula-Authors.md | @@ -10,7 +10,7 @@ Bindings are a special case of libraries that allow Python code to interact with
Homebrew is happy to accept applications that are built in Python, whether the apps are available from PyPI or not. Homebrew generally won't accept libraries that can be installed correctly with `pip install foo`. Bindings may be installed for packages that provide them, especially if equivalent functionality isn't available through pip.
-In general, applications should unconditionally bundle all of their Python-language dependencies and libraries and should install any unsatisfied dependencies; these strategies are discussed in depth in the following sections.
+Applications should unconditionally bundle all of their Python-language dependencies and libraries and should install any unsatisfied dependencies; these strategies are discussed in depth in the following sections.
## Applications
@@ -121,9 +121,9 @@ in case you need to do different things for different resources.
## Bindings
-It should be okay to build bindings with system Python and use them with any binary-compatible Python. If that's the case, go ahead and build and install Python 2 bindings and don't add an option. If that isn't the case, it's an upstream bug; [here's some advice for resolving it](http://blog.tim-smith.us/2015/09/python-extension-modules-os-x/).
+Build bindings with system Python by default (don't add an option) and they should be usable with any binary-compatible Python. If that isn't the case, it's an upstream bug; [here's some advice for resolving it](http://blog.tim-smith.us/2015/09/python-extension-modules-os-x/).
-If you'd like to add bindings for Python 3, please add `depends_on :python3 => :optional` and make the bindings conditional on `build.with?("python3")`.
+To add bindings for Python 3, please add `depends_on :python3 => :optional` and make the bindings conditional on `build.with?("python3")`.
### Dependencies
@@ -153,7 +153,7 @@ Sometimes we have to `inreplace` a `Makefile` to use our prefix for the Python b
### Python declarations
-Python 2 libraries probably do not need a `depends_on :python` declaration; this way, they will be built with system Python, but should still be usable with any other Python 2.7. If this is not the case, it is an upstream bug; [here is some advice for resolving it](http://blog.tim-smith.us/2015/09/python-extension-modules-os-x/). Libraries built for Python 3 should include `depends_on :python3`, which will bottle against Homebrew's python3, and use the first python3 discovered in `PATH` at build time when installing from source with `brew install --build-from-source`. If a library supports both Python 2.x and Python 3.x, the `:python3` dependency may be `:optional`. Python 2.x libraries must function when they are installed against either the system Python or Homebrew Python.
+Python 2 libraries do not need a `depends_on :python` declaration; they will be built with system Python, but should still be usable with any other Python 2.7. If this is not the case, it is an upstream bug; [here is some advice for resolving it](http://blog.tim-smith.us/2015/09/python-extension-modules-os-x/). Libraries built for Python 3 should include `depends_on :python3`, which will bottle against Homebrew's python3, and use the first python3 discovered in `PATH` at build time when installing from source with `brew install --build-from-source`. If a library supports both Python 2.x and Python 3.x, the `:python3` dependency should be `:optional`. Python 2.x libraries must function when they are installed against either the system Python or Homebrew Python.
### Installing
@@ -183,7 +183,7 @@ Distribute (not to be confused with distutils) is an obsolete fork of setuptools
### Running `setup.py`
-In the event that a formula needs to interact with `setup.py` instead of calling `pip`, Homebrew provides a helper method, `Language::Python.setup_install_args`, which returns useful arguments for invoking `setup.py`. Your formula should use this instead of invoking `setup.py` explicitly. The syntax is:
+In the event that a formula needs to interact with `setup.py` instead of calling `pip`, Homebrew provides a helper method, `Language::Python.setup_install_args`, which returns useful arguments for invoking `setup.py`. Your formula should use this instead of invoking `setup.py` explicitly. The syntax is:
```ruby
system "python", *Language::Python.setup_install_args(prefix) | false |
Other | Homebrew | brew | 4760f4e8032694d37f934257f6a58f0164438151.json | Raise an exception when double loading a formula
(As proposed in #2673) | Library/Homebrew/formulary.rb | @@ -20,6 +20,8 @@ def self.load_formula(name, path, contents, namespace)
raise "Formula loading disabled by HOMEBREW_DISABLE_LOAD_FORMULA!"
end
+ raise "Formula #{name} has already been loaded" if const_defined?(namespace)
+
mod = Module.new
const_set(namespace, mod)
begin | true |
Other | Homebrew | brew | 4760f4e8032694d37f934257f6a58f0164438151.json | Raise an exception when double loading a formula
(As proposed in #2673) | Library/Homebrew/test/formulary_spec.rb | @@ -27,6 +27,16 @@ def install
let(:bottle_dir) { Pathname.new("#{TEST_FIXTURE_DIR}/bottles") }
let(:bottle) { bottle_dir/"testball_bottle-0.1.#{Utils::Bottles.tag}.bottle.tar.gz" }
+ describe "::load_formula" do
+ it "does not allow namespace repetition" do |example|
+ definition = "Foo = Class.new(Formula)"
+ namespace = "Test#{example.description.hash.abs}"
+ subject.load_formula("foo", "bar", definition, namespace)
+ expect { subject.load_formula("foo", "bar", definition, namespace) }
+ .to raise_error RuntimeError, /already.* loaded/
+ end
+ end
+
describe "::class_s" do
it "replaces '+' with 'x'" do
expect(subject.class_s("foo++")).to eq("Fooxx") | true |
Other | Homebrew | brew | b06fceda57ea8306e130ba11ccb2bd71f6907c23.json | Add a test | Library/Homebrew/cmd/search.rb | @@ -48,7 +48,7 @@ def search
result = Formulary.factory(query).name
results = Array(result)
rescue FormulaUnavailableError
- results = search_taps(query)
+ results = search_taps(query.split('/')[-1])
end
puts Formatter.columns(results) unless results.empty? | true |
Other | Homebrew | brew | b06fceda57ea8306e130ba11ccb2bd71f6907c23.json | Add a test | Library/Homebrew/test/cmd/search_spec.rb | @@ -1,6 +1,7 @@
describe "brew search", :integration_test do
before(:each) do
setup_test_formula "testball"
+ setup_remote_tap "caskroom/cask/test"
end
it "lists all available Formulae when no argument is given" do
@@ -24,6 +25,13 @@
.and be_a_success
end
+ it "falls back to a tap search when no formula is found" do
+ expect { brew "search", "caskroom/cask/firefox" }
+ .to output(/firefox/).to_stdout
+ .and not_to_output.to_stderr
+ .and be_a_success
+ end
+
describe "--desc" do
let(:desc_cache) { HOMEBREW_CACHE/"desc_cache.json" }
| true |
Other | Homebrew | brew | 0e3f1ab27337338c19996a15e8f1e3b72ec270f1.json | Note cases when pinned formulae get upgraded.
Fixes #3021. | Library/Homebrew/cmd/pin.rb | @@ -1,6 +1,7 @@
#: * `pin` <formulae>:
#: Pin the specified <formulae>, preventing them from being upgraded when
-#: issuing the `brew upgrade` command. See also `unpin`.
+#: issuing the `brew upgrade <formulae>` command (but can still be upgraded
+#: as dependencies for other formulae). See also `unpin`.
require "formula"
| true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.