style: don't use prefix + directory
This commit is contained in:
parent
b4a9565b8b
commit
792533462a
@ -843,15 +843,6 @@ module Homebrew
|
|||||||
problem "Don't need to interpolate \"#{Regexp.last_match(2)}\" with #{Regexp.last_match(1)}"
|
problem "Don't need to interpolate \"#{Regexp.last_match(2)}\" with #{Regexp.last_match(1)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Prefer formula path shortcuts in Pathname+
|
|
||||||
if line =~ %r{\(\s*(prefix\s*\+\s*(['"])(bin|include|libexec|lib|sbin|share|Frameworks)[/'"])}
|
|
||||||
# TODO: check could be in RuboCop
|
|
||||||
problem(
|
|
||||||
"\"(#{Regexp.last_match(1)}...#{Regexp.last_match(2)})\" should" \
|
|
||||||
" be \"(#{Regexp.last_match(3).downcase}+...)\"",
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
return unless @strict
|
return unless @strict
|
||||||
|
|
||||||
# TODO: check could be in RuboCop
|
# TODO: check could be in RuboCop
|
||||||
|
|||||||
@ -93,6 +93,19 @@ module RuboCop
|
|||||||
offending_node(n)
|
offending_node(n)
|
||||||
problem "Use `depends_on :java` to set JAVA_HOME"
|
problem "Use `depends_on :java` to set JAVA_HOME"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
find_strings(body_node).each do |n|
|
||||||
|
# Skip strings that don't start with one of the keywords
|
||||||
|
next unless regex_match_group(n, %r{^(bin|include|libexec|lib|sbin|share|Frameworks)/?})
|
||||||
|
|
||||||
|
parent = n.parent
|
||||||
|
# Only look at keywords that have `prefix` before them
|
||||||
|
prefix_keyword_regex = %r{(prefix\s*\+\s*["'](bin|include|libexec|lib|sbin|share|Frameworks))["'/]}
|
||||||
|
if match = parent.source.match(prefix_keyword_regex)
|
||||||
|
offending_node(parent)
|
||||||
|
problem "Use `#{match[2].downcase}` instead of `#{match[1]}\"`"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -292,6 +292,28 @@ describe RuboCop::Cop::FormulaAudit::Text do
|
|||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "When using `prefix + \"bin\"` instead of `bin`" do
|
||||||
|
expect_offense(<<~RUBY)
|
||||||
|
class Foo < Formula
|
||||||
|
def install
|
||||||
|
ohai prefix + "bin"
|
||||||
|
^^^^^^^^^^^^^^ Use `bin` instead of `prefix + "bin"`
|
||||||
|
end
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
end
|
||||||
|
|
||||||
|
it "When using `prefix + \"bin/foo\"` instead of `bin`" do
|
||||||
|
expect_offense(<<~RUBY)
|
||||||
|
class Foo < Formula
|
||||||
|
def install
|
||||||
|
ohai prefix + "bin/foo"
|
||||||
|
^^^^^^^^^^^^^^^^^^ Use `bin` instead of `prefix + "bin"`
|
||||||
|
end
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user