commit
8be34a98f8
@ -127,6 +127,11 @@ Style/Encoding:
|
||||
Layout/Tab:
|
||||
Enabled: true
|
||||
|
||||
# We have no use for using `warn` because we are
|
||||
# calling Ruby with warnings disabled ourselves.
|
||||
Style/StderrPuts:
|
||||
Enabled: false
|
||||
|
||||
# dashes in filenames are typical
|
||||
Naming/FileName:
|
||||
Regex: !ruby/regexp /^[\w\@\-\+\.]+(\.rb)?$/
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
require "forwardable"
|
||||
|
||||
class Caveats
|
||||
extend Forwardable
|
||||
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
require "utils/bottles"
|
||||
require "formula"
|
||||
require "thread"
|
||||
|
||||
module Homebrew
|
||||
module Cleanup
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# RuboCop version used for `brew style` and `brew cask style`
|
||||
HOMEBREW_RUBOCOP_VERSION = "0.50.0"
|
||||
HOMEBREW_RUBOCOP_CASK_VERSION = "~> 0.14.4" # has to be updated when RuboCop version changes
|
||||
HOMEBREW_RUBOCOP_VERSION = "0.51.0"
|
||||
HOMEBREW_RUBOCOP_CASK_VERSION = "~> 0.15.0" # has to be updated when RuboCop version changes
|
||||
|
||||
@ -1097,7 +1097,7 @@ module Homebrew
|
||||
def all
|
||||
methods.map(&:to_s).grep(/^check_/)
|
||||
end
|
||||
end # end class Checks
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -422,7 +422,7 @@ module Formulary
|
||||
CoreTap.instance.formula_dir/"#{name.to_s.downcase}.rb"
|
||||
end
|
||||
|
||||
def self.tap_paths(name, taps = Dir["#{HOMEBREW_LIBRARY}/Taps/*/*/"])
|
||||
def self.tap_paths(name, taps = Dir[HOMEBREW_LIBRARY/"Taps/*/*/"])
|
||||
name = name.to_s.downcase
|
||||
taps.map do |tap|
|
||||
Pathname.glob([
|
||||
|
||||
@ -245,7 +245,7 @@ module Language
|
||||
"-v", "--no-deps", "--no-binary", ":all:",
|
||||
"--ignore-installed", *targets
|
||||
end
|
||||
end # class Virtualenv
|
||||
end # module Virtualenv
|
||||
end # module Python
|
||||
end # module Language
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
require "formula"
|
||||
require "tap"
|
||||
require "thread"
|
||||
|
||||
module Readall
|
||||
class << self
|
||||
|
||||
@ -24,6 +24,7 @@ module RuboCop
|
||||
def audit_sha256(checksum)
|
||||
return if checksum.nil?
|
||||
if regex_match_group(checksum, /^$/)
|
||||
@offense_source_range = @offensive_node.source_range
|
||||
problem "sha256 is empty"
|
||||
return
|
||||
end
|
||||
|
||||
@ -6,10 +6,8 @@ module RuboCop
|
||||
module FormulaAudit
|
||||
# This cop audits versioned Formulae for `conflicts_with`
|
||||
class Conflicts < FormulaCop
|
||||
MSG = <<~EOS.freeze
|
||||
Versioned formulae should not use `conflicts_with`.
|
||||
Use `keg_only :versioned_formula` instead.
|
||||
EOS
|
||||
MSG = "Versioned formulae should not use `conflicts_with`. " \
|
||||
"Use `keg_only :versioned_formula` instead.".freeze
|
||||
|
||||
WHITELIST = %w[
|
||||
node@
|
||||
|
||||
@ -186,11 +186,11 @@ module RuboCop
|
||||
end
|
||||
|
||||
def_node_search :required_dependency?, <<~EOS
|
||||
(send nil :depends_on ({str sym} _))
|
||||
(send nil? :depends_on ({str sym} _))
|
||||
EOS
|
||||
|
||||
def_node_search :required_dependency_name?, <<~EOS
|
||||
(send nil :depends_on ({str sym} %1))
|
||||
(send nil? :depends_on ({str sym} %1))
|
||||
EOS
|
||||
|
||||
def_node_search :dependency_type_hash_match?, <<~EOS
|
||||
|
||||
@ -29,10 +29,8 @@ module RuboCop
|
||||
desc_length = "#{@formula_name}: #{string_content(desc)}".length
|
||||
max_desc_length = 80
|
||||
return if desc_length <= max_desc_length
|
||||
problem <<~EOS
|
||||
Description is too long. "name: desc" should be less than #{max_desc_length} characters.
|
||||
Length is calculated as #{@formula_name} + desc. (currently #{desc_length})
|
||||
EOS
|
||||
problem "Description is too long. \"name: desc\" should be less than #{max_desc_length} characters. " \
|
||||
"Length is calculated as #{@formula_name} + desc. (currently #{desc_length})"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -8,11 +8,11 @@ module RuboCop
|
||||
def audit_formula(_node, _class_node, _parent_class_node, _body_node)
|
||||
[:automake, :autoconf, :libtool].each do |dependency|
|
||||
next unless depends_on?(dependency)
|
||||
problem ":#{dependency} is deprecated. Usage should be \"#{dependency}\""
|
||||
problem ":#{dependency} is deprecated. Usage should be \"#{dependency}\"."
|
||||
end
|
||||
|
||||
problem ':apr is deprecated. Usage should be "apr-util"' if depends_on?(:apr)
|
||||
problem ":tex is deprecated" if depends_on?(:tex)
|
||||
problem ':apr is deprecated. Usage should be "apr-util".' if depends_on?(:apr)
|
||||
problem ":tex is deprecated." if depends_on?(:tex)
|
||||
end
|
||||
end
|
||||
|
||||
@ -296,10 +296,8 @@ module RuboCop
|
||||
end
|
||||
|
||||
find_method_with_args(body_node, :skip_clean, :all) do
|
||||
problem <<~EOS.chomp
|
||||
`skip_clean :all` is deprecated; brew no longer strips symbols
|
||||
Pass explicit paths to prevent Homebrew from removing empty folders.
|
||||
EOS
|
||||
problem "`skip_clean :all` is deprecated; brew no longer strips symbols. " \
|
||||
"Pass explicit paths to prevent Homebrew from removing empty folders."
|
||||
end
|
||||
|
||||
if find_method_def(@processed_source.ast)
|
||||
@ -353,11 +351,11 @@ module RuboCop
|
||||
end
|
||||
|
||||
def_node_search :conditional_dependencies, <<~EOS
|
||||
{$(if (send (send nil :build) ${:include? :with? :without?} $(str _))
|
||||
(send nil :depends_on $({str sym} _)) nil)
|
||||
{$(if (send (send nil? :build) ${:include? :with? :without?} $(str _))
|
||||
(send nil? :depends_on $({str sym} _)) nil?)
|
||||
|
||||
$(if (send (send nil :build) ${:include? :with? :without?} $(str _)) nil
|
||||
(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
|
||||
@ -371,13 +369,13 @@ module RuboCop
|
||||
EOS
|
||||
|
||||
def_node_search :formula_path_strings, <<~EOS
|
||||
{(dstr (begin (send nil %1)) $(str _ ))
|
||||
(dstr _ (begin (send nil %1)) $(str _ ))}
|
||||
{(dstr (begin (send nil? %1)) $(str _ ))
|
||||
(dstr _ (begin (send nil? %1)) $(str _ ))}
|
||||
EOS
|
||||
|
||||
# Node Pattern search for Language::Node
|
||||
def_node_search :languageNodeModule?, <<~EOS
|
||||
(const (const nil :Language) :Node)
|
||||
(const (const nil? :Language) :Node)
|
||||
EOS
|
||||
end
|
||||
end
|
||||
|
||||
@ -36,7 +36,7 @@ GEM
|
||||
rspec-support (3.6.0)
|
||||
rspec-wait (0.0.9)
|
||||
rspec (>= 3, < 4)
|
||||
rubocop (0.50.0)
|
||||
rubocop (0.51.0)
|
||||
parallel (~> 1.10)
|
||||
parser (>= 2.3.3.1, < 3.0)
|
||||
powerpack (~> 0.1)
|
||||
@ -61,7 +61,7 @@ DEPENDENCIES
|
||||
rspec
|
||||
rspec-its
|
||||
rspec-wait
|
||||
rubocop (= 0.50.0)
|
||||
rubocop (= 0.51.0)
|
||||
simplecov
|
||||
|
||||
BUNDLED WITH
|
||||
|
||||
@ -1,6 +1,3 @@
|
||||
require "rubocop"
|
||||
require "rubocop/rspec/support"
|
||||
require_relative "../../extend/string"
|
||||
require_relative "../../rubocops/bottle_block_cop"
|
||||
|
||||
describe RuboCop::Cop::FormulaAuditStrict::BottleBlock do
|
||||
@ -8,34 +5,16 @@ describe RuboCop::Cop::FormulaAuditStrict::BottleBlock do
|
||||
|
||||
context "When auditing Bottle Block" do
|
||||
it "When there is revision in bottle block" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
bottle do
|
||||
cellar :any
|
||||
revision 2
|
||||
^^^^^^^^^^ Use rebuild instead of revision in bottle block
|
||||
end
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: described_class::MSG,
|
||||
severity: :convention,
|
||||
line: 5,
|
||||
column: 4,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
end
|
||||
|
||||
def expect_offense(expected, actual)
|
||||
expect(actual.message).to eq(expected[:message])
|
||||
expect(actual.severity).to eq(expected[:severity])
|
||||
expect(actual.line).to eq(expected[:line])
|
||||
expect(actual.column).to eq(expected[:column])
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
||||
@ -50,6 +29,7 @@ describe RuboCop::Cop::FormulaAuditStrict::BottleBlock do
|
||||
end
|
||||
end
|
||||
EOS
|
||||
|
||||
corrected_source = <<~EOS
|
||||
class Foo < Formula
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
|
||||
@ -1,6 +1,3 @@
|
||||
require "rubocop"
|
||||
require "rubocop/rspec/support"
|
||||
require_relative "../../extend/string"
|
||||
require_relative "../../rubocops/caveats_cop"
|
||||
|
||||
describe RuboCop::Cop::FormulaAudit::Caveats do
|
||||
@ -8,34 +5,16 @@ describe RuboCop::Cop::FormulaAudit::Caveats do
|
||||
|
||||
context "When auditing caveats" do
|
||||
it "When there is setuid mentioned in caveats" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
homepage "http://example.com/foo"
|
||||
url "http://example.com/foo-1.0.tgz"
|
||||
def caveats
|
||||
"setuid"
|
||||
^^^^^^ Don\'t recommend setuid in the caveats, suggest sudo instead.
|
||||
end
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "Don't recommend setuid in the caveats, suggest sudo instead.",
|
||||
severity: :convention,
|
||||
line: 5,
|
||||
column: 5,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
end
|
||||
|
||||
def expect_offense(expected, actual)
|
||||
expect(actual.message).to eq(expected[:message])
|
||||
expect(actual.severity).to eq(expected[:severity])
|
||||
expect(actual.line).to eq(expected[:line])
|
||||
expect(actual.column).to eq(expected[:column])
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,6 +1,3 @@
|
||||
require "rubocop"
|
||||
require "rubocop/rspec/support"
|
||||
require_relative "../../extend/string"
|
||||
require_relative "../../rubocops/checksum_cop"
|
||||
|
||||
describe RuboCop::Cop::FormulaAudit::Checksum do
|
||||
@ -8,105 +5,60 @@ describe RuboCop::Cop::FormulaAudit::Checksum do
|
||||
|
||||
context "When auditing spec checksums" do
|
||||
it "When the checksum is empty" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
stable do
|
||||
url "https://github.com/foo-lang/foo-compiler/archive/0.18.0.tar.gz"
|
||||
sha256 ""
|
||||
^^ sha256 is empty
|
||||
|
||||
resource "foo-package" do
|
||||
url "https://github.com/foo-lang/foo-package/archive/0.18.0.tar.gz"
|
||||
sha256 ""
|
||||
^^ sha256 is empty
|
||||
end
|
||||
end
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "sha256 is empty",
|
||||
severity: :convention,
|
||||
line: 5,
|
||||
column: 12,
|
||||
source: source },
|
||||
{ message: "sha256 is empty",
|
||||
severity: :convention,
|
||||
line: 9,
|
||||
column: 14,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "When the checksum is not 64 characters" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
stable do
|
||||
url "https://github.com/foo-lang/foo-compiler/archive/0.18.0.tar.gz"
|
||||
sha256 "5cf6e1ae0a645b426c0474cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea0e9ad"
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ sha256 should be 64 characters
|
||||
|
||||
resource "foo-package" do
|
||||
url "https://github.com/foo-lang/foo-package/archive/0.18.0.tar.gz"
|
||||
sha256 "5cf6e1ae0a645b426c047aaa4cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea0e9"
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ sha256 should be 64 characters
|
||||
end
|
||||
end
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "sha256 should be 64 characters",
|
||||
severity: :convention,
|
||||
line: 5,
|
||||
column: 12,
|
||||
source: source },
|
||||
{ message: "sha256 should be 64 characters",
|
||||
severity: :convention,
|
||||
line: 9,
|
||||
column: 14,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "When the checksum has invalid chars" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
stable do
|
||||
url "https://github.com/foo-lang/foo-compiler/archive/0.18.0.tar.gz"
|
||||
sha256 "5cf6e1ae0a645b426c0k7cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea0e9a"
|
||||
^ sha256 contains invalid characters
|
||||
|
||||
resource "foo-package" do
|
||||
url "https://github.com/foo-lang/foo-package/archive/0.18.0.tar.gz"
|
||||
sha256 "5cf6e1ae0a645b426x047aa4cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea9"
|
||||
^ sha256 contains invalid characters
|
||||
end
|
||||
end
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "sha256 contains invalid characters",
|
||||
severity: :convention,
|
||||
line: 5,
|
||||
column: 31,
|
||||
source: source },
|
||||
{ message: "sha256 contains invalid characters",
|
||||
severity: :convention,
|
||||
line: 9,
|
||||
column: 31,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -116,46 +68,32 @@ describe RuboCop::Cop::FormulaAudit::ChecksumCase do
|
||||
|
||||
context "When auditing spec checksums" do
|
||||
it "When the checksum has upper case characters" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
stable do
|
||||
url "https://github.com/foo-lang/foo-compiler/archive/0.18.0.tar.gz"
|
||||
sha256 "5cf6e1ae0A645b426c0a7cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea0e9a"
|
||||
^ sha256 should be lowercase
|
||||
|
||||
resource "foo-package" do
|
||||
url "https://github.com/foo-lang/foo-package/archive/0.18.0.tar.gz"
|
||||
sha256 "5cf6e1Ae0a645b426b047aa4cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea9"
|
||||
^ sha256 should be lowercase
|
||||
end
|
||||
end
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "sha256 should be lowercase",
|
||||
severity: :convention,
|
||||
line: 5,
|
||||
column: 21,
|
||||
source: source },
|
||||
{ message: "sha256 should be lowercase",
|
||||
severity: :convention,
|
||||
line: 9,
|
||||
column: 20,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "When auditing stable blocks outside spec blocks" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
resource "foo-outside" do
|
||||
url "https://github.com/foo-lang/foo-outside/archive/0.18.0.tar.gz"
|
||||
sha256 "A4cc7cd3f7d1605ffa1ac5755cf6e1ae0a645b426b047a6a39a8b2268ddc7ea9"
|
||||
^ sha256 should be lowercase
|
||||
end
|
||||
stable do
|
||||
url "https://github.com/foo-lang/foo-compiler/archive/0.18.0.tar.gz"
|
||||
@ -167,19 +105,7 @@ describe RuboCop::Cop::FormulaAudit::ChecksumCase do
|
||||
end
|
||||
end
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "sha256 should be lowercase",
|
||||
severity: :convention,
|
||||
line: 5,
|
||||
column: 12,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -1,81 +1,62 @@
|
||||
require "rubocop"
|
||||
require "rubocop/rspec/support"
|
||||
require_relative "../../extend/string"
|
||||
require_relative "../../rubocops/class_cop"
|
||||
|
||||
describe RuboCop::Cop::FormulaAudit::ClassName do
|
||||
subject(:cop) { described_class.new }
|
||||
|
||||
context "When auditing formula" do
|
||||
it "with deprecated inheritance" do
|
||||
formulas = [{
|
||||
"class" => "GithubGistFormula",
|
||||
}, {
|
||||
"class" => "ScriptFileFormula",
|
||||
}, {
|
||||
"class" => "AmazonWebServicesFormula",
|
||||
}]
|
||||
|
||||
formulas.each do |formula|
|
||||
source = <<~EOS
|
||||
class Foo < #{formula["class"]}
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "#{formula["class"]} is deprecated, use Formula instead",
|
||||
severity: :convention,
|
||||
line: 1,
|
||||
column: 12,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses.reverse).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
it "reports an offense when using ScriptFileFormula" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < ScriptFileFormula
|
||||
^^^^^^^^^^^^^^^^^ ScriptFileFormula is deprecated, use Formula instead
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "with deprecated inheritance and autocorrect" do
|
||||
source = <<~EOS
|
||||
class Foo < AmazonWebServicesFormula
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
end
|
||||
EOS
|
||||
corrected_source = <<~EOS
|
||||
class Foo < Formula
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
end
|
||||
EOS
|
||||
it "reports an offense when using GithubGistFormula" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < GithubGistFormula
|
||||
^^^^^^^^^^^^^^^^^ GithubGistFormula is deprecated, use Formula instead
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
new_source = autocorrect_source(source)
|
||||
expect(new_source).to eq(corrected_source)
|
||||
end
|
||||
it "reports an offense when using AmazonWebServicesFormula" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < AmazonWebServicesFormula
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^ AmazonWebServicesFormula is deprecated, use Formula instead
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "supports auto-correcting deprecated parent classes" do
|
||||
source = <<~EOS
|
||||
class Foo < AmazonWebServicesFormula
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
end
|
||||
EOS
|
||||
|
||||
corrected_source = <<~EOS
|
||||
class Foo < Formula
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
end
|
||||
EOS
|
||||
|
||||
new_source = autocorrect_source(source)
|
||||
expect(new_source).to eq(corrected_source)
|
||||
end
|
||||
end
|
||||
|
||||
describe RuboCop::Cop::FormulaAuditStrict::Test do
|
||||
subject(:cop) { described_class.new }
|
||||
|
||||
context "When auditing formula" do
|
||||
it "without a test block" do
|
||||
source = <<~EOS
|
||||
class Foo < Formula
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
end
|
||||
EOS
|
||||
expected_offenses = [{ message: described_class::MSG,
|
||||
severity: :convention,
|
||||
line: 1,
|
||||
column: 0,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
it "reports an offense when there is no test block" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
^^^^^^^^^^^^^^^^^^^ A `test do` test block should be added
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,6 +1,3 @@
|
||||
require "rubocop"
|
||||
require "rubocop/rspec/support"
|
||||
require_relative "../../extend/string"
|
||||
require_relative "../../rubocops/components_order_cop"
|
||||
|
||||
describe RuboCop::Cop::FormulaAuditStrict::ComponentsOrder do
|
||||
@ -8,28 +5,17 @@ describe RuboCop::Cop::FormulaAuditStrict::ComponentsOrder do
|
||||
|
||||
context "When auditing formula components order" do
|
||||
it "When url precedes homepage" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url "http://example.com/foo-1.0.tgz"
|
||||
homepage "http://example.com"
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `homepage` (line 3) should be put before `url` (line 2)
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "`homepage` (line 3) should be put before `url` (line 2)",
|
||||
severity: :convention,
|
||||
line: 3,
|
||||
column: 2,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "When `resource` precedes `depends_on`" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url "https://example.com/foo-1.0.tgz"
|
||||
|
||||
@ -38,24 +24,13 @@ describe RuboCop::Cop::FormulaAuditStrict::ComponentsOrder do
|
||||
end
|
||||
|
||||
depends_on "openssl"
|
||||
^^^^^^^^^^^^^^^^^^^^ `depends_on` (line 8) should be put before `resource` (line 4)
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "`depends_on` (line 8) should be put before `resource` (line 4)",
|
||||
severity: :convention,
|
||||
line: 8,
|
||||
column: 2,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "When `test` precedes `plist`" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url "https://example.com/foo-1.0.tgz"
|
||||
|
||||
@ -64,53 +39,24 @@ describe RuboCop::Cop::FormulaAuditStrict::ComponentsOrder do
|
||||
end
|
||||
|
||||
def plist
|
||||
^^^^^^^^^ `plist` (line 8) should be put before `test` (line 4)
|
||||
end
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "`plist` (line 8) should be put before `test` (line 4)",
|
||||
severity: :convention,
|
||||
line: 8,
|
||||
column: 2,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "When only one of many `depends_on` precedes `conflicts_with`" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
depends_on "autoconf" => :build
|
||||
conflicts_with "visionmedia-watch"
|
||||
depends_on "automake" => :build
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `depends_on` (line 4) should be put before `conflicts_with` (line 3)
|
||||
depends_on "libtool" => :build
|
||||
depends_on "pkg-config" => :build
|
||||
depends_on "gettext"
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "`depends_on` (line 4) should be put before `conflicts_with` (line 3)",
|
||||
severity: :convention,
|
||||
line: 4,
|
||||
column: 2,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
end
|
||||
|
||||
def expect_offense(expected, actual)
|
||||
expect(actual.message).to eq(expected[:message])
|
||||
expect(actual.severity).to eq(expected[:severity])
|
||||
expect(actual.line).to eq(expected[:line])
|
||||
expect(actual.column).to eq(expected[:column])
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
||||
@ -122,6 +68,7 @@ describe RuboCop::Cop::FormulaAuditStrict::ComponentsOrder do
|
||||
homepage "http://example.com"
|
||||
end
|
||||
EOS
|
||||
|
||||
correct_source = <<~EOS
|
||||
class Foo < Formula
|
||||
homepage "http://example.com"
|
||||
@ -145,6 +92,7 @@ describe RuboCop::Cop::FormulaAuditStrict::ComponentsOrder do
|
||||
depends_on "openssl"
|
||||
end
|
||||
EOS
|
||||
|
||||
correct_source = <<~EOS
|
||||
class Foo < Formula
|
||||
url "https://example.com/foo-1.0.tgz"
|
||||
@ -156,6 +104,7 @@ describe RuboCop::Cop::FormulaAuditStrict::ComponentsOrder do
|
||||
end
|
||||
end
|
||||
EOS
|
||||
|
||||
corrected_source = autocorrect_source(source)
|
||||
expect(corrected_source).to eq(correct_source)
|
||||
end
|
||||
|
||||
@ -1,6 +1,3 @@
|
||||
require "rubocop"
|
||||
require "rubocop/rspec/support"
|
||||
require_relative "../../extend/string"
|
||||
require_relative "../../rubocops/components_redundancy_cop"
|
||||
|
||||
describe RuboCop::Cop::FormulaAuditStrict::ComponentsRedundancy do
|
||||
@ -8,80 +5,40 @@ describe RuboCop::Cop::FormulaAuditStrict::ComponentsRedundancy do
|
||||
|
||||
context "When auditing formula components common errors" do
|
||||
it "When url outside stable block" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url "http://example.com/foo-1.0.tgz"
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `url` should be put inside `stable` block
|
||||
stable do
|
||||
# stuff
|
||||
end
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "`url` should be put inside `stable` block",
|
||||
severity: :convention,
|
||||
line: 2,
|
||||
column: 2,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "When both `head` and `head do` are present" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
head "http://example.com/foo.git"
|
||||
head do
|
||||
^^^^^^^ `head` and `head do` should not be simultaneously present
|
||||
# stuff
|
||||
end
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "`head` and `head do` should not be simultaneously present",
|
||||
severity: :convention,
|
||||
line: 3,
|
||||
column: 2,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "When both `bottle :modifier` and `bottle do` are present" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url "http://example.com/foo-1.0.tgz"
|
||||
bottle do
|
||||
^^^^^^^^^ `bottle :modifier` and `bottle do` should not be simultaneously present
|
||||
# bottles go here
|
||||
end
|
||||
bottle :unneeded
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "`bottle :modifier` and `bottle do` should not be simultaneously present",
|
||||
severity: :convention,
|
||||
line: 3,
|
||||
column: 2,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
end
|
||||
|
||||
def expect_offense(expected, actual)
|
||||
expect(actual.message).to eq(expected[:message])
|
||||
expect(actual.severity).to eq(expected[:severity])
|
||||
expect(actual.line).to eq(expected[:line])
|
||||
expect(actual.column).to eq(expected[:column])
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,6 +1,3 @@
|
||||
require "rubocop"
|
||||
require "rubocop/rspec/support"
|
||||
require_relative "../../extend/string"
|
||||
require_relative "../../rubocops/conflicts_cop"
|
||||
|
||||
describe RuboCop::Cop::FormulaAudit::Conflicts do
|
||||
@ -8,36 +5,23 @@ describe RuboCop::Cop::FormulaAudit::Conflicts do
|
||||
|
||||
context "When auditing formula for conflicts with" do
|
||||
it "multiple conflicts_with" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo@2.0.rb")
|
||||
class FooAT20 < Formula
|
||||
url 'http://example.com/foo-2.0.tgz'
|
||||
conflicts_with "mysql", "mariadb", "percona-server",
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Versioned formulae should not use `conflicts_with`. Use `keg_only :versioned_formula` instead.
|
||||
:because => "both install plugins"
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: described_class::MSG,
|
||||
severity: :convention,
|
||||
line: 3,
|
||||
column: 2,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source, "/homebrew-core/Formula/foo@2.0.rb")
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "no conflicts_with" do
|
||||
source = <<~EOS
|
||||
expect_no_offenses(<<~RUBY, "/homebrew-core/Formula/foo@2.0.rb")
|
||||
class FooAT20 < Formula
|
||||
url 'http://example.com/foo-2.0.tgz'
|
||||
desc 'Bar'
|
||||
end
|
||||
EOS
|
||||
inspect_source(source, "/homebrew-core/Formula/foo@2.0.rb")
|
||||
expect(cop.offenses).to eq([])
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,6 +1,3 @@
|
||||
require "rubocop"
|
||||
require "rubocop/rspec/support"
|
||||
require_relative "../../extend/string"
|
||||
require_relative "../../rubocops/formula_desc_cop"
|
||||
|
||||
describe RuboCop::Cop::FormulaAuditStrict::DescLength do
|
||||
@ -8,93 +5,43 @@ describe RuboCop::Cop::FormulaAuditStrict::DescLength do
|
||||
|
||||
context "When auditing formula desc" do
|
||||
it "When there is no desc" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
^^^^^^^^^^^^^^^^^^^ Formula should have a desc (Description).
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "Formula should have a desc (Description).",
|
||||
severity: :convention,
|
||||
line: 1,
|
||||
column: 0,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "reports an offense when desc is an empty string" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
|
||||
class Foo < Formula
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
desc ''
|
||||
^^^^^^^ The desc (description) should not be an empty string.
|
||||
end
|
||||
EOS
|
||||
|
||||
msg = "The desc (description) should not be an empty string."
|
||||
expected_offenses = [{ message: msg,
|
||||
severity: :convention,
|
||||
line: 3,
|
||||
column: 2,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source, "/homebrew-core/Formula/foo.rb")
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "When desc is too long" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
|
||||
class Foo < Formula
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
desc 'Bar#{"bar" * 29}'
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Description is too long. "name: desc" should be less than 80 characters. Length is calculated as foo + desc. (currently 95)
|
||||
end
|
||||
EOS
|
||||
|
||||
msg = <<~EOS
|
||||
Description is too long. "name: desc" should be less than 80 characters.
|
||||
Length is calculated as foo + desc. (currently 95)
|
||||
EOS
|
||||
expected_offenses = [{ message: msg,
|
||||
severity: :convention,
|
||||
line: 3,
|
||||
column: 2,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source, "/homebrew-core/Formula/foo.rb")
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "When desc is multiline string" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
|
||||
class Foo < Formula
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
desc 'Bar#{"bar" * 9}'\
|
||||
'#{"foo" * 21}'
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Description is too long. "name: desc" should be less than 80 characters. Length is calculated as foo + desc. (currently 98)
|
||||
end
|
||||
EOS
|
||||
|
||||
msg = <<~EOS
|
||||
Description is too long. "name: desc" should be less than 80 characters.
|
||||
Length is calculated as foo + desc. (currently 98)
|
||||
EOS
|
||||
expected_offenses = [{ message: msg,
|
||||
severity: :convention,
|
||||
line: 3,
|
||||
column: 2,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source, "/homebrew-core/Formula/foo.rb")
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -104,83 +51,44 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do
|
||||
|
||||
context "When auditing formula desc" do
|
||||
it "When wrong \"command-line\" usage in desc" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
|
||||
class Foo < Formula
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
desc 'command line'
|
||||
^ Description should start with a capital letter
|
||||
^^^^^^^^^^^^ Description should use \"command-line\" instead of \"command line\"
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "Description should use \"command-line\" instead of \"command line\"",
|
||||
severity: :convention,
|
||||
line: 3,
|
||||
column: 8,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "When an article is used in desc" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
|
||||
class Foo < Formula
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
desc 'An '
|
||||
^^^ Description shouldn\'t start with an indefinite article i.e. \"An\"
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "Description shouldn't start with an indefinite article i.e. \"An\"",
|
||||
severity: :convention,
|
||||
line: 3,
|
||||
column: 8,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "When an lowercase letter starts a desc" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
|
||||
class Foo < Formula
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
desc 'bar'
|
||||
^ Description should start with a capital letter
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "Description should start with a capital letter",
|
||||
severity: :convention,
|
||||
line: 3,
|
||||
column: 8,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "When formula name is in desc" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb")
|
||||
class Foo < Formula
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
desc 'Foo is a foobar'
|
||||
^^^^ Description shouldn\'t start with the formula name
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "Description shouldn't start with the formula name",
|
||||
severity: :convention,
|
||||
line: 3,
|
||||
column: 8,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source, "/homebrew-core/Formula/foo.rb")
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "autocorrects all rules" do
|
||||
@ -190,6 +98,7 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do
|
||||
desc ' an bar: commandline foo '
|
||||
end
|
||||
EOS
|
||||
|
||||
correct_source = <<~EOS
|
||||
class Foo < Formula
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
|
||||
@ -1,6 +1,3 @@
|
||||
require "rubocop"
|
||||
require "rubocop/rspec/support"
|
||||
require_relative "../../extend/string"
|
||||
require_relative "../../rubocops/homepage_cop"
|
||||
|
||||
describe RuboCop::Cop::FormulaAudit::Homepage do
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,32 +1,16 @@
|
||||
require "rubocop"
|
||||
require "rubocop/rspec/support"
|
||||
require_relative "../../extend/string"
|
||||
require_relative "../../rubocops/options_cop"
|
||||
|
||||
describe RuboCop::Cop::FormulaAudit::Options do
|
||||
subject(:cop) { described_class.new }
|
||||
|
||||
context "When auditing options" do
|
||||
it "32-bit" do
|
||||
source = <<~EOS
|
||||
class Foo < Formula
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
option "32-bit", "with 32-bit"
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: described_class::DEPRECATION_MSG,
|
||||
severity: :convention,
|
||||
line: 3,
|
||||
column: 10,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
it "reports an offense when using the 32-bit option" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
option "32-bit", "with 32-bit"
|
||||
^^^^^^ macOS has been 64-bit only since 10.6 so 32-bit options are deprecated.
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
||||
@ -35,71 +19,34 @@ describe RuboCop::Cop::FormulaAuditStrict::Options do
|
||||
|
||||
context "When auditing options strictly" do
|
||||
it "with universal" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
option :universal
|
||||
^^^^^^^^^^^^^^^^^ macOS has been 64-bit only since 10.6 so universal options are deprecated.
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: described_class::DEPRECATION_MSG,
|
||||
severity: :convention,
|
||||
line: 3,
|
||||
column: 2,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "with deprecated options" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
option :cxx11
|
||||
option "examples", "with-examples"
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Options should begin with with/without. Migrate '--examples' with `deprecated_option`.
|
||||
end
|
||||
EOS
|
||||
|
||||
MSG_1 = "Options should begin with with/without."\
|
||||
" Migrate '--examples' with `deprecated_option`.".freeze
|
||||
expected_offenses = [{ message: MSG_1,
|
||||
severity: :convention,
|
||||
line: 4,
|
||||
column: 2,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "with misc deprecated options" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
option "without-check"
|
||||
^^^^^^^^^^^^^^^^^^^^^^ Use '--without-test' instead of '--without-check'. Migrate '--without-check' with `deprecated_option`.
|
||||
end
|
||||
EOS
|
||||
|
||||
MSG_2 = "Use '--without-test' instead of '--without-check'."\
|
||||
" Migrate '--without-check' with `deprecated_option`.".freeze
|
||||
expected_offenses = [{ message: MSG_2,
|
||||
severity: :convention,
|
||||
line: 3,
|
||||
column: 2,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -109,24 +56,13 @@ describe RuboCop::Cop::NewFormulaAudit::Options do
|
||||
|
||||
context "When auditing options for a new formula" do
|
||||
it "with deprecated options" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
deprecated_option "examples" => "with-examples"
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ New Formula should not use `deprecated_option`
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: described_class::MSG,
|
||||
severity: :convention,
|
||||
line: 3,
|
||||
column: 2,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,6 +1,3 @@
|
||||
require "rubocop"
|
||||
require "rubocop/rspec/support"
|
||||
require_relative "../../extend/string"
|
||||
require_relative "../../rubocops/patches_cop"
|
||||
|
||||
describe RuboCop::Cop::FormulaAudit::Patches do
|
||||
@ -8,37 +5,24 @@ describe RuboCop::Cop::FormulaAudit::Patches do
|
||||
|
||||
context "When auditing legacy patches" do
|
||||
it "When there is no legacy patch" do
|
||||
source = <<~EOS
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
end
|
||||
EOS
|
||||
inspect_source(source)
|
||||
expect(cop.offenses).to eq([])
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "Formula with `def patches`" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
homepage "ftp://example.com/foo"
|
||||
url "http://example.com/foo-1.0.tgz"
|
||||
def patches
|
||||
^^^^^^^^^^^ Use the patch DSL instead of defining a 'patches' method
|
||||
DATA
|
||||
end
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "Use the patch DSL instead of defining a 'patches' method",
|
||||
severity: :convention,
|
||||
line: 4,
|
||||
column: 2,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "Patch URLs" do
|
||||
@ -120,7 +104,10 @@ describe RuboCop::Cop::FormulaAudit::Patches do
|
||||
source: source }]
|
||||
end
|
||||
expected_offense.zip([cop.offenses.last]).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
expect(actual.message).to eq(expected[:message])
|
||||
expect(actual.severity).to eq(expected[:severity])
|
||||
expect(actual.line).to eq(expected[:line])
|
||||
expect(actual.column).to eq(expected[:column])
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -157,7 +144,10 @@ describe RuboCop::Cop::FormulaAudit::Patches do
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
expect(actual.message).to eq(expected[:message])
|
||||
expect(actual.severity).to eq(expected[:severity])
|
||||
expect(actual.line).to eq(expected[:line])
|
||||
expect(actual.column).to eq(expected[:column])
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -233,7 +223,10 @@ describe RuboCop::Cop::FormulaAudit::Patches do
|
||||
source: source }]
|
||||
end
|
||||
expected_offense.zip([cop.offenses.last]).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
expect(actual.message).to eq(expected[:message])
|
||||
expect(actual.severity).to eq(expected[:severity])
|
||||
expect(actual.line).to eq(expected[:line])
|
||||
expect(actual.column).to eq(expected[:column])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,6 +1,3 @@
|
||||
require "rubocop"
|
||||
require "rubocop/rspec/support"
|
||||
require_relative "../../extend/string"
|
||||
require_relative "../../rubocops/text_cop"
|
||||
|
||||
describe RuboCop::Cop::FormulaAudit::Text do
|
||||
@ -8,189 +5,114 @@ describe RuboCop::Cop::FormulaAudit::Text do
|
||||
|
||||
context "When auditing formula text" do
|
||||
it "with both openssl and libressl optional dependencies" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url "http://example.com/foo-1.0.tgz"
|
||||
homepage "http://example.com"
|
||||
|
||||
depends_on "openssl"
|
||||
depends_on "libressl" => :optional
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Formulae should not depend on both OpenSSL and LibreSSL (even optionally).
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "Formulae should not depend on both OpenSSL and LibreSSL (even optionally).",
|
||||
severity: :convention,
|
||||
line: 6,
|
||||
column: 2,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "with both openssl and libressl dependencies" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url "http://example.com/foo-1.0.tgz"
|
||||
homepage "http://example.com"
|
||||
|
||||
depends_on "openssl"
|
||||
depends_on "libressl"
|
||||
^^^^^^^^^^^^^^^^^^^^^ Formulae should not depend on both OpenSSL and LibreSSL (even optionally).
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "Formulae should not depend on both OpenSSL and LibreSSL (even optionally).",
|
||||
severity: :convention,
|
||||
line: 6,
|
||||
column: 2,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "When xcodebuild is called without SYMROOT" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url "http://example.com/foo-1.0.tgz"
|
||||
homepage "http://example.com"
|
||||
|
||||
def install
|
||||
xcodebuild "-project", "meow.xcodeproject"
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ xcodebuild should be passed an explicit \"SYMROOT\"
|
||||
end
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "xcodebuild should be passed an explicit \"SYMROOT\"",
|
||||
severity: :convention,
|
||||
line: 6,
|
||||
column: 4,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "When xcodebuild is called without any args" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url "http://example.com/foo-1.0.tgz"
|
||||
homepage "http://example.com"
|
||||
|
||||
def install
|
||||
xcodebuild
|
||||
^^^^^^^^^^ xcodebuild should be passed an explicit \"SYMROOT\"
|
||||
end
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "xcodebuild should be passed an explicit \"SYMROOT\"",
|
||||
severity: :convention,
|
||||
line: 6,
|
||||
column: 4,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "When go get is executed" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url "http://example.com/foo-1.0.tgz"
|
||||
homepage "http://example.com"
|
||||
|
||||
def install
|
||||
system "go", "get", "bar"
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^ Formulae should not use `go get`. If non-vendored resources are required use `go_resource`s.
|
||||
end
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "Formulae should not use `go get`. If non-vendored resources are required use `go_resource`s.",
|
||||
severity: :convention,
|
||||
line: 6,
|
||||
column: 4,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "When xcodebuild is executed" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url "http://example.com/foo-1.0.tgz"
|
||||
homepage "http://example.com"
|
||||
|
||||
def install
|
||||
system "xcodebuild", "foo", "bar"
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use \"xcodebuild *args\" instead of \"system 'xcodebuild', *args\"
|
||||
end
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "use \"xcodebuild *args\" instead of \"system 'xcodebuild', *args\"",
|
||||
severity: :convention,
|
||||
line: 6,
|
||||
column: 4,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "When scons is executed" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url "http://example.com/foo-1.0.tgz"
|
||||
homepage "http://example.com"
|
||||
|
||||
def install
|
||||
system "scons", "foo", "bar"
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use \"scons *args\" instead of \"system 'scons', *args\"
|
||||
end
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "use \"scons *args\" instead of \"system 'scons', *args\"",
|
||||
severity: :convention,
|
||||
line: 6,
|
||||
column: 4,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "When plist_options are not defined when using a formula-defined plist", :ruby23 do
|
||||
source = <<~RUBY
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url "http://example.com/foo-1.0.tgz"
|
||||
homepage "http://example.com"
|
||||
|
||||
def install
|
||||
system "xcodebuild", "foo", "bar"
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use \"xcodebuild *args\" instead of \"system 'xcodebuild', *args\"
|
||||
end
|
||||
|
||||
def plist
|
||||
^^^^^^^^^ Please set plist_options when using a formula-defined plist.
|
||||
<<~XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
@ -204,23 +126,12 @@ describe RuboCop::Cop::FormulaAudit::Text do
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
|
||||
expected_offenses = [{ message: "Please set plist_options when using a formula-defined plist.",
|
||||
severity: :convention,
|
||||
line: 9,
|
||||
column: 2,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
end
|
||||
|
||||
it "When language/go is require'd" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
require "language/go"
|
||||
^^^^^^^^^^^^^^^^^^^^^ require "language/go" is unnecessary unless using `go_resource`s
|
||||
|
||||
class Foo < Formula
|
||||
url "http://example.com/foo-1.0.tgz"
|
||||
@ -228,30 +139,20 @@ describe RuboCop::Cop::FormulaAudit::Text do
|
||||
|
||||
def install
|
||||
system "go", "get", "bar"
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^ Formulae should not use `go get`. If non-vendored resources are required use `go_resource`s.
|
||||
end
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "require \"language/go\" is unnecessary unless using `go_resource`s",
|
||||
severity: :convention,
|
||||
line: 1,
|
||||
column: 0,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "When formula uses virtualenv and also `setuptools` resource" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url "http://example.com/foo-1.0.tgz"
|
||||
homepage "http://example.com"
|
||||
|
||||
resource "setuptools" do
|
||||
^^^^^^^^^^^^^^^^^^^^^ Formulae using virtualenvs do not need a `setuptools` resource.
|
||||
url "https://foo.com/foo.tar.gz"
|
||||
sha256 "db0904a28253cfe53e7dedc765c71596f3c53bb8a866ae50123320ec1a7b73fd"
|
||||
end
|
||||
@ -260,51 +161,21 @@ describe RuboCop::Cop::FormulaAudit::Text do
|
||||
virtualenv_create(libexec)
|
||||
end
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "Formulae using virtualenvs do not need a `setuptools` resource.",
|
||||
severity: :convention,
|
||||
line: 5,
|
||||
column: 2,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "When Formula.factory(name) is used" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url "http://example.com/foo-1.0.tgz"
|
||||
homepage "http://example.com"
|
||||
|
||||
def install
|
||||
Formula.factory(name)
|
||||
^^^^^^^^^^^^^^^^^^^^^ \"Formula.factory(name)\" is deprecated in favor of \"Formula[name]\"
|
||||
end
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "\"Formula.factory(name)\" is deprecated in favor of \"Formula[name]\"",
|
||||
severity: :convention,
|
||||
line: 6,
|
||||
column: 4,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
end
|
||||
|
||||
def expect_offense(expected, actual)
|
||||
expect(actual.message).to eq(expected[:message])
|
||||
expect(actual.severity).to eq(expected[:severity])
|
||||
expect(actual.line).to eq(expected[:line])
|
||||
expect(actual.column).to eq(expected[:column])
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,6 +1,3 @@
|
||||
require "rubocop"
|
||||
require "rubocop/rspec/support"
|
||||
require_relative "../../extend/string"
|
||||
require_relative "../../rubocops/urls_cop"
|
||||
|
||||
describe RuboCop::Cop::FormulaAudit::Urls do
|
||||
@ -129,65 +126,40 @@ describe RuboCop::Cop::FormulaAudit::Urls do
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses.reverse).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
expect(actual.message).to eq(expected[:message])
|
||||
expect(actual.severity).to eq(expected[:severity])
|
||||
expect(actual.line).to eq(expected[:line])
|
||||
expect(actual.column).to eq(expected[:column])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "with offenses in stable/devel/head block" do
|
||||
formulas = [{
|
||||
"url" => "git://github.com/foo.git",
|
||||
"msg" => "Please use https:// for git://github.com/foo.git",
|
||||
"col" => 4,
|
||||
}]
|
||||
formulas.each do |formula|
|
||||
source = <<~EOS
|
||||
class Foo < Formula
|
||||
desc "foo"
|
||||
url "https://foo.com"
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
desc "foo"
|
||||
url "https://foo.com"
|
||||
|
||||
devel do
|
||||
url "#{formula["url"]}",
|
||||
:tag => "v1.0.0-alpha.1",
|
||||
:revision => "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
version "1.0.0-alpha.1"
|
||||
end
|
||||
devel do
|
||||
url "git://github.com/foo.git",
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Please use https:// for git://github.com/foo.git
|
||||
:tag => "v1.0.0-alpha.1",
|
||||
:revision => "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
version "1.0.0-alpha.1"
|
||||
end
|
||||
EOS
|
||||
expected_offenses = [{ message: formula["msg"],
|
||||
severity: :convention,
|
||||
line: 6,
|
||||
column: formula["col"],
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses.reverse).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "with duplicate mirror" do
|
||||
source = <<~EOS
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
desc "foo"
|
||||
url "https://ftpmirror.fnu.org/foo/foo-1.0.tar.gz"
|
||||
mirror "https://ftpmirror.fnu.org/foo/foo-1.0.tar.gz"
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ URL should not be duplicated as a mirror: https://ftpmirror.fnu.org/foo/foo-1.0.tar.gz
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "URL should not be duplicated as a mirror: https://ftpmirror.fnu.org/foo/foo-1.0.tar.gz",
|
||||
severity: :convention,
|
||||
line: 4,
|
||||
column: 2,
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
|
||||
expected_offenses.zip(cop.offenses.reverse).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -195,42 +167,31 @@ end
|
||||
describe RuboCop::Cop::FormulaAuditStrict::PyPiUrls do
|
||||
subject(:cop) { described_class.new }
|
||||
|
||||
context "When auditing urls" do
|
||||
it "with pypi offenses" do
|
||||
formulas = [{
|
||||
"url" => "https://pypi.python.org/packages/source/foo/foo-0.1.tar.gz",
|
||||
"msg" => "https://pypi.python.org/packages/source/foo/foo-0.1.tar.gz should be `https://files.pythonhosted.org/packages/source/foo/foo-0.1.tar.gz`",
|
||||
"col" => 2,
|
||||
"corrected_url" =>"https://files.pythonhosted.org/packages/source/foo/foo-0.1.tar.gz",
|
||||
}]
|
||||
formulas.each do |formula|
|
||||
source = <<~EOS
|
||||
class Foo < Formula
|
||||
desc "foo"
|
||||
url "#{formula["url"]}"
|
||||
end
|
||||
EOS
|
||||
corrected_source = <<~EOS
|
||||
class Foo < Formula
|
||||
desc "foo"
|
||||
url "#{formula["corrected_url"]}"
|
||||
end
|
||||
EOS
|
||||
expected_offenses = [{ message: formula["msg"],
|
||||
severity: :convention,
|
||||
line: 3,
|
||||
column: formula["col"],
|
||||
source: source }]
|
||||
|
||||
inspect_source(source)
|
||||
# Check for expected offenses
|
||||
expected_offenses.zip(cop.offenses.reverse).each do |expected, actual|
|
||||
expect_offense(expected, actual)
|
||||
context "when a pypi.python.org URL is used" do
|
||||
it "reports an offense" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
desc "foo"
|
||||
url "https://pypi.python.org/packages/source/foo/foo-0.1.tar.gz"
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ https://pypi.python.org/packages/source/foo/foo-0.1.tar.gz should be `https://files.pythonhosted.org/packages/source/foo/foo-0.1.tar.gz`
|
||||
end
|
||||
# Check for expected auto corrected source
|
||||
new_source = autocorrect_source(source)
|
||||
expect(new_source).to eq(corrected_source)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "support auto-correction" do
|
||||
corrected = autocorrect_source(<<~RUBY)
|
||||
class Foo < Formula
|
||||
desc "foo"
|
||||
url "https://pypi.python.org/packages/source/foo/foo-0.1.tar.gz"
|
||||
end
|
||||
RUBY
|
||||
|
||||
expect(corrected).to eq <<~RUBY
|
||||
class Foo < Formula
|
||||
desc "foo"
|
||||
url "https://files.pythonhosted.org/packages/source/foo/foo-0.1.tar.gz"
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -2,6 +2,8 @@ require "find"
|
||||
require "pathname"
|
||||
require "rspec/its"
|
||||
require "rspec/wait"
|
||||
require "rubocop"
|
||||
require "rubocop/rspec/support"
|
||||
require "set"
|
||||
|
||||
if ENV["HOMEBREW_TESTS_COVERAGE"]
|
||||
@ -23,7 +25,6 @@ require "test/support/helper/fixtures"
|
||||
require "test/support/helper/formula"
|
||||
require "test/support/helper/mktmpdir"
|
||||
require "test/support/helper/output_as_tty"
|
||||
require "test/support/helper/rubocop"
|
||||
|
||||
require "test/support/helper/spec/shared_context/homebrew_cask" if OS.mac?
|
||||
require "test/support/helper/spec/shared_context/integration_test"
|
||||
@ -43,11 +44,14 @@ RSpec.configure do |config|
|
||||
|
||||
config.filter_run_when_matching :focus
|
||||
|
||||
config.include(FileUtils)
|
||||
|
||||
config.include(RuboCop::RSpec::ExpectOffense)
|
||||
|
||||
config.include(Test::Helper::Fixtures)
|
||||
config.include(Test::Helper::Formula)
|
||||
config.include(Test::Helper::MkTmpDir)
|
||||
config.include(Test::Helper::OutputAsTTY)
|
||||
config.include(Test::Helper::RuboCop)
|
||||
|
||||
config.before(:each, :needs_compat) do
|
||||
skip "Requires compatibility layer." if ENV["HOMEBREW_NO_COMPAT"]
|
||||
|
||||
@ -1,13 +0,0 @@
|
||||
module Test
|
||||
module Helper
|
||||
module RuboCop
|
||||
def expect_offense(expected, actual)
|
||||
expect(actual).to_not be_nil
|
||||
expect(actual.message).to eq(expected[:message])
|
||||
expect(actual.severity).to eq(expected[:severity])
|
||||
expect(actual.line).to eq(expected[:line])
|
||||
expect(actual.column).to eq(expected[:column])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -1,6 +1,4 @@
|
||||
describe Tap do
|
||||
include FileUtils
|
||||
|
||||
alias_matcher :have_formula_file, :be_formula_file
|
||||
alias_matcher :have_custom_remote, :be_custom_remote
|
||||
|
||||
@ -307,8 +305,6 @@ describe Tap do
|
||||
end
|
||||
|
||||
describe CoreTap do
|
||||
include FileUtils
|
||||
|
||||
specify "attributes" do
|
||||
expect(subject.user).to eq("Homebrew")
|
||||
expect(subject.repo).to eq("core")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user