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