String interpolations in regexps should also be allowed
- This came up in Cask `simply-fortran`:
```
Scanning /opt/homebrew/Library/Taps/homebrew/homebrew-cask/Casks/simply-fortran.rb
send_node: s(:send, nil, :arch), send_node.parent: s(:begin,
s(:send, nil, :arch)), send_node.parent.parent: (regexp
(str "href=.*?simplyfortran[._-]v?(\\d+(?:\\.\\d+)+)")
(begin
(send nil :arch))
(str "\\.dmg")
(regopt :i))
Casks/simply-fortran.rb:2:3: C: Cask/NoOverrides: Do not use a top-level arch 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.
arch arm: "-arm64", intel: "-x86_64"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1 file inspected, 1 offense detected
```
This commit is contained in:
parent
c1de3dfb90
commit
d4d413db62
@ -43,7 +43,9 @@ module RuboCop
|
|||||||
# Skip (nested) livecheck blocks as its `url` is different to a download `url`.
|
# Skip (nested) livecheck blocks as its `url` is different to a download `url`.
|
||||||
next if send_node.method_name == :livecheck || inside_livecheck_block?(send_node)
|
next if send_node.method_name == :livecheck || inside_livecheck_block?(send_node)
|
||||||
# Skip string interpolations.
|
# Skip string interpolations.
|
||||||
next if send_node.ancestors.drop_while { |a| !a.begin_type? }.any?(&:dstr_type?)
|
if send_node.ancestors.drop_while { |a| !a.begin_type? }.any? { |a| a.dstr_type? || a.regexp_type? }
|
||||||
|
next
|
||||||
|
end
|
||||||
next if ON_SYSTEM_METHODS.include?(send_node.method_name)
|
next if ON_SYSTEM_METHODS.include?(send_node.method_name)
|
||||||
|
|
||||||
names.add(send_node.method_name)
|
names.add(send_node.method_name)
|
||||||
|
|||||||
@ -71,6 +71,29 @@ describe RuboCop::Cop::Cask::NoOverrides do
|
|||||||
include_examples "does not report any offenses"
|
include_examples "does not report any offenses"
|
||||||
end
|
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
|
context "when there are single-line livecheck blocks within `on_*` blocks, ignore their contents" do
|
||||||
let(:source) do
|
let(:source) do
|
||||||
<<~CASK
|
<<~CASK
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user