mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Refactor RuboCop tests.
This commit is contained in:
parent
82dc1d25ef
commit
02dbeb62fc
@ -23,7 +23,7 @@ module RuboCop
|
|||||||
extend AutoCorrector
|
extend AutoCorrector
|
||||||
include CaskHelp
|
include CaskHelp
|
||||||
|
|
||||||
MESSAGE = "Use `%<preferred>s` instead of `%<current>s`"
|
MESSAGE = "Use `%<preferred>s` instead of `%<current>s`."
|
||||||
|
|
||||||
def on_cask(cask_block)
|
def on_cask(cask_block)
|
||||||
@cask_header = cask_block.header
|
@cask_header = cask_block.header
|
||||||
|
@ -13,10 +13,9 @@ module RuboCop
|
|||||||
:appcast, :arch, :auto_updates, :conflicts_with, :container,
|
:appcast, :arch, :auto_updates, :conflicts_with, :container,
|
||||||
:desc, :homepage, :sha256, :url, :version
|
:desc, :homepage, :sha256, :url, :version
|
||||||
].freeze
|
].freeze
|
||||||
MESSAGE = <<~EOS
|
MESSAGE = "Do not use a top-level `%<stanza>s` stanza as the default. " \
|
||||||
Do not use a top-level `%<stanza>s` stanza as the default. Add it to an `on_{system}` block instead.
|
"Add it to an `on_{system}` block instead. " \
|
||||||
Use `:or_older` or `:or_newer` to specify a range of macOS versions.
|
"Use `:or_older` or `:or_newer` to specify a range of macOS versions."
|
||||||
EOS
|
|
||||||
|
|
||||||
def on_cask(cask_block)
|
def on_cask(cask_block)
|
||||||
cask_stanzas = cask_block.toplevel_stanzas
|
cask_stanzas = cask_block.toplevel_stanzas
|
||||||
|
@ -4,13 +4,13 @@
|
|||||||
module RuboCop
|
module RuboCop
|
||||||
module Cop
|
module Cop
|
||||||
module Cask
|
module Cask
|
||||||
# This cop checks for version.before_comma and version.after_comma
|
# This cop checks for `version.before_comma` and `version.after_comma`.
|
||||||
class UrlLegacyCommaSeparators < Url
|
class UrlLegacyCommaSeparators < Url
|
||||||
include OnUrlStanza
|
include OnUrlStanza
|
||||||
extend AutoCorrector
|
extend AutoCorrector
|
||||||
|
|
||||||
MSG_CSV = "Use 'version.csv.first' instead of 'version.before_comma' " \
|
MSG_CSV = "Use `version.csv.first` instead of `version.before_comma` " \
|
||||||
"and 'version.csv.second' instead of 'version.after_comma'"
|
"and `version.csv.second` instead of `version.after_comma`."
|
||||||
|
|
||||||
def on_url_stanza(stanza)
|
def on_url_stanza(stanza)
|
||||||
return if stanza.stanza_node.type == :block
|
return if stanza.stanza_node.type == :block
|
||||||
|
@ -50,7 +50,7 @@ module RuboCop
|
|||||||
replacement_parameters << "intel: #{intel_node.source}" unless blank_node?(intel_node)
|
replacement_parameters << "intel: #{intel_node.source}" unless blank_node?(intel_node)
|
||||||
replacement_string += replacement_parameters.join(", ")
|
replacement_string += replacement_parameters.join(", ")
|
||||||
|
|
||||||
add_offense(node, message: "Use `#{replacement_string}` instead of `#{node.source}`") do |corrector|
|
add_offense(node, message: "Use `#{replacement_string}` instead of `#{node.source}`.") do |corrector|
|
||||||
corrector.replace(node, replacement_string)
|
corrector.replace(node, replacement_string)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "rubocops/rubocop-cask"
|
require "rubocops/rubocop-cask"
|
||||||
require "test/rubocops/cask/shared_examples/cask_cop"
|
|
||||||
|
|
||||||
describe RuboCop::Cop::Cask::Desc do
|
|
||||||
subject(:cop) { described_class.new }
|
|
||||||
|
|
||||||
|
describe RuboCop::Cop::Cask::Desc, :config do
|
||||||
it "does not start with an article" do
|
it "does not start with an article" do
|
||||||
expect_no_offenses <<~RUBY
|
expect_no_offenses <<~RUBY
|
||||||
cask "foo" do
|
cask "foo" do
|
||||||
@ -16,14 +13,14 @@ describe RuboCop::Cop::Cask::Desc do
|
|||||||
expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb"
|
expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb"
|
||||||
cask 'foo' do
|
cask 'foo' do
|
||||||
desc 'A bar program'
|
desc 'A bar program'
|
||||||
^ Cask/Desc: Description shouldn't start with an article.
|
^ Description shouldn't start with an article.
|
||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
|
|
||||||
expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb"
|
expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb"
|
||||||
cask 'foo' do
|
cask 'foo' do
|
||||||
desc 'The bar program'
|
desc 'The bar program'
|
||||||
^^^ Cask/Desc: Description shouldn't start with an article.
|
^^^ Description shouldn't start with an article.
|
||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
|
|
||||||
@ -38,35 +35,35 @@ describe RuboCop::Cop::Cask::Desc do
|
|||||||
expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb"
|
expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb"
|
||||||
cask 'foobar' do
|
cask 'foobar' do
|
||||||
desc 'Foo bar program'
|
desc 'Foo bar program'
|
||||||
^^^^^^^ Cask/Desc: Description shouldn't start with the cask name.
|
^^^^^^^ Description shouldn't start with the cask name.
|
||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
|
|
||||||
expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb"
|
expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb"
|
||||||
cask 'foobar' do
|
cask 'foobar' do
|
||||||
desc 'Foo-Bar program'
|
desc 'Foo-Bar program'
|
||||||
^^^^^^^ Cask/Desc: Description shouldn't start with the cask name.
|
^^^^^^^ Description shouldn't start with the cask name.
|
||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
|
|
||||||
expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb"
|
expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb"
|
||||||
cask 'foo-bar' do
|
cask 'foo-bar' do
|
||||||
desc 'Foo bar program'
|
desc 'Foo bar program'
|
||||||
^^^^^^^ Cask/Desc: Description shouldn't start with the cask name.
|
^^^^^^^ Description shouldn't start with the cask name.
|
||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
|
|
||||||
expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb"
|
expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb"
|
||||||
cask 'foo-bar' do
|
cask 'foo-bar' do
|
||||||
desc 'Foo-Bar program'
|
desc 'Foo-Bar program'
|
||||||
^^^^^^^ Cask/Desc: Description shouldn't start with the cask name.
|
^^^^^^^ Description shouldn't start with the cask name.
|
||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
|
|
||||||
expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb"
|
expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb"
|
||||||
cask 'foo-bar' do
|
cask 'foo-bar' do
|
||||||
desc 'Foo Bar'
|
desc 'Foo Bar'
|
||||||
^^^^^^^ Cask/Desc: Description shouldn't start with the cask name.
|
^^^^^^^ Description shouldn't start with the cask name.
|
||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
end
|
end
|
||||||
@ -75,28 +72,28 @@ describe RuboCop::Cop::Cask::Desc do
|
|||||||
expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb"
|
expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb"
|
||||||
cask 'foo-bar' do
|
cask 'foo-bar' do
|
||||||
desc 'macOS status bar monitor'
|
desc 'macOS status bar monitor'
|
||||||
^^^^^ Cask/Desc: Description shouldn't contain the platform.
|
^^^^^ Description shouldn't contain the platform.
|
||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
|
|
||||||
expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb"
|
expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb"
|
||||||
cask 'foo-bar' do
|
cask 'foo-bar' do
|
||||||
desc 'Toggles dark mode on Mac OS Mojave'
|
desc 'Toggles dark mode on Mac OS Mojave'
|
||||||
^^^^^^ Cask/Desc: Description shouldn't contain the platform.
|
^^^^^^ Description shouldn't contain the platform.
|
||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
|
|
||||||
expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb"
|
expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb"
|
||||||
cask 'foo-bar' do
|
cask 'foo-bar' do
|
||||||
desc 'Better input source switcher for OS X'
|
desc 'Better input source switcher for OS X'
|
||||||
^^^^ Cask/Desc: Description shouldn't contain the platform.
|
^^^^ Description shouldn't contain the platform.
|
||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
|
|
||||||
expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb"
|
expect_offense <<~RUBY, "/homebrew-cask/Casks/foo.rb"
|
||||||
cask 'foo-bar' do
|
cask 'foo-bar' do
|
||||||
desc 'Media Manager for Mac OS X'
|
desc 'Media Manager for Mac OS X'
|
||||||
^^^^^^^^ Cask/Desc: Description shouldn't contain the platform.
|
^^^^^^^^ Description shouldn't contain the platform.
|
||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
|
|
||||||
@ -109,7 +106,7 @@ describe RuboCop::Cop::Cask::Desc do
|
|||||||
expect_offense <<~RUBY
|
expect_offense <<~RUBY
|
||||||
cask 'foo' do
|
cask 'foo' do
|
||||||
desc 'Application for managing macOS virtual machines on macOS'
|
desc 'Application for managing macOS virtual machines on macOS'
|
||||||
^^^^^ Cask/Desc: Description shouldn't contain the platform.
|
^^^^^ Description shouldn't contain the platform.
|
||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
|
|
||||||
|
@ -1,64 +1,36 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "rubocops/rubocop-cask"
|
require "rubocops/rubocop-cask"
|
||||||
require "test/rubocops/cask/shared_examples/cask_cop"
|
|
||||||
|
|
||||||
describe RuboCop::Cop::Cask::HomepageUrlTrailingSlash do
|
describe RuboCop::Cop::Cask::HomepageUrlTrailingSlash, :config do
|
||||||
include CaskCop
|
it "accepts a homepage URL ending with a slash" do
|
||||||
|
expect_no_offenses <<~CASK
|
||||||
subject(:cop) { described_class.new }
|
cask 'foo' do
|
||||||
|
homepage 'https://foo.brew.sh/'
|
||||||
context "when the homepage URL ends with a slash" do
|
end
|
||||||
let(:source) do
|
CASK
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
homepage 'https://foo.brew.sh/'
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when the homepage URL does not end with a slash but has a path" do
|
it "accepts a homepage URL with a path" do
|
||||||
let(:source) do
|
expect_no_offenses <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
homepage 'https://foo.brew.sh/path'
|
||||||
homepage 'https://foo.brew.sh/path'
|
end
|
||||||
end
|
CASK
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when the homepage URL does not end with a slash and has no path" do
|
it "reports an offense when the homepage URL does not end with a slash and has no path" do
|
||||||
let(:source) do
|
expect_offense <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
homepage 'https://foo.brew.sh'
|
||||||
homepage 'https://foo.brew.sh'
|
^^^^^^^^^^^^^^^^^^^^^ 'https://foo.brew.sh' must have a slash after the domain.
|
||||||
end
|
end
|
||||||
CASK
|
CASK
|
||||||
end
|
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
homepage 'https://foo.brew.sh/'
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
|
||||||
message: "Cask/HomepageUrlTrailingSlash: 'https://foo.brew.sh' must have a slash after the domain.",
|
|
||||||
severity: :convention,
|
|
||||||
line: 2,
|
|
||||||
column: 11,
|
|
||||||
source: "'https://foo.brew.sh'",
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
expect_correction <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
include_examples "autocorrects source"
|
homepage 'https://foo.brew.sh/'
|
||||||
|
end
|
||||||
|
CASK
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,34 +1,20 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "rubocops/rubocop-cask"
|
require "rubocops/rubocop-cask"
|
||||||
require "test/rubocops/cask/shared_examples/cask_cop"
|
|
||||||
|
|
||||||
describe RuboCop::Cop::Cask::NoDslVersion do
|
describe RuboCop::Cop::Cask::NoDslVersion, :config do
|
||||||
include CaskCop
|
it "accepts `cask` without a DSL version" do
|
||||||
|
expect_no_offenses "cask 'foo' do; end"
|
||||||
subject(:cop) { described_class.new }
|
|
||||||
|
|
||||||
context "with no dsl version" do
|
|
||||||
let(:source) { "cask 'foo' do; end" }
|
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with dsl version" do
|
it "reports an offense when `cask` has a DSL version" do
|
||||||
let(:source) { "cask :v1 => 'foo' do; end" }
|
expect_offense <<~CASK
|
||||||
let(:correct_source) { "cask 'foo' do; end" }
|
cask :v1 => 'foo' do; end
|
||||||
let(:expected_offenses) do
|
^^^^^^^^^^^^^^^^^ Use `cask 'foo'` instead of `cask :v1 => 'foo'`.
|
||||||
[{
|
CASK
|
||||||
message: "Cask/NoDslVersion: Use `cask 'foo'` instead of `cask :v1 => 'foo'`",
|
|
||||||
severity: :convention,
|
|
||||||
line: 1,
|
|
||||||
column: 0,
|
|
||||||
source: "cask :v1 => 'foo'",
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
expect_correction <<~CASK
|
||||||
|
cask 'foo' do; end
|
||||||
include_examples "autocorrects source"
|
CASK
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,254 +1,176 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "rubocops/rubocop-cask"
|
require "rubocops/rubocop-cask"
|
||||||
require "test/rubocops/cask/shared_examples/cask_cop"
|
|
||||||
|
|
||||||
describe RuboCop::Cop::Cask::NoOverrides do
|
describe RuboCop::Cop::Cask::NoOverrides, :config do
|
||||||
include CaskCop
|
it "accepts when there are no `on_*` blocks" do
|
||||||
|
expect_no_offenses <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
version '1.2.3'
|
||||||
|
url 'https://brew.sh/foo.pkg'
|
||||||
|
|
||||||
subject(:cop) { described_class.new }
|
name 'Foo'
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
end
|
||||||
|
|
||||||
context "when there are no on_system blocks" do
|
it "accepts when there are no top-level standalone stanzas" do
|
||||||
let(:source) do
|
expect_no_offenses <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
on_mojave :or_later do
|
||||||
|
version :latest
|
||||||
|
end
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
end
|
||||||
|
|
||||||
|
it "accepts non-overridable stanzas in `on_*` blocks" do
|
||||||
|
expect_no_offenses <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
version '1.2.3'
|
||||||
|
|
||||||
|
on_arm do
|
||||||
|
binary "foo-\#{version}-arm64"
|
||||||
|
end
|
||||||
|
|
||||||
|
app "foo-\#{version}.app"
|
||||||
|
|
||||||
|
binary "foo-\#{version}"
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
end
|
||||||
|
|
||||||
|
it "accepts `arch` and `version` interpolations in strings in `on_*` blocks" do
|
||||||
|
expect_no_offenses <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
arch arm: "arm64", intel: "x86"
|
||||||
|
version '1.2.3'
|
||||||
|
|
||||||
|
on_mojave :or_later do
|
||||||
|
sha256 "aaa"
|
||||||
|
|
||||||
|
url "https://brew.sh/foo-\#{version}-\#{arch}.pkg"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
end
|
||||||
|
|
||||||
|
it "accepts `version` interpolations with method calls in strings in `on_*` blocks" do
|
||||||
|
expect_no_offenses <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
version '0.99,123.3'
|
||||||
|
|
||||||
|
on_mojave :or_later do
|
||||||
|
url "https://brew.sh/foo-\#{version.csv.first}-\#{version.csv.second}.pkg"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
end
|
||||||
|
|
||||||
|
it "accepts `arch` interpolations in regexes in `on_*` blocks" do
|
||||||
|
expect_no_offenses <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
arch arm: "arm64", intel: "x86"
|
||||||
|
|
||||||
|
version '0.99,123.3'
|
||||||
|
|
||||||
|
on_mojave :or_later do
|
||||||
|
url "https://brew.sh/foo-\#{arch}-\#{version.csv.first}-\#{version.csv.last}.pkg"
|
||||||
|
|
||||||
|
livecheck do
|
||||||
|
url "https://brew.sh/foo/releases.html"
|
||||||
|
regex(/href=.*?foo[._-]v?(\d+(?:.\d+)+)-\#{arch}.pkg/i)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
end
|
||||||
|
|
||||||
|
it "ignores contents of single-line `livecheck` blocks in `on_*` blocks" do
|
||||||
|
expect_no_offenses <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
on_intel do
|
||||||
|
livecheck do
|
||||||
|
url 'https://brew.sh/foo' # Livecheck should be allowed since it's a different "kind" of URL.
|
||||||
|
end
|
||||||
version '1.2.3'
|
version '1.2.3'
|
||||||
url 'https://brew.sh/foo.pkg'
|
|
||||||
|
|
||||||
name 'Foo'
|
|
||||||
end
|
end
|
||||||
CASK
|
on_arm do
|
||||||
end
|
version '2.3.4'
|
||||||
|
end
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
url 'https://brew.sh/foo.pkg'
|
||||||
|
sha256 "bbb"
|
||||||
|
end
|
||||||
|
CASK
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when there are no top-level standalone stanzas" do
|
it "ignores contents of multi-line `livecheck` blocks in `on_*` blocks" do
|
||||||
let(:source) do
|
expect_no_offenses <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
on_intel do
|
||||||
on_mojave :or_later do
|
livecheck do
|
||||||
version :latest
|
url 'https://brew.sh/foo' # Livecheck should be allowed since it's a different "kind" of URL.
|
||||||
|
strategy :sparkle
|
||||||
end
|
end
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when there are top-level stanzas also in `on_*` blocks that should not override" do
|
|
||||||
let(:source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
version '1.2.3'
|
version '1.2.3'
|
||||||
|
|
||||||
on_arm do
|
|
||||||
binary "foo-\#{version}-arm64"
|
|
||||||
end
|
|
||||||
|
|
||||||
app "foo-\#{version}.app"
|
|
||||||
|
|
||||||
binary "foo-\#{version}"
|
|
||||||
end
|
end
|
||||||
CASK
|
on_arm do
|
||||||
end
|
version '2.3.4'
|
||||||
|
end
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
url 'https://brew.sh/foo.pkg'
|
||||||
|
sha256 "bbb"
|
||||||
|
end
|
||||||
|
CASK
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when there are `arch` variables in the `url` in the `on_*` blocks" do
|
it "accepts `on_*` blocks that don't override upper-level stanzas" do
|
||||||
let(:source) do
|
expect_no_offenses <<~CASK
|
||||||
<<~CASK
|
cask "foo" do
|
||||||
cask 'foo' do
|
version "1.2.3"
|
||||||
arch arm: "arm64", intel: "x86"
|
|
||||||
version '1.2.3'
|
|
||||||
on_mojave :or_later do
|
|
||||||
url "https://brew.sh/foo-\#{version}-\#{arch}.pkg"
|
|
||||||
sha256 "aaa"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
on_big_sur :or_older do
|
||||||
end
|
|
||||||
|
|
||||||
context "when there are `version` interpolations in `on_*` blocks with methods called on them" do
|
|
||||||
let(:source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
version 0.99,123.3
|
|
||||||
|
|
||||||
on_mojave :or_later do
|
|
||||||
url "https://brew.sh/foo-\#{version.csv.first}-\#{version.csv.second}.pkg"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when there are `arch` interpolations in regexps in `on_*` blocks" do
|
|
||||||
let(:source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
arch arm: "arm64", intel: "x86"
|
|
||||||
|
|
||||||
version 0.99,123.3
|
|
||||||
|
|
||||||
on_mojave :or_later do
|
|
||||||
url "https://brew.sh/foo-\#{arch}-\#{version.csv.first}-\#{version.csv.last}.pkg"
|
|
||||||
|
|
||||||
livecheck do
|
|
||||||
url "https://brew.sh/foo/releases.html"
|
|
||||||
regex(/href=.*?foo[._-]v?(\d+(?:.\d+)+)-\#{arch}.pkg/i)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when there are single-line livecheck blocks within `on_*` blocks, ignore their contents" do
|
|
||||||
let(:source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
on_intel do
|
|
||||||
livecheck do
|
|
||||||
url 'https://brew.sh/foo' # Livecheck should be allowed since it's a different "kind" of URL.
|
|
||||||
end
|
|
||||||
version '1.2.3'
|
|
||||||
end
|
|
||||||
on_arm do
|
|
||||||
version '2.3.4'
|
|
||||||
end
|
|
||||||
|
|
||||||
url 'https://brew.sh/foo.pkg'
|
|
||||||
sha256 "bbb"
|
sha256 "bbb"
|
||||||
|
url "https://brew.sh/legacy/foo-2.3.4.dmg"
|
||||||
end
|
end
|
||||||
CASK
|
on_monterey :or_newer do
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when there are multi-line livecheck blocks within `on_*` blocks, ignore their contents" do
|
|
||||||
let(:source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
on_intel do
|
|
||||||
livecheck do
|
|
||||||
url 'https://brew.sh/foo' # Livecheck should be allowed since it's a different "kind" of URL.
|
|
||||||
strategy :sparkle
|
|
||||||
end
|
|
||||||
version '1.2.3'
|
|
||||||
end
|
|
||||||
on_arm do
|
|
||||||
version '2.3.4'
|
|
||||||
end
|
|
||||||
|
|
||||||
url 'https://brew.sh/foo.pkg'
|
|
||||||
sha256 "bbb"
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when there's only one difference between the `on_*` blocks" do
|
|
||||||
let(:source) do
|
|
||||||
<<~CASK
|
|
||||||
cask "foo" do
|
|
||||||
version "1.2.3"
|
|
||||||
|
|
||||||
on_big_sur :or_older do
|
|
||||||
sha256 "bbb"
|
|
||||||
url "https://brew.sh/legacy/foo-2.3.4.dmg"
|
|
||||||
end
|
|
||||||
on_monterey :or_newer do
|
|
||||||
sha256 "aaa"
|
|
||||||
url "https://brew.sh/foo-2.3.4.dmg"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when there are multiple differences between the `on_*` blocks" do
|
|
||||||
let(:source) do
|
|
||||||
<<~CASK
|
|
||||||
cask "foo" do
|
|
||||||
version "1.2.3"
|
|
||||||
sha256 "aaa"
|
sha256 "aaa"
|
||||||
url "https://brew.sh/foo-2.3.4.dmg"
|
url "https://brew.sh/foo-2.3.4.dmg"
|
||||||
|
|
||||||
on_big_sur :or_older do
|
|
||||||
sha256 "bbb"
|
|
||||||
url "https://brew.sh/legacy/foo-2.3.4.dmg"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
CASK
|
end
|
||||||
end
|
CASK
|
||||||
|
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
|
||||||
message: <<~EOS,
|
|
||||||
Cask/NoOverrides: Do not use a top-level `sha256` stanza as the default. Add it to an `on_{system}` block instead.
|
|
||||||
Use `:or_older` or `:or_newer` to specify a range of macOS versions.
|
|
||||||
EOS
|
|
||||||
severity: :convention,
|
|
||||||
line: 3,
|
|
||||||
column: 2,
|
|
||||||
source: "sha256 \"aaa\"",
|
|
||||||
}, {
|
|
||||||
message: <<~EOS,
|
|
||||||
Cask/NoOverrides: Do not use a top-level `url` stanza as the default. Add it to an `on_{system}` block instead.
|
|
||||||
Use `:or_older` or `:or_newer` to specify a range of macOS versions.
|
|
||||||
EOS
|
|
||||||
severity: :convention,
|
|
||||||
line: 4,
|
|
||||||
column: 2,
|
|
||||||
source: "url \"https://brew.sh/foo-2.3.4.dmg\"",
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when there are top-level standalone stanzas" do
|
it "reports an offense when `on_*` blocks override a single upper-level stanza" do
|
||||||
let(:source) do
|
expect_offense <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
version '2.3.4'
|
||||||
version '2.3.4'
|
^^^^^^^^^^^^^^^ Do not use a top-level `version` stanza as the default. Add it to an `on_{system}` block instead. Use `:or_older` or `:or_newer` to specify a range of macOS versions.
|
||||||
on_mojave :or_older do
|
|
||||||
version '1.2.3'
|
|
||||||
end
|
|
||||||
|
|
||||||
url 'https://brew.sh/foo-2.3.4.dmg'
|
on_mojave :or_older do
|
||||||
|
version '1.2.3'
|
||||||
end
|
end
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
let(:expected_offenses) do
|
url 'https://brew.sh/foo-2.3.4.dmg'
|
||||||
[{
|
end
|
||||||
message: <<~EOS,
|
CASK
|
||||||
Cask/NoOverrides: Do not use a top-level `version` stanza as the default. Add it to an `on_{system}` block instead.
|
end
|
||||||
Use `:or_older` or `:or_newer` to specify a range of macOS versions.
|
|
||||||
EOS
|
|
||||||
severity: :convention,
|
|
||||||
line: 2,
|
|
||||||
column: 2,
|
|
||||||
source: "version '2.3.4'",
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
it "reports an offense when `on_*` blocks override multiple upper-level stanzas" do
|
||||||
|
expect_offense <<~CASK
|
||||||
|
cask "foo" do
|
||||||
|
version "1.2.3"
|
||||||
|
sha256 "aaa"
|
||||||
|
^^^^^^^^^^^^ Do not use a top-level `sha256` stanza as the default. Add it to an `on_{system}` block instead. Use `:or_older` or `:or_newer` to specify a range of macOS versions.
|
||||||
|
url "https://brew.sh/foo-2.3.4.dmg"
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use a top-level `url` stanza as the default. Add it to an `on_{system}` block instead. Use `:or_older` or `:or_newer` to specify a range of macOS versions.
|
||||||
|
|
||||||
|
on_big_sur :or_older do
|
||||||
|
sha256 "bbb"
|
||||||
|
url "https://brew.sh/legacy/foo-2.3.4.dmg"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
CASK
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,458 +1,249 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "rubocops/rubocop-cask"
|
require "rubocops/rubocop-cask"
|
||||||
require "test/rubocops/cask/shared_examples/cask_cop"
|
|
||||||
|
|
||||||
describe RuboCop::Cop::Cask::OnSystemConditionals do
|
|
||||||
include CaskCop
|
|
||||||
|
|
||||||
subject(:cop) { described_class.new }
|
|
||||||
|
|
||||||
|
describe RuboCop::Cop::Cask::OnSystemConditionals, :config do
|
||||||
context "when auditing `postflight` stanzas" do
|
context "when auditing `postflight` stanzas" do
|
||||||
context "when there are no on_system blocks" do
|
it "accepts when there are no `on_*` blocks" do
|
||||||
let(:source) do
|
expect_no_offenses <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
postflight do
|
||||||
postflight do
|
foobar
|
||||||
|
end
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
end
|
||||||
|
|
||||||
|
it "reports an offense it contains an `on_intel` block" do
|
||||||
|
expect_offense <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
postflight do
|
||||||
|
on_intel do
|
||||||
|
^^^^^^^^ Don't use `on_intel` in `postflight do`, use `if Hardware::CPU.intel?` instead.
|
||||||
foobar
|
foobar
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
CASK
|
end
|
||||||
end
|
CASK
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
# FIXME: Infinite loop alternating between `if Hardware::CPU.intel?` and `on_intel do`.
|
||||||
|
expect_correction <<~CASK, loop: false
|
||||||
|
cask 'foo' do
|
||||||
|
postflight do
|
||||||
|
if Hardware::CPU.intel?
|
||||||
|
foobar
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
CASK
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when there is an `on_intel` block" do
|
it "reports an offense when it contains an `on_monterey` block" do
|
||||||
let(:source) do
|
expect_offense <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
postflight do
|
||||||
postflight do
|
on_monterey do
|
||||||
on_intel do
|
^^^^^^^^^^^ Don't use `on_monterey` in `postflight do`, use `if MacOS.version == :monterey` instead.
|
||||||
foobar
|
foobar
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
CASK
|
end
|
||||||
end
|
CASK
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
# FIXME: Infinite loop alternating between `if MacOS.version == :monterey` and `on_monterey do`.
|
||||||
cask 'foo' do
|
expect_correction <<~CASK, loop: false
|
||||||
postflight do
|
cask 'foo' do
|
||||||
if Hardware::CPU.intel?
|
postflight do
|
||||||
foobar
|
if MacOS.version == :monterey
|
||||||
end
|
foobar
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
CASK
|
end
|
||||||
end
|
CASK
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
|
||||||
message: <<~EOS.chomp,
|
|
||||||
Cask/OnSystemConditionals: Don't use `on_intel` in `postflight do`, use `if Hardware::CPU.intel?` instead.
|
|
||||||
EOS
|
|
||||||
severity: :convention,
|
|
||||||
line: 3,
|
|
||||||
column: 4,
|
|
||||||
source: "on_intel",
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
|
||||||
|
|
||||||
include_examples "autocorrects source"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when there is an `on_monterey` block" do
|
it "reports an offense when it contains an `on_monterey :or_older` block" do
|
||||||
let(:source) do
|
expect_offense <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
postflight do
|
||||||
postflight do
|
on_monterey :or_older do
|
||||||
on_monterey do
|
^^^^^^^^^^^^^^^^^^^^^ Don't use `on_monterey :or_older` in `postflight do`, use `if MacOS.version <= :monterey` instead.
|
||||||
foobar
|
foobar
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
CASK
|
end
|
||||||
end
|
CASK
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
# FIXME: Infinite loop alternating between `if MacOS.version <= :monterey` and `on_monterey :or_older do`.
|
||||||
cask 'foo' do
|
expect_correction <<~CASK, loop: false
|
||||||
postflight do
|
cask 'foo' do
|
||||||
if MacOS.version == :monterey
|
postflight do
|
||||||
foobar
|
if MacOS.version <= :monterey
|
||||||
end
|
foobar
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
CASK
|
end
|
||||||
end
|
CASK
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
|
||||||
message: "Cask/OnSystemConditionals: Don't use `on_monterey` in `postflight do`, use " \
|
|
||||||
"`if MacOS.version == :monterey` instead.",
|
|
||||||
severity: :convention,
|
|
||||||
line: 3,
|
|
||||||
column: 4,
|
|
||||||
source: "on_monterey",
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
|
||||||
|
|
||||||
include_examples "autocorrects source"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when there is an `on_monterey :or_older` block" do
|
|
||||||
let(:source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
postflight do
|
|
||||||
on_monterey :or_older do
|
|
||||||
foobar
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
postflight do
|
|
||||||
if MacOS.version <= :monterey
|
|
||||||
foobar
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
|
||||||
message: "Cask/OnSystemConditionals: Don't use `on_monterey :or_older` in `postflight do`, " \
|
|
||||||
"use `if MacOS.version <= :monterey` instead.",
|
|
||||||
severity: :convention,
|
|
||||||
line: 3,
|
|
||||||
column: 4,
|
|
||||||
source: "on_monterey :or_older",
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
|
||||||
|
|
||||||
include_examples "autocorrects source"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when auditing `sha256` stanzas inside on_arch blocks" do
|
context "when auditing `sha256` stanzas inside `on_arch` blocks" do
|
||||||
context "when there are no on_arch blocks" do
|
it "accepts when there are no `on_arch` blocks" do
|
||||||
let(:source) do
|
expect_no_offenses <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
end
|
||||||
|
|
||||||
|
it "accepts when the `sha256` stanza is used with keyword arguments" do
|
||||||
|
expect_no_offenses <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
sha256 arm: "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94",
|
||||||
|
intel: "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
end
|
||||||
|
|
||||||
|
it "accepts when there is only one `on_arch` block" do
|
||||||
|
expect_no_offenses <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
on_intel do
|
||||||
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
||||||
end
|
end
|
||||||
CASK
|
end
|
||||||
end
|
CASK
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when the proper `sha256` stanza is used" do
|
it "reports an offense when `sha256` is specified in all `on_arch` blocks" do
|
||||||
let(:source) do
|
expect_offense <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
on_intel do
|
||||||
sha256 arm: "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94",
|
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
||||||
intel: "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
|
|
||||||
end
|
end
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when the `sha256` stanza needs to be removed from the on_arch blocks" do
|
|
||||||
let(:source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
on_intel do
|
|
||||||
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
|
||||||
end
|
|
||||||
on_arm do
|
|
||||||
sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
#{" "}
|
|
||||||
sha256 arm: "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b", intel: "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:offense_source) do
|
|
||||||
<<~CASK
|
|
||||||
on_arm do
|
on_arm do
|
||||||
sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
|
^^^^^^^^^ Use `sha256 arm: "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b", intel: "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"` instead of nesting the `sha256` stanzas in `on_intel` and `on_arm` blocks
|
||||||
end
|
sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
|
||||||
CASK
|
end
|
||||||
end
|
end
|
||||||
let(:expected_offenses) do
|
CASK
|
||||||
[{
|
|
||||||
message: <<~EOS.chomp,
|
|
||||||
Cask/OnSystemConditionals: Use `sha256 arm: "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b", intel: "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"` instead of nesting the `sha256` stanzas in `on_intel` and `on_arm` blocks
|
|
||||||
EOS
|
|
||||||
severity: :convention,
|
|
||||||
line: 5,
|
|
||||||
column: 2,
|
|
||||||
source: offense_source.strip,
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
expect_correction <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
include_examples "autocorrects source"
|
#{" "}
|
||||||
|
sha256 arm: "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b", intel: "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
||||||
|
end
|
||||||
|
CASK
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when there is only one on_arch block" do
|
it "accepts when there is also a `version` stanza inside the `on_arch` blocks" do
|
||||||
let(:source) do
|
expect_no_offenses <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
on_intel do
|
||||||
on_intel do
|
version "1.0.0"
|
||||||
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
||||||
end
|
|
||||||
end
|
end
|
||||||
CASK
|
on_arm do
|
||||||
end
|
version "2.0.0"
|
||||||
|
sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
|
||||||
include_examples "does not report any offenses"
|
end
|
||||||
|
end
|
||||||
|
CASK
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when there is also a `version` stanza inside the on_arch blocks" do
|
it "accepts when there is also a `version` stanza inside only a single `on_arch` block" do
|
||||||
let(:source) do
|
expect_no_offenses <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
on_intel do
|
||||||
on_intel do
|
version "2.0.0"
|
||||||
version "1.0.0"
|
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
||||||
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
|
||||||
end
|
|
||||||
on_arm do
|
|
||||||
version "2.0.0"
|
|
||||||
sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
CASK
|
on_arm do
|
||||||
end
|
sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when there is also a `version` stanza inside only a single on_arch block" do
|
|
||||||
let(:source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
on_intel do
|
|
||||||
version "2.0.0"
|
|
||||||
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
|
||||||
end
|
|
||||||
on_arm do
|
|
||||||
sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
CASK
|
end
|
||||||
end
|
CASK
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when auditing loose `Hardware::CPU` method calls" do
|
context "when auditing loose `Hardware::CPU` method calls" do
|
||||||
context "when there is a `Hardware::CPU.arm?` reference" do
|
it "reports an offense when `Hardware::CPU.arm?` is used" do
|
||||||
let(:source) do
|
expect_offense <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
if Hardware::CPU.arm? && other_condition
|
||||||
if Hardware::CPU.arm? && other_condition
|
^^^^^^^^^^^^^^^^^^ Don't use `Hardware::CPU.arm?`, use `on_arm` and `on_intel` blocks instead.
|
||||||
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
|
||||||
else
|
|
||||||
sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
|
||||||
message: <<~EOS.chomp,
|
|
||||||
Cask/OnSystemConditionals: Don't use `Hardware::CPU.arm?`, use `on_arm` and `on_intel` blocks instead.
|
|
||||||
EOS
|
|
||||||
severity: :convention,
|
|
||||||
line: 2,
|
|
||||||
column: 5,
|
|
||||||
source: "Hardware::CPU.arm?",
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when there is a `Hardware::CPU.intel?` reference" do
|
|
||||||
let(:source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
if Hardware::CPU.intel? && other_condition
|
|
||||||
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
|
||||||
else
|
|
||||||
sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
|
||||||
message: <<~EOS.chomp,
|
|
||||||
Cask/OnSystemConditionals: Don't use `Hardware::CPU.intel?`, use `on_arm` and `on_intel` blocks instead.
|
|
||||||
EOS
|
|
||||||
severity: :convention,
|
|
||||||
line: 2,
|
|
||||||
column: 5,
|
|
||||||
source: "Hardware::CPU.intel?",
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when there is a `Hardware::CPU.arch` reference" do
|
|
||||||
let(:source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
version "1.2.3"
|
|
||||||
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
||||||
|
else
|
||||||
url "https://example.com/foo-\#{version}-\#{Hardware::CPU.arch}.zip"
|
sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
|
||||||
end
|
end
|
||||||
CASK
|
end
|
||||||
end
|
CASK
|
||||||
let(:expected_offenses) do
|
end
|
||||||
[{
|
|
||||||
message: <<~EOS.chomp,
|
|
||||||
Cask/OnSystemConditionals: Don't use `Hardware::CPU.arch`, use `on_arm` and `on_intel` blocks instead.
|
|
||||||
EOS
|
|
||||||
severity: :convention,
|
|
||||||
line: 5,
|
|
||||||
column: 44,
|
|
||||||
source: "Hardware::CPU.arch",
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
it "reports an offense when `Hardware::CPU.intel?` is used" do
|
||||||
|
expect_offense <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
if Hardware::CPU.intel? && other_condition
|
||||||
|
^^^^^^^^^^^^^^^^^^^^ Don't use `Hardware::CPU.intel?`, use `on_arm` and `on_intel` blocks instead.
|
||||||
|
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
||||||
|
else
|
||||||
|
sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
end
|
||||||
|
|
||||||
|
it "reports an offense when `Hardware::CPU.arch` is used" do
|
||||||
|
expect_offense <<~'CASK'
|
||||||
|
cask 'foo' do
|
||||||
|
version "1.2.3"
|
||||||
|
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
||||||
|
|
||||||
|
url "https://example.com/foo-#{version}-#{Hardware::CPU.arch}.zip"
|
||||||
|
^^^^^^^^^^^^^^^^^^ Don't use `Hardware::CPU.arch`, use `on_arm` and `on_intel` blocks instead.
|
||||||
|
end
|
||||||
|
CASK
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when auditing loose `MacOS.version` method calls" do
|
context "when auditing loose `MacOS.version` method calls" do
|
||||||
context "when there is a `MacOS.version ==` reference" do
|
it "reports an offense when `MacOS.version ==` is used" do
|
||||||
let(:source) do
|
expect_offense <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
if MacOS.version == :catalina
|
||||||
if MacOS.version == :catalina
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't use `if MacOS.version == :catalina`, use `on_catalina do` instead.
|
||||||
version "1.0.0"
|
version "1.0.0"
|
||||||
else
|
else
|
||||||
version "2.0.0"
|
version "2.0.0"
|
||||||
end
|
|
||||||
end
|
end
|
||||||
CASK
|
end
|
||||||
end
|
CASK
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
|
||||||
message: <<~EOS.chomp,
|
|
||||||
Cask/OnSystemConditionals: Don't use `if MacOS.version == :catalina`, use `on_catalina do` instead.
|
|
||||||
EOS
|
|
||||||
severity: :convention,
|
|
||||||
line: 2,
|
|
||||||
column: 2,
|
|
||||||
source: "if MacOS.version == :catalina\n version \"1.0.0\"\n else\n version \"2.0.0\"\n end",
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when there is a `MacOS.version <=` reference" do
|
it "reports an offense when `MacOS.version <=` is used" do
|
||||||
let(:source) do
|
expect_offense <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
if MacOS.version <= :catalina
|
||||||
if MacOS.version <= :catalina
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't use `if MacOS.version <= :catalina`, use `on_catalina :or_older do` instead.
|
||||||
version "1.0.0"
|
version "1.0.0"
|
||||||
else
|
else
|
||||||
version "2.0.0"
|
version "2.0.0"
|
||||||
end
|
|
||||||
end
|
end
|
||||||
CASK
|
end
|
||||||
end
|
CASK
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
|
||||||
message: <<~EOS.chomp,
|
|
||||||
Cask/OnSystemConditionals: Don't use `if MacOS.version <= :catalina`, use `on_catalina :or_older do` instead.
|
|
||||||
EOS
|
|
||||||
severity: :convention,
|
|
||||||
line: 2,
|
|
||||||
column: 2,
|
|
||||||
source: "if MacOS.version <= :catalina\n version \"1.0.0\"\n else\n version \"2.0.0\"\n end",
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when there is a `MacOS.version >=` reference" do
|
it "reports an offense when `MacOS.version >=` is used" do
|
||||||
let(:source) do
|
expect_offense <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
if MacOS.version >= :catalina
|
||||||
if MacOS.version >= :catalina
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't use `if MacOS.version >= :catalina`, use `on_catalina :or_newer do` instead.
|
||||||
version "1.0.0"
|
version "1.0.0"
|
||||||
else
|
else
|
||||||
version "2.0.0"
|
version "2.0.0"
|
||||||
end
|
|
||||||
end
|
end
|
||||||
CASK
|
end
|
||||||
end
|
CASK
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
|
||||||
message: <<~EOS.chomp,
|
|
||||||
Cask/OnSystemConditionals: Don't use `if MacOS.version >= :catalina`, use `on_catalina :or_newer do` instead.
|
|
||||||
EOS
|
|
||||||
severity: :convention,
|
|
||||||
line: 2,
|
|
||||||
column: 2,
|
|
||||||
source: "if MacOS.version >= :catalina\n version \"1.0.0\"\n else\n version \"2.0.0\"\n end",
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when there is a `MacOS.version` reference" do
|
|
||||||
let(:source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
version "1.2.3"
|
|
||||||
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
|
||||||
|
|
||||||
url "https://example.com/foo-\#{version}-\#{MacOS.version == :monterey}.zip"
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
|
||||||
message: <<~EOS.chomp,
|
|
||||||
Cask/OnSystemConditionals: Don't use `MacOS.version == :monterey`, use `on_{macos_version}` blocks instead.
|
|
||||||
EOS
|
|
||||||
severity: :convention,
|
|
||||||
line: 5,
|
|
||||||
column: 44,
|
|
||||||
source: "MacOS.version == :monterey",
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,62 +0,0 @@
|
|||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
module CaskCop
|
|
||||||
shared_examples "does not report any offenses" do
|
|
||||||
it "does not report any offenses" do
|
|
||||||
expect_no_offenses(source)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
shared_examples "reports offenses" do
|
|
||||||
it "reports offenses" do
|
|
||||||
expect_reported_offenses(source, expected_offenses)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
shared_examples "autocorrects source" do
|
|
||||||
it "autocorrects source" do
|
|
||||||
expect_autocorrected_source(source, correct_source)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def expect_no_offenses(source)
|
|
||||||
expect(inspect_source(source)).to be_empty
|
|
||||||
end
|
|
||||||
|
|
||||||
def expect_reported_offenses(source, expected_offenses)
|
|
||||||
offenses = inspect_source(source)
|
|
||||||
expect(offenses.size).to eq(expected_offenses.size)
|
|
||||||
expected_offenses.zip(offenses).each do |expected, actual|
|
|
||||||
expect_offense2(expected, actual)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def expect_offense2(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])
|
|
||||||
expect(actual.location.source).to eq(expected[:source])
|
|
||||||
end
|
|
||||||
|
|
||||||
# TODO: Replace with `expect_correction` from `rubocop-rspec`.
|
|
||||||
def expect_autocorrected_source(source, correct_source)
|
|
||||||
correct_source = Array(correct_source).join("\n")
|
|
||||||
|
|
||||||
current_source = source
|
|
||||||
|
|
||||||
# RuboCop runs auto-correction in a loop to handle nested offenses.
|
|
||||||
loop do
|
|
||||||
current_source = autocorrect_source(current_source)
|
|
||||||
|
|
||||||
if (ignored_nodes = cop.instance_variable_get(:@ignored_nodes)) && ignored_nodes.any?
|
|
||||||
ignored_nodes.clear
|
|
||||||
next
|
|
||||||
end
|
|
||||||
|
|
||||||
break
|
|
||||||
end
|
|
||||||
|
|
||||||
expect(current_source).to eq correct_source
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,337 +1,205 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "rubocops/rubocop-cask"
|
require "rubocops/rubocop-cask"
|
||||||
require "test/rubocops/cask/shared_examples/cask_cop"
|
|
||||||
|
|
||||||
describe RuboCop::Cop::Cask::StanzaGrouping do
|
describe RuboCop::Cop::Cask::StanzaGrouping, :config do
|
||||||
include CaskCop
|
it "accepts a sole stanza" do
|
||||||
|
expect_no_offenses <<~CASK
|
||||||
subject(:cop) { described_class.new }
|
cask 'foo' do
|
||||||
|
version :latest
|
||||||
let(:missing_line_msg) do
|
end
|
||||||
"Cask/StanzaGrouping: stanza groups should be separated by a single empty line"
|
CASK
|
||||||
end
|
|
||||||
let(:extra_line_msg) do
|
|
||||||
"Cask/StanzaGrouping: stanzas within the same group should have no lines between them"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when there is only one stanza" do
|
it "accepts correctly grouped stanzas" do
|
||||||
let(:source) do
|
expect_no_offenses <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
version :latest
|
||||||
version :latest
|
sha256 :no_check
|
||||||
end
|
end
|
||||||
CASK
|
CASK
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when no stanzas are incorrectly grouped" do
|
it "accepts correctly grouped stanzas and variable assignments" do
|
||||||
let(:source) do
|
expect_no_offenses <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
arch arm: "arm64", intel: "x86_64"
|
||||||
version :latest
|
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
||||||
sha256 :no_check
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
version :latest
|
||||||
|
sha256 :no_check
|
||||||
|
end
|
||||||
|
CASK
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when no stanzas or variable assignments are incorrectly grouped" do
|
it "reports an offense when a stanza is grouped incorrectly" do
|
||||||
let(:source) do
|
expect_offense <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
version :latest
|
||||||
arch arm: "arm64", intel: "x86_64"
|
|
||||||
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
|
||||||
|
|
||||||
version :latest
|
^{} stanzas within the same group should have no lines between them
|
||||||
sha256 :no_check
|
sha256 :no_check
|
||||||
end
|
end
|
||||||
CASK
|
CASK
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
expect_correction <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
version :latest
|
||||||
|
sha256 :no_check
|
||||||
|
end
|
||||||
|
CASK
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when one stanza is incorrectly grouped" do
|
it "reports an offense for an incorrectly grouped `arch` stanza" do
|
||||||
let(:source) do
|
expect_offense <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
arch arm: "arm64", intel: "x86_64"
|
||||||
version :latest
|
version :latest
|
||||||
|
^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line
|
||||||
|
sha256 :no_check
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
|
||||||
sha256 :no_check
|
expect_correction <<~CASK
|
||||||
end
|
cask 'foo' do
|
||||||
CASK
|
arch arm: "arm64", intel: "x86_64"
|
||||||
end
|
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
version :latest
|
|
||||||
sha256 :no_check
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
|
||||||
message: extra_line_msg,
|
|
||||||
severity: :convention,
|
|
||||||
line: 3,
|
|
||||||
column: 0,
|
|
||||||
source: "\n",
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
version :latest
|
||||||
|
sha256 :no_check
|
||||||
include_examples "autocorrects source"
|
end
|
||||||
|
CASK
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when the arch stanza is incorrectly grouped" do
|
it "reports an offense for an incorrectly grouped variable assignment" do
|
||||||
let(:source) do
|
expect_offense <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
arch arm: "arm64", intel: "x86_64"
|
||||||
arch arm: "arm64", intel: "x86_64"
|
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
||||||
version :latest
|
version :latest
|
||||||
sha256 :no_check
|
^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line
|
||||||
end
|
sha256 :no_check
|
||||||
CASK
|
end
|
||||||
end
|
CASK
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
arch arm: "arm64", intel: "x86_64"
|
|
||||||
|
|
||||||
version :latest
|
expect_correction <<~CASK
|
||||||
sha256 :no_check
|
cask 'foo' do
|
||||||
end
|
arch arm: "arm64", intel: "x86_64"
|
||||||
CASK
|
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
||||||
end
|
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
|
||||||
message: missing_line_msg,
|
|
||||||
severity: :convention,
|
|
||||||
line: 3,
|
|
||||||
column: 0,
|
|
||||||
source: " version :latest",
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
version :latest
|
||||||
|
sha256 :no_check
|
||||||
include_examples "autocorrects source"
|
end
|
||||||
|
CASK
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when one variable assignment is incorrectly grouped" do
|
it "reports an offense for multiple incorrectly grouped stanzas" do
|
||||||
let(:source) do
|
expect_offense <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
version :latest
|
||||||
arch arm: "arm64", intel: "x86_64"
|
sha256 :no_check
|
||||||
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
url 'https://foo.brew.sh/foo.zip'
|
||||||
version :latest
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line
|
||||||
sha256 :no_check
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
arch arm: "arm64", intel: "x86_64"
|
|
||||||
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
|
||||||
|
|
||||||
version :latest
|
^{} stanzas within the same group should have no lines between them
|
||||||
sha256 :no_check
|
name 'Foo'
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
|
||||||
message: missing_line_msg,
|
|
||||||
severity: :convention,
|
|
||||||
line: 4,
|
|
||||||
column: 0,
|
|
||||||
source: " version :latest",
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
^{} stanzas within the same group should have no lines between them
|
||||||
|
homepage 'https://foo.brew.sh'
|
||||||
|
|
||||||
include_examples "autocorrects source"
|
app 'Foo.app'
|
||||||
|
uninstall :quit => 'com.example.foo',
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line
|
||||||
|
:kext => 'com.example.foo.kextextension'
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
|
||||||
|
expect_correction <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
version :latest
|
||||||
|
sha256 :no_check
|
||||||
|
|
||||||
|
url 'https://foo.brew.sh/foo.zip'
|
||||||
|
name 'Foo'
|
||||||
|
homepage 'https://foo.brew.sh'
|
||||||
|
|
||||||
|
app 'Foo.app'
|
||||||
|
|
||||||
|
uninstall :quit => 'com.example.foo',
|
||||||
|
:kext => 'com.example.foo.kextextension'
|
||||||
|
end
|
||||||
|
CASK
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when many stanzas are incorrectly grouped" do
|
it "reports an offense for multiple incorrectly grouped stanzas and variable assignments" do
|
||||||
let(:source) do
|
expect_offense <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
arch arm: "arm64", intel: "x86_64"
|
||||||
version :latest
|
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
||||||
sha256 :no_check
|
|
||||||
url 'https://foo.brew.sh/foo.zip'
|
^{} stanzas within the same group should have no lines between them
|
||||||
|
platform = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
||||||
name 'Foo'
|
version :latest
|
||||||
|
^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line
|
||||||
homepage 'https://foo.brew.sh'
|
sha256 :no_check
|
||||||
|
|
||||||
app 'Foo.app'
|
url 'https://foo.brew.sh/foo.zip'
|
||||||
uninstall :quit => 'com.example.foo',
|
|
||||||
:kext => 'com.example.foo.kextextension'
|
^{} stanzas within the same group should have no lines between them
|
||||||
end
|
name 'Foo'
|
||||||
CASK
|
|
||||||
end
|
^{} stanzas within the same group should have no lines between them
|
||||||
let(:correct_source) do
|
homepage 'https://foo.brew.sh'
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
app 'Foo.app'
|
||||||
version :latest
|
uninstall :quit => 'com.example.foo',
|
||||||
sha256 :no_check
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line
|
||||||
|
:kext => 'com.example.foo.kextextension'
|
||||||
url 'https://foo.brew.sh/foo.zip'
|
end
|
||||||
name 'Foo'
|
CASK
|
||||||
homepage 'https://foo.brew.sh'
|
|
||||||
|
expect_correction <<~CASK
|
||||||
app 'Foo.app'
|
cask 'foo' do
|
||||||
|
arch arm: "arm64", intel: "x86_64"
|
||||||
uninstall :quit => 'com.example.foo',
|
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
||||||
:kext => 'com.example.foo.kextextension'
|
platform = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
||||||
end
|
|
||||||
CASK
|
version :latest
|
||||||
end
|
sha256 :no_check
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
url 'https://foo.brew.sh/foo.zip'
|
||||||
message: missing_line_msg,
|
name 'Foo'
|
||||||
severity: :convention,
|
homepage 'https://foo.brew.sh'
|
||||||
line: 4,
|
|
||||||
column: 0,
|
app 'Foo.app'
|
||||||
source: " url 'https://foo.brew.sh/foo.zip'",
|
|
||||||
}, {
|
uninstall :quit => 'com.example.foo',
|
||||||
message: extra_line_msg,
|
:kext => 'com.example.foo.kextextension'
|
||||||
severity: :convention,
|
end
|
||||||
line: 5,
|
CASK
|
||||||
column: 0,
|
end
|
||||||
source: "\n",
|
|
||||||
}, {
|
shared_examples "caveats" do
|
||||||
message: extra_line_msg,
|
it "reports an offense for an incorrectly grouped `caveats` stanza" do
|
||||||
severity: :convention,
|
# Indent all except the first line.
|
||||||
line: 7,
|
interpolated_caveats = caveats.strip
|
||||||
column: 0,
|
|
||||||
source: "\n",
|
expect_offense <<~CASK
|
||||||
}, {
|
|
||||||
message: missing_line_msg,
|
|
||||||
severity: :convention,
|
|
||||||
line: 11,
|
|
||||||
column: 0,
|
|
||||||
source: " uninstall :quit => 'com.example.foo',",
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
|
||||||
|
|
||||||
include_examples "autocorrects source"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when many stanzas and variable assignments are incorrectly grouped" do
|
|
||||||
let(:source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
arch arm: "arm64", intel: "x86_64"
|
|
||||||
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
|
||||||
|
|
||||||
platform = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
|
||||||
version :latest
|
|
||||||
sha256 :no_check
|
|
||||||
url 'https://foo.brew.sh/foo.zip'
|
|
||||||
|
|
||||||
name 'Foo'
|
|
||||||
|
|
||||||
homepage 'https://foo.brew.sh'
|
|
||||||
|
|
||||||
app 'Foo.app'
|
|
||||||
uninstall :quit => 'com.example.foo',
|
|
||||||
:kext => 'com.example.foo.kextextension'
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
arch arm: "arm64", intel: "x86_64"
|
|
||||||
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
|
||||||
platform = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
|
||||||
|
|
||||||
version :latest
|
|
||||||
sha256 :no_check
|
|
||||||
|
|
||||||
url 'https://foo.brew.sh/foo.zip'
|
|
||||||
name 'Foo'
|
|
||||||
homepage 'https://foo.brew.sh'
|
|
||||||
|
|
||||||
app 'Foo.app'
|
|
||||||
|
|
||||||
uninstall :quit => 'com.example.foo',
|
|
||||||
:kext => 'com.example.foo.kextextension'
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
|
||||||
message: extra_line_msg,
|
|
||||||
severity: :convention,
|
|
||||||
line: 4,
|
|
||||||
column: 0,
|
|
||||||
source: "\n",
|
|
||||||
}, {
|
|
||||||
message: missing_line_msg,
|
|
||||||
severity: :convention,
|
|
||||||
line: 6,
|
|
||||||
column: 0,
|
|
||||||
source: " version :latest",
|
|
||||||
}, {
|
|
||||||
message: missing_line_msg,
|
|
||||||
severity: :convention,
|
|
||||||
line: 8,
|
|
||||||
column: 0,
|
|
||||||
source: " url 'https://foo.brew.sh/foo.zip'",
|
|
||||||
}, {
|
|
||||||
message: extra_line_msg,
|
|
||||||
severity: :convention,
|
|
||||||
line: 9,
|
|
||||||
column: 0,
|
|
||||||
source: "\n",
|
|
||||||
}, {
|
|
||||||
message: extra_line_msg,
|
|
||||||
severity: :convention,
|
|
||||||
line: 11,
|
|
||||||
column: 0,
|
|
||||||
source: "\n",
|
|
||||||
}, {
|
|
||||||
message: missing_line_msg,
|
|
||||||
severity: :convention,
|
|
||||||
line: 15,
|
|
||||||
column: 0,
|
|
||||||
source: " uninstall :quit => 'com.example.foo',",
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
|
||||||
|
|
||||||
include_examples "autocorrects source"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when caveats stanza is incorrectly grouped" do
|
|
||||||
let(:source) do
|
|
||||||
format(<<~CASK, caveats: caveats.strip)
|
|
||||||
cask 'foo' do
|
cask 'foo' do
|
||||||
version :latest
|
version :latest
|
||||||
sha256 :no_check
|
sha256 :no_check
|
||||||
url 'https://foo.brew.sh/foo.zip'
|
url 'https://foo.brew.sh/foo.zip'
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line
|
||||||
name 'Foo'
|
name 'Foo'
|
||||||
app 'Foo.app'
|
app 'Foo.app'
|
||||||
%<caveats>s
|
^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line
|
||||||
|
#{interpolated_caveats}
|
||||||
end
|
end
|
||||||
CASK
|
CASK
|
||||||
end
|
|
||||||
let(:correct_source) do
|
# Remove offense annotations.
|
||||||
format(<<~CASK, caveats: caveats.strip)
|
corrected_caveats = interpolated_caveats.gsub(/\n\s*\^+\s+.*$/, "")
|
||||||
|
|
||||||
|
expect_correction <<~CASK
|
||||||
cask 'foo' do
|
cask 'foo' do
|
||||||
version :latest
|
version :latest
|
||||||
sha256 :no_check
|
sha256 :no_check
|
||||||
@ -341,242 +209,232 @@ describe RuboCop::Cop::Cask::StanzaGrouping do
|
|||||||
|
|
||||||
app 'Foo.app'
|
app 'Foo.app'
|
||||||
|
|
||||||
%<caveats>s
|
#{corrected_caveats}
|
||||||
end
|
end
|
||||||
CASK
|
CASK
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "when caveats is a one-line string" do
|
context "when `caveats` is a one-line string" do
|
||||||
let(:caveats) { "caveats 'This is a one-line caveat.'" }
|
let(:caveats) do
|
||||||
|
<<~CAVEATS
|
||||||
include_examples "autocorrects source"
|
caveats 'This is a one-line caveat.'
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line
|
||||||
|
CAVEATS
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when caveats is a heredoc" do
|
include_examples "caveats"
|
||||||
let(:caveats) do
|
end
|
||||||
<<~CAVEATS
|
|
||||||
|
context "when `caveats` is a heredoc" do
|
||||||
|
let(:caveats) do
|
||||||
|
<<~CAVEATS
|
||||||
caveats <<~EOS
|
caveats <<~EOS
|
||||||
This is a multiline caveat.
|
^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line
|
||||||
|
This is a multiline caveat.
|
||||||
|
|
||||||
Let's hope it doesn't cause any problems!
|
Let's hope it doesn't cause any problems!
|
||||||
EOS
|
EOS
|
||||||
CAVEATS
|
CAVEATS
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "autocorrects source"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when caveats is a block" do
|
include_examples "caveats"
|
||||||
let(:caveats) do
|
end
|
||||||
<<~CAVEATS
|
|
||||||
|
context "when `caveats` is a block" do
|
||||||
|
let(:caveats) do
|
||||||
|
<<~CAVEATS
|
||||||
caveats do
|
caveats do
|
||||||
puts 'This is a multiline caveat.'
|
^^^^^^^^^^^^ stanza groups should be separated by a single empty line
|
||||||
|
puts 'This is a multiline caveat.'
|
||||||
|
|
||||||
puts "Let's hope it doesn't cause any problems!"
|
puts "Let's hope it doesn't cause any problems!"
|
||||||
end
|
end
|
||||||
CAVEATS
|
CAVEATS
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "autocorrects source"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
include_examples "caveats"
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when the postflight stanza is incorrectly grouped" do
|
it "reports an offense for an incorrectly grouped `postflight` stanza" do
|
||||||
let(:source) do
|
expect_offense <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
version :latest
|
||||||
version :latest
|
sha256 :no_check
|
||||||
sha256 :no_check
|
url 'https://foo.brew.sh/foo.zip'
|
||||||
url 'https://foo.brew.sh/foo.zip'
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line
|
||||||
name 'Foo'
|
name 'Foo'
|
||||||
app 'Foo.app'
|
app 'Foo.app'
|
||||||
postflight do
|
^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line
|
||||||
puts 'We have liftoff!'
|
postflight do
|
||||||
end
|
^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line
|
||||||
|
puts 'We have liftoff!'
|
||||||
end
|
end
|
||||||
CASK
|
end
|
||||||
end
|
CASK
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
version :latest
|
|
||||||
sha256 :no_check
|
|
||||||
|
|
||||||
url 'https://foo.brew.sh/foo.zip'
|
expect_correction <<~CASK
|
||||||
name 'Foo'
|
cask 'foo' do
|
||||||
|
version :latest
|
||||||
|
sha256 :no_check
|
||||||
|
|
||||||
app 'Foo.app'
|
url 'https://foo.brew.sh/foo.zip'
|
||||||
|
name 'Foo'
|
||||||
|
|
||||||
postflight do
|
app 'Foo.app'
|
||||||
puts 'We have liftoff!'
|
|
||||||
end
|
postflight do
|
||||||
|
puts 'We have liftoff!'
|
||||||
end
|
end
|
||||||
CASK
|
end
|
||||||
end
|
CASK
|
||||||
|
|
||||||
include_examples "autocorrects source"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when a stanza has a comment" do
|
it "reports an offense for incorrectly grouped comments" do
|
||||||
let(:source) do
|
expect_offense <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
version :latest
|
||||||
version :latest
|
sha256 :no_check
|
||||||
sha256 :no_check
|
# comment with an empty line between
|
||||||
# comment with an empty line between
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line
|
||||||
|
|
||||||
# comment directly above
|
# comment directly above
|
||||||
postflight do
|
postflight do
|
||||||
puts 'We have liftoff!'
|
puts 'We have liftoff!'
|
||||||
end
|
|
||||||
url 'https://foo.brew.sh/foo.zip'
|
|
||||||
name 'Foo'
|
|
||||||
app 'Foo.app'
|
|
||||||
end
|
end
|
||||||
CASK
|
url 'https://foo.brew.sh/foo.zip'
|
||||||
end
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line
|
||||||
let(:correct_source) do
|
name 'Foo'
|
||||||
<<~CASK
|
app 'Foo.app'
|
||||||
cask 'foo' do
|
^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line
|
||||||
version :latest
|
end
|
||||||
sha256 :no_check
|
CASK
|
||||||
|
|
||||||
# comment with an empty line between
|
expect_correction <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
version :latest
|
||||||
|
sha256 :no_check
|
||||||
|
|
||||||
# comment directly above
|
# comment with an empty line between
|
||||||
postflight do
|
|
||||||
puts 'We have liftoff!'
|
|
||||||
end
|
|
||||||
|
|
||||||
url 'https://foo.brew.sh/foo.zip'
|
# comment directly above
|
||||||
name 'Foo'
|
postflight do
|
||||||
|
puts 'We have liftoff!'
|
||||||
app 'Foo.app'
|
|
||||||
end
|
end
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "autocorrects source"
|
url 'https://foo.brew.sh/foo.zip'
|
||||||
|
name 'Foo'
|
||||||
|
|
||||||
|
app 'Foo.app'
|
||||||
|
end
|
||||||
|
CASK
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when a stanza has a comment and there is a variable assignment" do
|
it "reports an offense for incorrectly grouped comments and variable assignments" do
|
||||||
let(:source) do
|
expect_offense <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
arch arm: "arm64", intel: "x86_64"
|
||||||
arch arm: "arm64", intel: "x86_64"
|
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
||||||
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
# comment with an empty line between
|
||||||
# comment with an empty line between
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line
|
||||||
version :latest
|
version :latest
|
||||||
sha256 :no_check
|
sha256 :no_check
|
||||||
|
|
||||||
# comment directly above
|
# comment directly above
|
||||||
postflight do
|
postflight do
|
||||||
puts 'We have liftoff!'
|
puts 'We have liftoff!'
|
||||||
end
|
|
||||||
url 'https://foo.brew.sh/foo.zip'
|
|
||||||
name 'Foo'
|
|
||||||
app 'Foo.app'
|
|
||||||
end
|
end
|
||||||
CASK
|
url 'https://foo.brew.sh/foo.zip'
|
||||||
end
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line
|
||||||
let(:correct_source) do
|
name 'Foo'
|
||||||
<<~CASK
|
app 'Foo.app'
|
||||||
cask 'foo' do
|
^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line
|
||||||
arch arm: "arm64", intel: "x86_64"
|
end
|
||||||
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
CASK
|
||||||
|
|
||||||
# comment with an empty line between
|
expect_correction <<~CASK
|
||||||
version :latest
|
cask 'foo' do
|
||||||
sha256 :no_check
|
arch arm: "arm64", intel: "x86_64"
|
||||||
|
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
||||||
|
|
||||||
# comment directly above
|
# comment with an empty line between
|
||||||
postflight do
|
version :latest
|
||||||
puts 'We have liftoff!'
|
sha256 :no_check
|
||||||
end
|
|
||||||
|
|
||||||
url 'https://foo.brew.sh/foo.zip'
|
# comment directly above
|
||||||
name 'Foo'
|
postflight do
|
||||||
|
puts 'We have liftoff!'
|
||||||
app 'Foo.app'
|
|
||||||
end
|
end
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "autocorrects source"
|
url 'https://foo.brew.sh/foo.zip'
|
||||||
|
name 'Foo'
|
||||||
|
|
||||||
|
app 'Foo.app'
|
||||||
|
end
|
||||||
|
CASK
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when stanzas are nested one-level in `on_*` blocks" do
|
it "reports an offense for incorrectly grouped stanzas in `on_*` blocks" do
|
||||||
describe "basic nesting" do
|
expect_offense <<~CASK
|
||||||
let(:source) do
|
cask 'foo' do
|
||||||
<<~CASK
|
on_arm do
|
||||||
cask 'foo' do
|
version "1.0.2"
|
||||||
on_arm do
|
|
||||||
version "1.0.2"
|
|
||||||
|
|
||||||
sha256 :no_check
|
^{} stanzas within the same group should have no lines between them
|
||||||
end
|
sha256 :no_check
|
||||||
on_intel do
|
end
|
||||||
version "0.9.8"
|
on_intel do
|
||||||
sha256 :no_check
|
version "0.9.8"
|
||||||
url "https://foo.brew.sh/foo-intel.zip"
|
sha256 :no_check
|
||||||
end
|
url "https://foo.brew.sh/foo-intel.zip"
|
||||||
end
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ stanza groups should be separated by a single empty line
|
||||||
CASK
|
end
|
||||||
end
|
end
|
||||||
|
CASK
|
||||||
|
|
||||||
let(:correct_source) do
|
expect_correction <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
on_arm do
|
||||||
on_arm do
|
version "1.0.2"
|
||||||
version "1.0.2"
|
sha256 :no_check
|
||||||
sha256 :no_check
|
end
|
||||||
end
|
on_intel do
|
||||||
on_intel do
|
version "0.9.8"
|
||||||
version "0.9.8"
|
sha256 :no_check
|
||||||
sha256 :no_check
|
|
||||||
|
|
||||||
url "https://foo.brew.sh/foo-intel.zip"
|
url "https://foo.brew.sh/foo-intel.zip"
|
||||||
end
|
end
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
end
|
||||||
|
CASK
|
||||||
|
end
|
||||||
|
|
||||||
include_examples "autocorrects source"
|
it "reports an offense for incorrectly grouped stanzas with comments in `on_*` blocks" do
|
||||||
end
|
expect_offense <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
on_arm do
|
||||||
|
version "1.0.2"
|
||||||
|
|
||||||
describe "nested `on_*` blocks with comments" do
|
^{} stanzas within the same group should have no lines between them
|
||||||
let(:source) do
|
sha256 :no_check # comment on same line
|
||||||
<<~CASK
|
end
|
||||||
cask 'foo' do
|
on_intel do
|
||||||
on_arm do
|
version "0.9.8"
|
||||||
version "1.0.2"
|
sha256 :no_check
|
||||||
|
end
|
||||||
sha256 :no_check # comment on same line
|
|
||||||
end
|
|
||||||
on_intel do
|
|
||||||
version "0.9.8"
|
|
||||||
sha256 :no_check
|
|
||||||
end
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
end
|
||||||
|
CASK
|
||||||
|
|
||||||
let(:correct_source) do
|
expect_correction <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
on_arm do
|
||||||
on_arm do
|
version "1.0.2"
|
||||||
version "1.0.2"
|
sha256 :no_check # comment on same line
|
||||||
sha256 :no_check # comment on same line
|
end
|
||||||
end
|
on_intel do
|
||||||
on_intel do
|
version "0.9.8"
|
||||||
version "0.9.8"
|
sha256 :no_check
|
||||||
sha256 :no_check
|
end
|
||||||
end
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
end
|
||||||
|
CASK
|
||||||
include_examples "autocorrects source"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,501 +1,385 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "rubocops/rubocop-cask"
|
require "rubocops/rubocop-cask"
|
||||||
require "test/rubocops/cask/shared_examples/cask_cop"
|
|
||||||
|
|
||||||
describe RuboCop::Cop::Cask::StanzaOrder, :config do
|
describe RuboCop::Cop::Cask::StanzaOrder, :config do
|
||||||
include CaskCop
|
it "accepts a sole stanza" do
|
||||||
|
expect_no_offenses <<~CASK
|
||||||
context "when there is only one stanza" do
|
cask 'foo' do
|
||||||
let(:source) do
|
version :latest
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
version :latest
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when no stanzas are out of order" do
|
|
||||||
let(:source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
arch arm: "arm", intel: "x86_64"
|
|
||||||
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
|
||||||
version :latest
|
|
||||||
sha256 :no_check
|
|
||||||
foo = "bar"
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when one pair of stanzas is out of order" do
|
|
||||||
let(:source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
sha256 :no_check
|
|
||||||
version :latest
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
version :latest
|
|
||||||
sha256 :no_check
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
|
||||||
message: "`sha256` stanza out of order",
|
|
||||||
severity: :convention,
|
|
||||||
line: 2,
|
|
||||||
column: 2,
|
|
||||||
source: "sha256 :no_check",
|
|
||||||
}, {
|
|
||||||
message: "`version` stanza out of order",
|
|
||||||
severity: :convention,
|
|
||||||
line: 3,
|
|
||||||
column: 2,
|
|
||||||
source: "version :latest",
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
|
||||||
|
|
||||||
include_examples "autocorrects source"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when the arch stanza is out of order" do
|
|
||||||
let(:source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
version :latest
|
|
||||||
sha256 :no_check
|
|
||||||
arch arm: "arm", intel: "x86_64"
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
arch arm: "arm", intel: "x86_64"
|
|
||||||
version :latest
|
|
||||||
sha256 :no_check
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
|
||||||
message: "`version` stanza out of order",
|
|
||||||
severity: :convention,
|
|
||||||
line: 2,
|
|
||||||
column: 2,
|
|
||||||
source: "version :latest",
|
|
||||||
}, {
|
|
||||||
message: "`sha256` stanza out of order",
|
|
||||||
severity: :convention,
|
|
||||||
line: 3,
|
|
||||||
column: 2,
|
|
||||||
source: "sha256 :no_check",
|
|
||||||
}, {
|
|
||||||
message: "`arch` stanza out of order",
|
|
||||||
severity: :convention,
|
|
||||||
line: 4,
|
|
||||||
column: 2,
|
|
||||||
source: 'arch arm: "arm", intel: "x86_64"',
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
|
||||||
|
|
||||||
include_examples "autocorrects source"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when an arch variable assignment is out of order" do
|
|
||||||
let(:source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
arch arm: "arm", intel: "x86_64"
|
|
||||||
sha256 :no_check
|
|
||||||
version :latest
|
|
||||||
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
arch arm: "arm", intel: "x86_64"
|
|
||||||
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
|
||||||
version :latest
|
|
||||||
sha256 :no_check
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
|
||||||
message: "`sha256` stanza out of order",
|
|
||||||
severity: :convention,
|
|
||||||
line: 3,
|
|
||||||
column: 2,
|
|
||||||
source: "sha256 :no_check",
|
|
||||||
}, {
|
|
||||||
message: "`on_arch_conditional` stanza out of order",
|
|
||||||
severity: :convention,
|
|
||||||
line: 5,
|
|
||||||
column: 2,
|
|
||||||
source: 'folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"',
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
|
||||||
|
|
||||||
include_examples "autocorrects source"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when an arch variable assignment is above the arch stanza" do
|
|
||||||
let(:source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
|
||||||
arch arm: "arm", intel: "x86_64"
|
|
||||||
version :latest
|
|
||||||
sha256 :no_check
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
arch arm: "arm", intel: "x86_64"
|
|
||||||
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
|
||||||
version :latest
|
|
||||||
sha256 :no_check
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
|
||||||
message: "`on_arch_conditional` stanza out of order",
|
|
||||||
severity: :convention,
|
|
||||||
line: 2,
|
|
||||||
column: 2,
|
|
||||||
source: 'folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"',
|
|
||||||
}, {
|
|
||||||
message: "`arch` stanza out of order",
|
|
||||||
severity: :convention,
|
|
||||||
line: 3,
|
|
||||||
column: 2,
|
|
||||||
source: 'arch arm: "arm", intel: "x86_64"',
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
|
||||||
|
|
||||||
include_examples "autocorrects source"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when many stanzas are out of order" do
|
|
||||||
let(:source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
url 'https://foo.brew.sh/foo.zip'
|
|
||||||
uninstall :quit => 'com.example.foo',
|
|
||||||
:kext => 'com.example.foo.kext'
|
|
||||||
version :latest
|
|
||||||
app 'Foo.app'
|
|
||||||
sha256 :no_check
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
version :latest
|
|
||||||
sha256 :no_check
|
|
||||||
url 'https://foo.brew.sh/foo.zip'
|
|
||||||
app 'Foo.app'
|
|
||||||
uninstall :quit => 'com.example.foo',
|
|
||||||
:kext => 'com.example.foo.kext'
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
|
||||||
message: "`url` stanza out of order",
|
|
||||||
severity: :convention,
|
|
||||||
line: 2,
|
|
||||||
column: 2,
|
|
||||||
source: "url 'https://foo.brew.sh/foo.zip'",
|
|
||||||
}, {
|
|
||||||
message: "`uninstall` stanza out of order",
|
|
||||||
severity: :convention,
|
|
||||||
line: 3,
|
|
||||||
column: 2,
|
|
||||||
source: "uninstall :quit => 'com.example.foo'," \
|
|
||||||
"\n :kext => 'com.example.foo.kext'",
|
|
||||||
}, {
|
|
||||||
message: "`version` stanza out of order",
|
|
||||||
severity: :convention,
|
|
||||||
line: 5,
|
|
||||||
column: 2,
|
|
||||||
source: "version :latest",
|
|
||||||
}, {
|
|
||||||
message: "`sha256` stanza out of order",
|
|
||||||
severity: :convention,
|
|
||||||
line: 7,
|
|
||||||
column: 2,
|
|
||||||
source: "sha256 :no_check",
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
|
||||||
|
|
||||||
include_examples "autocorrects source"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when a stanza appears multiple times" do
|
|
||||||
let(:source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
name 'Foo'
|
|
||||||
url 'https://foo.brew.sh/foo.zip'
|
|
||||||
name 'FancyFoo'
|
|
||||||
version :latest
|
|
||||||
app 'Foo.app'
|
|
||||||
sha256 :no_check
|
|
||||||
name 'FunkyFoo'
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
version :latest
|
|
||||||
sha256 :no_check
|
|
||||||
url 'https://foo.brew.sh/foo.zip'
|
|
||||||
name 'Foo'
|
|
||||||
name 'FancyFoo'
|
|
||||||
name 'FunkyFoo'
|
|
||||||
app 'Foo.app'
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
it "preserves the original order" do
|
|
||||||
expect_autocorrected_source(source, correct_source)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when a stanza has a comment" do
|
|
||||||
let(:source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
version :latest
|
|
||||||
# comment with an empty line between
|
|
||||||
|
|
||||||
# comment directly above
|
|
||||||
postflight do
|
|
||||||
puts 'We have liftoff!'
|
|
||||||
end
|
|
||||||
sha256 :no_check # comment on same line
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
version :latest
|
|
||||||
sha256 :no_check # comment on same line
|
|
||||||
# comment with an empty line between
|
|
||||||
|
|
||||||
# comment directly above
|
|
||||||
postflight do
|
|
||||||
puts 'We have liftoff!'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "autocorrects source"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when a variable assignment is out of order with a comment" do
|
|
||||||
let(:source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
version :latest
|
|
||||||
sha256 :no_check
|
|
||||||
# comment with an empty line between
|
|
||||||
|
|
||||||
# comment directly above
|
|
||||||
postflight do
|
|
||||||
puts 'We have liftoff!'
|
|
||||||
end
|
|
||||||
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin" # comment on same line
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin" # comment on same line
|
|
||||||
version :latest
|
|
||||||
sha256 :no_check
|
|
||||||
# comment with an empty line between
|
|
||||||
|
|
||||||
# comment directly above
|
|
||||||
postflight do
|
|
||||||
puts 'We have liftoff!'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "autocorrects source"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when the caveats stanza is out of order" do
|
|
||||||
let(:source) do
|
|
||||||
format(<<~CASK, caveats: caveats.strip)
|
|
||||||
cask 'foo' do
|
|
||||||
name 'Foo'
|
|
||||||
url 'https://foo.brew.sh/foo.zip'
|
|
||||||
%<caveats>s
|
|
||||||
version :latest
|
|
||||||
app 'Foo.app'
|
|
||||||
sha256 :no_check
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:correct_source) do
|
|
||||||
format(<<~CASK, caveats: caveats.strip)
|
|
||||||
cask 'foo' do
|
|
||||||
version :latest
|
|
||||||
sha256 :no_check
|
|
||||||
url 'https://foo.brew.sh/foo.zip'
|
|
||||||
name 'Foo'
|
|
||||||
app 'Foo.app'
|
|
||||||
%<caveats>s
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when caveats is a one-line string" do
|
|
||||||
let(:caveats) { "caveats 'This is a one-line caveat.'" }
|
|
||||||
|
|
||||||
include_examples "autocorrects source"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when caveats is a heredoc" do
|
|
||||||
let(:caveats) do
|
|
||||||
<<~CAVEATS
|
|
||||||
caveats <<~EOS
|
|
||||||
This is a multiline caveat.
|
|
||||||
|
|
||||||
Let's hope it doesn't cause any problems!
|
|
||||||
EOS
|
|
||||||
CAVEATS
|
|
||||||
end
|
end
|
||||||
|
CASK
|
||||||
|
end
|
||||||
|
|
||||||
include_examples "autocorrects source"
|
it "accepts when all stanzas are in order" do
|
||||||
end
|
expect_no_offenses <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
context "when caveats is a block" do
|
arch arm: "arm", intel: "x86_64"
|
||||||
let(:caveats) do
|
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
||||||
<<~CAVEATS
|
version :latest
|
||||||
caveats do
|
sha256 :no_check
|
||||||
puts 'This is a multiline caveat.'
|
foo = "bar"
|
||||||
|
|
||||||
puts "Let's hope it doesn't cause any problems!"
|
|
||||||
end
|
|
||||||
CAVEATS
|
|
||||||
end
|
end
|
||||||
|
CASK
|
||||||
include_examples "autocorrects source"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when the postflight stanza is out of order" do
|
it "reports an offense when stanzas are out of order" do
|
||||||
let(:source) do
|
expect_offense <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
|
sha256 :no_check
|
||||||
|
^^^^^^^^^^^^^^^^ `sha256` stanza out of order
|
||||||
|
version :latest
|
||||||
|
^^^^^^^^^^^^^^^ `version` stanza out of order
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
|
||||||
|
expect_correction <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
version :latest
|
||||||
|
sha256 :no_check
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
end
|
||||||
|
|
||||||
|
it "reports an offense when an `arch` stanza is out of order" do
|
||||||
|
expect_offense <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
version :latest
|
||||||
|
^^^^^^^^^^^^^^^ `version` stanza out of order
|
||||||
|
sha256 :no_check
|
||||||
|
^^^^^^^^^^^^^^^^ `sha256` stanza out of order
|
||||||
|
arch arm: "arm", intel: "x86_64"
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `arch` stanza out of order
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
|
||||||
|
expect_correction <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
arch arm: "arm", intel: "x86_64"
|
||||||
|
version :latest
|
||||||
|
sha256 :no_check
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
end
|
||||||
|
|
||||||
|
it "reports an offense when an `on_arch_conditional` variable assignment is out of order" do
|
||||||
|
expect_offense <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
arch arm: "arm", intel: "x86_64"
|
||||||
|
sha256 :no_check
|
||||||
|
^^^^^^^^^^^^^^^^ `sha256` stanza out of order
|
||||||
|
version :latest
|
||||||
|
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `on_arch_conditional` stanza out of order
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
|
||||||
|
expect_correction <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
arch arm: "arm", intel: "x86_64"
|
||||||
|
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
||||||
|
version :latest
|
||||||
|
sha256 :no_check
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
end
|
||||||
|
|
||||||
|
it "reports an offense when an `on_arch_conditional` variable assignment is above an `arch` stanza" do
|
||||||
|
expect_offense <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `on_arch_conditional` stanza out of order
|
||||||
|
arch arm: "arm", intel: "x86_64"
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `arch` stanza out of order
|
||||||
|
version :latest
|
||||||
|
sha256 :no_check
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
|
||||||
|
expect_correction <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
arch arm: "arm", intel: "x86_64"
|
||||||
|
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
||||||
|
version :latest
|
||||||
|
sha256 :no_check
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
end
|
||||||
|
|
||||||
|
it "reports an offense when multiple stanzas are out of order" do
|
||||||
|
expect_offense <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
url 'https://foo.brew.sh/foo.zip'
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `url` stanza out of order
|
||||||
|
uninstall :quit => 'com.example.foo',
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `uninstall` stanza out of order
|
||||||
|
:kext => 'com.example.foo.kext'
|
||||||
|
version :latest
|
||||||
|
^^^^^^^^^^^^^^^ `version` stanza out of order
|
||||||
|
app 'Foo.app'
|
||||||
|
sha256 :no_check
|
||||||
|
^^^^^^^^^^^^^^^^ `sha256` stanza out of order
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
|
||||||
|
expect_correction <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
version :latest
|
||||||
|
sha256 :no_check
|
||||||
|
url 'https://foo.brew.sh/foo.zip'
|
||||||
|
app 'Foo.app'
|
||||||
|
uninstall :quit => 'com.example.foo',
|
||||||
|
:kext => 'com.example.foo.kext'
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not reorder multiple stanzas of the same type" do
|
||||||
|
expect_offense <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
name 'Foo'
|
||||||
|
^^^^^^^^^^ `name` stanza out of order
|
||||||
|
url 'https://foo.brew.sh/foo.zip'
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `url` stanza out of order
|
||||||
|
name 'FancyFoo'
|
||||||
|
^^^^^^^^^^^^^^^ `name` stanza out of order
|
||||||
|
version :latest
|
||||||
|
^^^^^^^^^^^^^^^ `version` stanza out of order
|
||||||
|
app 'Foo.app'
|
||||||
|
^^^^^^^^^^^^^ `app` stanza out of order
|
||||||
|
sha256 :no_check
|
||||||
|
^^^^^^^^^^^^^^^^ `sha256` stanza out of order
|
||||||
|
name 'FunkyFoo'
|
||||||
|
^^^^^^^^^^^^^^^ `name` stanza out of order
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
|
||||||
|
expect_correction <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
version :latest
|
||||||
|
sha256 :no_check
|
||||||
|
url 'https://foo.brew.sh/foo.zip'
|
||||||
|
name 'Foo'
|
||||||
|
name 'FancyFoo'
|
||||||
|
name 'FunkyFoo'
|
||||||
|
app 'Foo.app'
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
end
|
||||||
|
|
||||||
|
it "keeps associated comments when auto-correcting" do
|
||||||
|
expect_offense <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
version :latest
|
||||||
|
# comment with an empty line between
|
||||||
|
|
||||||
|
# comment directly above
|
||||||
|
postflight do
|
||||||
|
^^^^^^^^^^^^^ `postflight` stanza out of order
|
||||||
|
puts 'We have liftoff!'
|
||||||
|
end
|
||||||
|
sha256 :no_check # comment on same line
|
||||||
|
^^^^^^^^^^^^^^^^ `sha256` stanza out of order
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
|
||||||
|
expect_correction <<~CASK, loop: false
|
||||||
|
cask 'foo' do
|
||||||
|
version :latest
|
||||||
|
sha256 :no_check # comment on same line
|
||||||
|
# comment with an empty line between
|
||||||
|
|
||||||
|
# comment directly above
|
||||||
|
postflight do
|
||||||
|
puts 'We have liftoff!'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
end
|
||||||
|
|
||||||
|
it "reports an offense when an `on_arch_conditional` variable assignment with a comment is out of order" do
|
||||||
|
expect_offense <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
version :latest
|
||||||
|
^^^^^^^^^^^^^^^ `version` stanza out of order
|
||||||
|
sha256 :no_check
|
||||||
|
^^^^^^^^^^^^^^^^ `sha256` stanza out of order
|
||||||
|
# comment with an empty line between
|
||||||
|
|
||||||
|
# comment directly above
|
||||||
|
postflight do
|
||||||
|
^^^^^^^^^^^^^ `postflight` stanza out of order
|
||||||
|
puts 'We have liftoff!'
|
||||||
|
end
|
||||||
|
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin" # comment on same line
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `on_arch_conditional` stanza out of order
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
|
||||||
|
expect_correction <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin" # comment on same line
|
||||||
|
version :latest
|
||||||
|
sha256 :no_check
|
||||||
|
# comment with an empty line between
|
||||||
|
|
||||||
|
# comment directly above
|
||||||
|
postflight do
|
||||||
|
puts 'We have liftoff!'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
end
|
||||||
|
|
||||||
|
shared_examples "caveats" do
|
||||||
|
it "reports an offense when a `caveats` stanza is out of order" do
|
||||||
|
# Indent all except the first line.
|
||||||
|
interpolated_caveats = caveats.lines.map { |l| " #{l}" }.join.strip
|
||||||
|
|
||||||
|
expect_offense <<~CASK
|
||||||
cask 'foo' do
|
cask 'foo' do
|
||||||
name 'Foo'
|
name 'Foo'
|
||||||
|
^^^^^^^^^^ `name` stanza out of order
|
||||||
url 'https://foo.brew.sh/foo.zip'
|
url 'https://foo.brew.sh/foo.zip'
|
||||||
postflight do
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `url` stanza out of order
|
||||||
puts 'We have liftoff!'
|
#{interpolated_caveats}
|
||||||
end
|
|
||||||
version :latest
|
version :latest
|
||||||
|
^^^^^^^^^^^^^^^ `version` stanza out of order
|
||||||
app 'Foo.app'
|
app 'Foo.app'
|
||||||
sha256 :no_check
|
sha256 :no_check
|
||||||
|
^^^^^^^^^^^^^^^^ `sha256` stanza out of order
|
||||||
end
|
end
|
||||||
CASK
|
CASK
|
||||||
end
|
|
||||||
let(:correct_source) do
|
# Remove offense annotations.
|
||||||
<<~CASK
|
corrected_caveats = interpolated_caveats.gsub(/\n\s*\^+\s+.*$/, "")
|
||||||
|
|
||||||
|
expect_correction <<~CASK
|
||||||
cask 'foo' do
|
cask 'foo' do
|
||||||
version :latest
|
version :latest
|
||||||
sha256 :no_check
|
sha256 :no_check
|
||||||
url 'https://foo.brew.sh/foo.zip'
|
url 'https://foo.brew.sh/foo.zip'
|
||||||
name 'Foo'
|
name 'Foo'
|
||||||
app 'Foo.app'
|
app 'Foo.app'
|
||||||
postflight do
|
#{corrected_caveats}
|
||||||
puts 'We have liftoff!'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
CASK
|
CASK
|
||||||
end
|
end
|
||||||
|
|
||||||
include_examples "autocorrects source"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when `on_arch` blocks and their contents are out of order" do
|
context "when caveats is a one-line string" do
|
||||||
let(:source) do
|
let(:caveats) do
|
||||||
<<~CASK
|
<<~CAVEATS
|
||||||
cask 'foo' do
|
caveats 'This is a one-line caveat.'
|
||||||
on_intel do
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `caveats` stanza out of order
|
||||||
url "https://foo.brew.sh/foo-intel.zip"
|
CAVEATS
|
||||||
|
|
||||||
version :latest
|
|
||||||
sha256 :no_check
|
|
||||||
end
|
|
||||||
on_arm do
|
|
||||||
version :latest
|
|
||||||
sha256 :no_check
|
|
||||||
|
|
||||||
url "https://foo.brew.sh/foo-arm.zip"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:correct_source) do
|
include_examples "caveats"
|
||||||
<<~CASK
|
end
|
||||||
cask 'foo' do
|
|
||||||
on_arm do
|
|
||||||
version :latest
|
|
||||||
sha256 :no_check
|
|
||||||
|
|
||||||
url "https://foo.brew.sh/foo-arm.zip"
|
context "when caveats is a heredoc" do
|
||||||
end
|
let(:caveats) do
|
||||||
on_intel do
|
<<~CAVEATS
|
||||||
version :latest
|
caveats <<~EOS
|
||||||
|
^^^^^^^^^^^^^^ `caveats` stanza out of order
|
||||||
|
This is a multiline caveat.
|
||||||
|
|
||||||
sha256 :no_check
|
Let's hope it doesn't cause any problems!
|
||||||
url "https://foo.brew.sh/foo-intel.zip"
|
EOS
|
||||||
end
|
CAVEATS
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
end
|
||||||
|
|
||||||
include_examples "autocorrects source"
|
include_examples "caveats"
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when caveats is a block" do
|
||||||
|
let(:caveats) do
|
||||||
|
<<~CAVEATS
|
||||||
|
caveats do
|
||||||
|
^^^^^^^^^^ `caveats` stanza out of order
|
||||||
|
puts 'This is a multiline caveat.'
|
||||||
|
|
||||||
|
puts "Let's hope it doesn't cause any problems!"
|
||||||
|
end
|
||||||
|
CAVEATS
|
||||||
|
end
|
||||||
|
|
||||||
|
include_examples "caveats"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "reports an offense when the `postflight` stanza is out of order" do
|
||||||
|
expect_offense <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
name 'Foo'
|
||||||
|
^^^^^^^^^^ `name` stanza out of order
|
||||||
|
url 'https://foo.brew.sh/foo.zip'
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `url` stanza out of order
|
||||||
|
postflight do
|
||||||
|
^^^^^^^^^^^^^ `postflight` stanza out of order
|
||||||
|
puts 'We have liftoff!'
|
||||||
|
end
|
||||||
|
version :latest
|
||||||
|
^^^^^^^^^^^^^^^ `version` stanza out of order
|
||||||
|
app 'Foo.app'
|
||||||
|
sha256 :no_check
|
||||||
|
^^^^^^^^^^^^^^^^ `sha256` stanza out of order
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
|
||||||
|
expect_correction <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
version :latest
|
||||||
|
sha256 :no_check
|
||||||
|
url 'https://foo.brew.sh/foo.zip'
|
||||||
|
name 'Foo'
|
||||||
|
app 'Foo.app'
|
||||||
|
postflight do
|
||||||
|
puts 'We have liftoff!'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
end
|
||||||
|
|
||||||
|
it "supports `on_arch` blocks and their contents" do
|
||||||
|
expect_offense <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
on_intel do
|
||||||
|
^^^^^^^^^^^ `on_intel` stanza out of order
|
||||||
|
url "https://foo.brew.sh/foo-intel.zip"
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `url` stanza out of order
|
||||||
|
|
||||||
|
version :latest
|
||||||
|
^^^^^^^^^^^^^^^ `version` stanza out of order
|
||||||
|
sha256 :no_check
|
||||||
|
^^^^^^^^^^^^^^^^ `sha256` stanza out of order
|
||||||
|
end
|
||||||
|
on_arm do
|
||||||
|
^^^^^^^^^ `on_arm` stanza out of order
|
||||||
|
version :latest
|
||||||
|
sha256 :no_check
|
||||||
|
|
||||||
|
url "https://foo.brew.sh/foo-arm.zip"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
|
||||||
|
expect_correction <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
on_arm do
|
||||||
|
version :latest
|
||||||
|
sha256 :no_check
|
||||||
|
|
||||||
|
url "https://foo.brew.sh/foo-arm.zip"
|
||||||
|
end
|
||||||
|
on_intel do
|
||||||
|
version :latest
|
||||||
|
|
||||||
|
sha256 :no_check
|
||||||
|
url "https://foo.brew.sh/foo-intel.zip"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
CASK
|
||||||
end
|
end
|
||||||
|
|
||||||
it "registers an offense when `on_os` stanzas and their contents are out of order" do
|
it "registers an offense when `on_os` stanzas and their contents are out of order" do
|
||||||
|
@ -1,102 +1,57 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "rubocops/rubocop-cask"
|
require "rubocops/rubocop-cask"
|
||||||
require "test/rubocops/cask/shared_examples/cask_cop"
|
|
||||||
|
|
||||||
describe RuboCop::Cop::Cask::UrlLegacyCommaSeparators do
|
describe RuboCop::Cop::Cask::UrlLegacyCommaSeparators, :config do
|
||||||
include CaskCop
|
it "accepts a simple `version` interpolation" do
|
||||||
|
expect_no_offenses <<~'CASK'
|
||||||
subject(:cop) { described_class.new }
|
cask 'foo' do
|
||||||
|
version '1.1'
|
||||||
context "when url version interpolation does not include version.before_comma or version.after_comma" do
|
url 'https://foo.brew.sh/foo-#{version}.dmg'
|
||||||
let(:source) do
|
end
|
||||||
<<~CASK
|
CASK
|
||||||
cask 'foo' do
|
|
||||||
version '1.1'
|
|
||||||
url 'https://foo.brew.sh/foo-\#{version}.dmg'
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when the url uses csv" do
|
it "accepts an interpolation using `version.csv`" do
|
||||||
let(:source) do
|
expect_no_offenses <<~'CASK'
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
version '1.1,111'
|
||||||
version '1.1,111'
|
url 'https://foo.brew.sh/foo-#{version.csv.first}.dmg'
|
||||||
url 'https://foo.brew.sh/foo-\#{version.csv.first}.dmg'
|
end
|
||||||
end
|
CASK
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when the url uses version.before_comma" do
|
it "reports an offense for an interpolation using `version.before_comma`" do
|
||||||
let(:source) do
|
expect_offense <<~'CASK'
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
version '1.1,111'
|
||||||
version '1.1,111'
|
url 'https://foo.brew.sh/foo-#{version.before_comma}.dmg'
|
||||||
url 'https://foo.brew.sh/foo-\#{version.before_comma}.dmg'
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `version.csv.first` instead of `version.before_comma` and `version.csv.second` instead of `version.after_comma`.
|
||||||
end
|
end
|
||||||
CASK
|
CASK
|
||||||
end
|
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
version '1.1,111'
|
|
||||||
url 'https://foo.brew.sh/foo-\#{version.csv.first}.dmg'
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
|
||||||
message: "Cask/UrlLegacyCommaSeparators: Use 'version.csv.first' instead of 'version.before_comma' " \
|
|
||||||
"and 'version.csv.second' instead of 'version.after_comma'",
|
|
||||||
severity: :convention,
|
|
||||||
line: 3,
|
|
||||||
column: 6,
|
|
||||||
source: "'https://foo.brew.sh/foo-\#{version.before_comma}.dmg'",
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
expect_correction <<~'CASK'
|
||||||
|
cask 'foo' do
|
||||||
include_examples "autocorrects source"
|
version '1.1,111'
|
||||||
|
url 'https://foo.brew.sh/foo-#{version.csv.first}.dmg'
|
||||||
|
end
|
||||||
|
CASK
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when the url uses version.after_comma" do
|
it "reports an offense for an interpolation using `version.after_comma`" do
|
||||||
let(:source) do
|
expect_offense <<~'CASK'
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
version '1.1,111'
|
||||||
version '1.1,111'
|
url 'https://foo.brew.sh/foo-#{version.after_comma}.dmg'
|
||||||
url 'https://foo.brew.sh/foo-\#{version.after_comma}.dmg'
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `version.csv.first` instead of `version.before_comma` and `version.csv.second` instead of `version.after_comma`.
|
||||||
end
|
end
|
||||||
CASK
|
CASK
|
||||||
end
|
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
version '1.1,111'
|
|
||||||
url 'https://foo.brew.sh/foo-\#{version.csv.second}.dmg'
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
|
||||||
message: "Cask/UrlLegacyCommaSeparators: Use 'version.csv.first' instead of 'version.before_comma' " \
|
|
||||||
"and 'version.csv.second' instead of 'version.after_comma'",
|
|
||||||
severity: :convention,
|
|
||||||
line: 3,
|
|
||||||
column: 6,
|
|
||||||
source: "'https://foo.brew.sh/foo-\#{version.after_comma}.dmg'",
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
expect_correction <<~'CASK'
|
||||||
|
cask 'foo' do
|
||||||
include_examples "autocorrects source"
|
version '1.1,111'
|
||||||
|
url 'https://foo.brew.sh/foo-#{version.csv.second}.dmg'
|
||||||
|
end
|
||||||
|
CASK
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,138 +1,85 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "rubocops/rubocop-cask"
|
require "rubocops/rubocop-cask"
|
||||||
require "test/rubocops/cask/shared_examples/cask_cop"
|
|
||||||
|
|
||||||
describe RuboCop::Cop::Cask::Url do
|
describe RuboCop::Cop::Cask::Url, :config do
|
||||||
include CaskCop
|
it "accepts a `verified` value that does not start with a protocol" do
|
||||||
|
expect_no_offenses <<~CASK
|
||||||
|
cask "foo" do
|
||||||
|
url "https://example.com/download/foo-v1.2.0.dmg",
|
||||||
|
verified: "example.com/download/"
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
end
|
||||||
|
|
||||||
subject(:cop) { described_class.new }
|
it "reports an offense for a `verified` value that starts with a protocol" do
|
||||||
|
expect_offense <<~CASK
|
||||||
|
cask "foo" do
|
||||||
|
url "https://example.com/download/foo-v1.2.0.dmg",
|
||||||
|
verified: "https://example.com/download/"
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Verified URL parameter value should not contain a URL scheme.
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
|
||||||
context "when url 'verified' value does not start with a protocol" do
|
expect_correction <<~CASK
|
||||||
let(:source) do
|
cask "foo" do
|
||||||
<<~CASK
|
url "https://example.com/download/foo-v1.2.0.dmg",
|
||||||
|
verified: "example.com/download/"
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when then URL does not have a path and ends with a /" do
|
||||||
|
it "accepts a `verified` value ending with a /" do
|
||||||
|
expect_no_offenses <<~CASK
|
||||||
cask "foo" do
|
cask "foo" do
|
||||||
url "https://example.com/download/foo-v1.2.0.dmg",
|
url "https://example.org/",
|
||||||
verified: "example.com/download/"
|
verified: "example.org/"
|
||||||
end
|
end
|
||||||
CASK
|
CASK
|
||||||
end
|
end
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
it "reports an offense for a `verified` value not ending a /" do
|
||||||
|
expect_offense <<~CASK
|
||||||
|
cask "foo" do
|
||||||
|
url "https://example.org/",
|
||||||
|
verified: "example.org"
|
||||||
|
^^^^^^^^^^^^^ Verified URL parameter value should end with a /.
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
|
||||||
|
expect_correction <<~CASK
|
||||||
|
cask "foo" do
|
||||||
|
url "https://example.org/",
|
||||||
|
verified: "example.org/"
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when url 'verified' value starts with a protocol" do
|
context "when the URL has a path and does not end with a /" do
|
||||||
let(:source) do
|
it "accepts a `verified` value with one path component" do
|
||||||
<<~CASK
|
expect_no_offenses <<~CASK
|
||||||
cask "foo" do
|
cask "foo" do
|
||||||
url "https://example.com/download/foo-v1.2.0.dmg",
|
url "https://github.com/Foo",
|
||||||
verified: "https://example.com/download/"
|
verified: "github.com/Foo"
|
||||||
end
|
end
|
||||||
CASK
|
CASK
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:expected_offenses) do
|
it "accepts a `verified` value with two path components" do
|
||||||
[{
|
expect_no_offenses <<~CASK
|
||||||
message: "Cask/Url: Verified URL parameter value should not contain a URL scheme.",
|
|
||||||
severity: :convention,
|
|
||||||
line: 3,
|
|
||||||
column: 16,
|
|
||||||
source: "\"https://example.com/download/\"",
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
|
||||||
cask "foo" do
|
cask "foo" do
|
||||||
url "https://example.com/download/foo-v1.2.0.dmg",
|
url "https://github.com/foo/foo.git",
|
||||||
verified: "example.com/download/"
|
verified: "github.com/foo/foo"
|
||||||
end
|
end
|
||||||
CASK
|
CASK
|
||||||
end
|
end
|
||||||
|
|
||||||
include_examples "reports offenses"
|
|
||||||
include_examples "autocorrects source"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when url 'verified' value does not have a path component" do
|
context "when the url ends with a /" do
|
||||||
context "when the URL ends with a slash" do
|
it "accepts a `verified` value ending with a /" do
|
||||||
let(:source) do
|
expect_no_offenses <<~CASK
|
||||||
<<~CASK
|
|
||||||
cask "foo" do
|
|
||||||
url "https://example.org/",
|
|
||||||
verified: "example.org/"
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when the URL does not end with a slash" do
|
|
||||||
let(:source) do
|
|
||||||
<<~CASK
|
|
||||||
cask "foo" do
|
|
||||||
url "https://example.org/",
|
|
||||||
verified: "example.org"
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
|
||||||
message: "Cask/Url: Verified URL parameter value should end with a /.",
|
|
||||||
severity: :convention,
|
|
||||||
line: 3,
|
|
||||||
column: 16,
|
|
||||||
source: "\"example.org\"",
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
|
||||||
cask "foo" do
|
|
||||||
url "https://example.org/",
|
|
||||||
verified: "example.org/"
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
|
||||||
include_examples "autocorrects source"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when the URL does not end with a slash" do
|
|
||||||
describe "and it has one path component" do
|
|
||||||
let(:source) do
|
|
||||||
<<~CASK
|
|
||||||
cask "foo" do
|
|
||||||
url "https://github.com/Foo",
|
|
||||||
verified: "github.com/Foo"
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "and it has two path components" do
|
|
||||||
let(:source) do
|
|
||||||
<<~CASK
|
|
||||||
cask "foo" do
|
|
||||||
url "https://github.com/foo/foo.git",
|
|
||||||
verified: "github.com/foo/foo"
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when the url ends with a / and the verified value does too" do
|
|
||||||
let(:source) do
|
|
||||||
<<~CASK
|
|
||||||
cask "foo" do
|
cask "foo" do
|
||||||
url "https://github.com/",
|
url "https://github.com/",
|
||||||
verified: "github.com/"
|
verified: "github.com/"
|
||||||
@ -140,58 +87,36 @@ describe RuboCop::Cop::Cask::Url do
|
|||||||
CASK
|
CASK
|
||||||
end
|
end
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
it "reports an offense for a `verified` value not ending with a /" do
|
||||||
end
|
expect_offense <<~CASK
|
||||||
|
|
||||||
context "when the url ends with a / and the verified value does not" do
|
|
||||||
let(:source) do
|
|
||||||
<<~CASK
|
|
||||||
cask "foo" do
|
cask "foo" do
|
||||||
url "https://github.com/",
|
url "https://github.com/",
|
||||||
verified: "github.com"
|
verified: "github.com"
|
||||||
|
^^^^^^^^^^^^ Verified URL parameter value should end with a /.
|
||||||
end
|
end
|
||||||
CASK
|
CASK
|
||||||
end
|
|
||||||
|
|
||||||
let(:expected_offenses) do
|
expect_correction <<~CASK
|
||||||
[{
|
|
||||||
message: "Cask/Url: Verified URL parameter value should end with a /.",
|
|
||||||
severity: :convention,
|
|
||||||
line: 3,
|
|
||||||
column: 16,
|
|
||||||
source: "\"github.com\"",
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
|
||||||
cask "foo" do
|
cask "foo" do
|
||||||
url "https://github.com/",
|
url "https://github.com/",
|
||||||
verified: "github.com/"
|
verified: "github.com/"
|
||||||
end
|
end
|
||||||
CASK
|
CASK
|
||||||
end
|
end
|
||||||
|
|
||||||
include_examples "reports offenses"
|
|
||||||
include_examples "autocorrects source"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when url 'verified' value has a path component that ends with a /" do
|
it "accepts a `verified` value with a path ending with a /" do
|
||||||
let(:source) do
|
expect_no_offenses <<~CASK
|
||||||
<<~CASK
|
cask "foo" do
|
||||||
cask "foo" do
|
url "https://github.com/Foo/foo/releases/download/v1.2.0/foo-v1.2.0.dmg",
|
||||||
url "https://github.com/Foo/foo/releases/download/v1.2.0/foo-v1.2.0.dmg",
|
verified: "github.com/Foo/foo/"
|
||||||
verified: "github.com/Foo/foo/"
|
end
|
||||||
end
|
CASK
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when the url has interpolation in it and the verified url ends with a /" do
|
context "when the URL uses interpolation" do
|
||||||
let(:source) do
|
it "accepts a `verified` value with a path ending with a /" do
|
||||||
<<~CASK
|
expect_no_offenses <<~CASK
|
||||||
cask "foo" do
|
cask "foo" do
|
||||||
version "1.2.3"
|
version "1.2.3"
|
||||||
url "Cask/Url: https://example.com/download/foo-v\#{version}.dmg",
|
url "Cask/Url: https://example.com/download/foo-v\#{version}.dmg",
|
||||||
@ -199,40 +124,22 @@ describe RuboCop::Cop::Cask::Url do
|
|||||||
end
|
end
|
||||||
CASK
|
CASK
|
||||||
end
|
end
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when the url 'verified' value has a path component that doesn't end with a /" do
|
it "reports an offense for a `verified` value with a path component that doesn't end with a /" do
|
||||||
let(:source) do
|
expect_offense <<~CASK
|
||||||
<<~CASK
|
cask "foo" do
|
||||||
cask "foo" do
|
url "https://github.com/Foo/foo/releases/download/v1.2.0/foo-v1.2.0.dmg",
|
||||||
url "https://github.com/Foo/foo/releases/download/v1.2.0/foo-v1.2.0.dmg",
|
verified: "github.com/Foo/foo"
|
||||||
verified: "github.com/Foo/foo"
|
^^^^^^^^^^^^^^^^^^^^ Verified URL parameter value should end with a /.
|
||||||
end
|
end
|
||||||
CASK
|
CASK
|
||||||
end
|
|
||||||
|
|
||||||
let(:expected_offenses) do
|
expect_correction <<~CASK
|
||||||
[{
|
cask "foo" do
|
||||||
message: "Cask/Url: Verified URL parameter value should end with a /.",
|
url "https://github.com/Foo/foo/releases/download/v1.2.0/foo-v1.2.0.dmg",
|
||||||
severity: :convention,
|
verified: "github.com/Foo/foo/"
|
||||||
line: 3,
|
end
|
||||||
column: 16,
|
CASK
|
||||||
source: "\"github.com/Foo/foo\"",
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
|
||||||
cask "foo" do
|
|
||||||
url "https://github.com/Foo/foo/releases/download/v1.2.0/foo-v1.2.0.dmg",
|
|
||||||
verified: "github.com/Foo/foo/"
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
|
||||||
include_examples "autocorrects source"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,281 +1,140 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "rubocops/rubocop-cask"
|
require "rubocops/rubocop-cask"
|
||||||
require "test/rubocops/cask/shared_examples/cask_cop"
|
|
||||||
|
|
||||||
describe RuboCop::Cop::Cask::Variables do
|
describe RuboCop::Cop::Cask::Variables, :config do
|
||||||
include CaskCop
|
it "accepts when there are no variables" do
|
||||||
|
expect_no_offenses <<~CASK
|
||||||
subject(:cop) { described_class.new }
|
cask "foo" do
|
||||||
|
version :latest
|
||||||
context "when there are no variables" do
|
end
|
||||||
let(:source) do
|
CASK
|
||||||
<<~CASK
|
|
||||||
cask "foo" do
|
|
||||||
version :latest
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when there is an arch stanza" do
|
it "accepts when there is an `arch` stanza" do
|
||||||
let(:source) do
|
expect_no_offenses <<~CASK
|
||||||
<<~CASK
|
cask "foo" do
|
||||||
cask "foo" do
|
arch arm: "darwin-arm64", intel: "darwin"
|
||||||
arch arm: "darwin-arm64", intel: "darwin"
|
end
|
||||||
end
|
CASK
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when there is a non-arch variable that uses the arch conditional" do
|
it "accepts an `on_arch_conditional` variable" do
|
||||||
let(:source) do
|
expect_no_offenses <<~CASK
|
||||||
<<~CASK
|
cask "foo" do
|
||||||
cask "foo" do
|
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
||||||
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
end
|
||||||
end
|
CASK
|
||||||
CASK
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "does not report any offenses"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when there is an arch variable" do
|
it "reports an offense for an `arch` variable using strings" do
|
||||||
let(:source) do
|
expect_offense <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
arch = Hardware::CPU.intel? ? "darwin" : "darwin-arm64"
|
||||||
arch = Hardware::CPU.intel? ? "darwin" : "darwin-arm64"
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `arch arm: "darwin-arm64", intel: "darwin"` instead of `arch = Hardware::CPU.intel? ? "darwin" : "darwin-arm64"`.
|
||||||
end
|
end
|
||||||
CASK
|
CASK
|
||||||
end
|
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
arch arm: "darwin-arm64", intel: "darwin"
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
|
||||||
message: 'Cask/Variables: Use `arch arm: "darwin-arm64", intel: "darwin"` instead of ' \
|
|
||||||
'`arch = Hardware::CPU.intel? ? "darwin" : "darwin-arm64"`',
|
|
||||||
severity: :convention,
|
|
||||||
line: 2,
|
|
||||||
column: 2,
|
|
||||||
source: 'arch = Hardware::CPU.intel? ? "darwin" : "darwin-arm64"',
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
expect_correction <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
include_examples "autocorrects source"
|
arch arm: "darwin-arm64", intel: "darwin"
|
||||||
|
end
|
||||||
|
CASK
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when there is an arch variable that doesn't use strings" do
|
it "reports an offense for an `arch` variable using symbols" do
|
||||||
let(:source) do
|
expect_offense <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
arch = Hardware::CPU.intel? ? :darwin : :darwin_arm64
|
||||||
arch = Hardware::CPU.intel? ? :darwin : :darwin_arm64
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `arch arm: :darwin_arm64, intel: :darwin` instead of `arch = Hardware::CPU.intel? ? :darwin : :darwin_arm64`.
|
||||||
end
|
end
|
||||||
CASK
|
CASK
|
||||||
end
|
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
arch arm: :darwin_arm64, intel: :darwin
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
|
||||||
message: "Cask/Variables: Use `arch arm: :darwin_arm64, intel: :darwin` instead of " \
|
|
||||||
"`arch = Hardware::CPU.intel? ? :darwin : :darwin_arm64`",
|
|
||||||
severity: :convention,
|
|
||||||
line: 2,
|
|
||||||
column: 2,
|
|
||||||
source: "arch = Hardware::CPU.intel? ? :darwin : :darwin_arm64",
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
expect_correction <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
include_examples "autocorrects source"
|
arch arm: :darwin_arm64, intel: :darwin
|
||||||
|
end
|
||||||
|
CASK
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when there is an arch with an empty string" do
|
it "reports an offense for an `arch` variable with an empty string" do
|
||||||
let(:source) do
|
expect_offense <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
arch = Hardware::CPU.intel? ? "" : "arm64"
|
||||||
arch = Hardware::CPU.intel? ? "" : "arm64"
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `arch arm: "arm64"` instead of `arch = Hardware::CPU.intel? ? "" : "arm64"`.
|
||||||
end
|
end
|
||||||
CASK
|
CASK
|
||||||
end
|
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
arch arm: "arm64"
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
|
||||||
message: 'Cask/Variables: Use `arch arm: "arm64"` instead of ' \
|
|
||||||
'`arch = Hardware::CPU.intel? ? "" : "arm64"`',
|
|
||||||
severity: :convention,
|
|
||||||
line: 2,
|
|
||||||
column: 2,
|
|
||||||
source: 'arch = Hardware::CPU.intel? ? "" : "arm64"',
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
expect_correction <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
include_examples "autocorrects source"
|
arch arm: "arm64"
|
||||||
|
end
|
||||||
|
CASK
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when there is a non-arch variable" do
|
it "reports an offense for a non-`arch` variable using strings" do
|
||||||
let(:source) do
|
expect_offense <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
folder = Hardware::CPU.intel? ? "darwin" : "darwin-arm64"
|
||||||
folder = Hardware::CPU.intel? ? "darwin" : "darwin-arm64"
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"` instead of `folder = Hardware::CPU.intel? ? "darwin" : "darwin-arm64"`.
|
||||||
end
|
end
|
||||||
CASK
|
CASK
|
||||||
end
|
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
|
||||||
message: 'Cask/Variables: Use `folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"` ' \
|
|
||||||
'instead of `folder = Hardware::CPU.intel? ? "darwin" : "darwin-arm64"`',
|
|
||||||
severity: :convention,
|
|
||||||
line: 2,
|
|
||||||
column: 2,
|
|
||||||
source: 'folder = Hardware::CPU.intel? ? "darwin" : "darwin-arm64"',
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
expect_correction <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
include_examples "autocorrects source"
|
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
||||||
|
end
|
||||||
|
CASK
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when there is a non-arch variable with an empty string" do
|
it "reports an offense for a non-`arch` variable with an empty string" do
|
||||||
let(:source) do
|
expect_offense <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
folder = Hardware::CPU.intel? ? "amd64" : ""
|
||||||
folder = Hardware::CPU.intel? ? "amd64" : ""
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `folder = on_arch_conditional intel: "amd64"` instead of `folder = Hardware::CPU.intel? ? "amd64" : ""`.
|
||||||
end
|
end
|
||||||
CASK
|
CASK
|
||||||
end
|
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
folder = on_arch_conditional intel: "amd64"
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
|
||||||
message: 'Cask/Variables: Use `folder = on_arch_conditional intel: "amd64"` instead of ' \
|
|
||||||
'`folder = Hardware::CPU.intel? ? "amd64" : ""`',
|
|
||||||
severity: :convention,
|
|
||||||
line: 2,
|
|
||||||
column: 2,
|
|
||||||
source: 'folder = Hardware::CPU.intel? ? "amd64" : ""',
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
expect_correction <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
include_examples "autocorrects source"
|
folder = on_arch_conditional intel: "amd64"
|
||||||
|
end
|
||||||
|
CASK
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when there is an arch and a non-arch variable" do
|
it "reports an offense for consecutive `arch` and non-`arch` variables" do
|
||||||
let(:source) do
|
expect_offense <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
arch = Hardware::CPU.arm? ? "darwin-arm64" : "darwin"
|
||||||
arch = Hardware::CPU.arm? ? "darwin-arm64" : "darwin"
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `arch arm: "darwin-arm64", intel: "darwin"` instead of `arch = Hardware::CPU.arm? ? "darwin-arm64" : "darwin"`.
|
||||||
folder = Hardware::CPU.arm? ? "darwin-arm64" : "darwin"
|
folder = Hardware::CPU.arm? ? "darwin-arm64" : "darwin"
|
||||||
end
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"` instead of `folder = Hardware::CPU.arm? ? "darwin-arm64" : "darwin"`.
|
||||||
CASK
|
end
|
||||||
end
|
CASK
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
arch arm: "darwin-arm64", intel: "darwin"
|
|
||||||
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
|
||||||
message: 'Cask/Variables: Use `arch arm: "darwin-arm64", intel: "darwin"` instead of ' \
|
|
||||||
'`arch = Hardware::CPU.arm? ? "darwin-arm64" : "darwin"`',
|
|
||||||
severity: :convention,
|
|
||||||
line: 2,
|
|
||||||
column: 2,
|
|
||||||
source: 'arch = Hardware::CPU.arm? ? "darwin-arm64" : "darwin"',
|
|
||||||
}, {
|
|
||||||
message: 'Cask/Variables: Use `folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"` ' \
|
|
||||||
'instead of `folder = Hardware::CPU.arm? ? "darwin-arm64" : "darwin"`',
|
|
||||||
severity: :convention,
|
|
||||||
line: 3,
|
|
||||||
column: 2,
|
|
||||||
source: 'folder = Hardware::CPU.arm? ? "darwin-arm64" : "darwin"',
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
expect_correction <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
include_examples "autocorrects source"
|
arch arm: "darwin-arm64", intel: "darwin"
|
||||||
|
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
||||||
|
end
|
||||||
|
CASK
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when there are two non-arch variables" do
|
it "reports an offense for two consecutive non-`arch` variables" do
|
||||||
let(:source) do
|
expect_offense <<~CASK
|
||||||
<<~CASK
|
cask 'foo' do
|
||||||
cask 'foo' do
|
folder = Hardware::CPU.arm? ? "darwin-arm64" : "darwin"
|
||||||
folder = Hardware::CPU.arm? ? "darwin-arm64" : "darwin"
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"` instead of `folder = Hardware::CPU.arm? ? "darwin-arm64" : "darwin"`.
|
||||||
platform = Hardware::CPU.intel? ? "darwin": "darwin-arm64"
|
platform = Hardware::CPU.intel? ? "darwin": "darwin-arm64"
|
||||||
end
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `platform = on_arch_conditional arm: "darwin-arm64", intel: "darwin"` instead of `platform = Hardware::CPU.intel? ? "darwin": "darwin-arm64"`.
|
||||||
CASK
|
end
|
||||||
end
|
CASK
|
||||||
let(:correct_source) do
|
|
||||||
<<~CASK
|
|
||||||
cask 'foo' do
|
|
||||||
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
|
||||||
platform = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
|
||||||
end
|
|
||||||
CASK
|
|
||||||
end
|
|
||||||
let(:expected_offenses) do
|
|
||||||
[{
|
|
||||||
message: 'Cask/Variables: Use `folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"` instead ' \
|
|
||||||
'of `folder = Hardware::CPU.arm? ? "darwin-arm64" : "darwin"`',
|
|
||||||
severity: :convention,
|
|
||||||
line: 2,
|
|
||||||
column: 2,
|
|
||||||
source: 'folder = Hardware::CPU.arm? ? "darwin-arm64" : "darwin"',
|
|
||||||
}, {
|
|
||||||
message: 'Cask/Variables: Use `platform = on_arch_conditional arm: "darwin-arm64", intel: "darwin"` ' \
|
|
||||||
'instead of `platform = Hardware::CPU.intel? ? "darwin": "darwin-arm64"`',
|
|
||||||
severity: :convention,
|
|
||||||
line: 3,
|
|
||||||
column: 2,
|
|
||||||
source: 'platform = Hardware::CPU.intel? ? "darwin": "darwin-arm64"',
|
|
||||||
}]
|
|
||||||
end
|
|
||||||
|
|
||||||
include_examples "reports offenses"
|
expect_correction <<~CASK
|
||||||
|
cask 'foo' do
|
||||||
include_examples "autocorrects source"
|
folder = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
||||||
|
platform = on_arch_conditional arm: "darwin-arm64", intel: "darwin"
|
||||||
|
end
|
||||||
|
CASK
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user