Merge pull request #14372 from samford/rubocops-caveats-disallow-ansi-escape-codes

rubocops/caveats: Disallow ANSI escape codes
This commit is contained in:
Mike McQuaid 2023-01-19 09:56:19 +00:00 committed by GitHub
commit 5a4e226b2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 2 deletions

View File

@ -27,10 +27,12 @@ module RuboCop
class Caveats < FormulaCop class Caveats < FormulaCop
def audit_formula(_node, _class_node, _parent_class_node, _body_node) def audit_formula(_node, _class_node, _parent_class_node, _body_node)
caveats_strings.each do |n| caveats_strings.each do |n|
next unless regex_match_group(n, /\bsetuid\b/i) if regex_match_group(n, /\bsetuid\b/i)
problem "Don't recommend setuid in the caveats, suggest sudo instead." problem "Don't recommend setuid in the caveats, suggest sudo instead."
end end
problem "Don't use ANSI escape codes in the caveats." if regex_match_group(n, /\e/)
end
end end
end end
end end

View File

@ -19,5 +19,29 @@ describe RuboCop::Cop::FormulaAudit::Caveats do
end end
RUBY RUBY
end end
it "reports an offense if an escape character is present" do
expect_offense(<<~RUBY)
class Foo < Formula
homepage "https://brew.sh/foo"
url "https://brew.sh/foo-1.0.tgz"
def caveats
"\\x1B"
^^^^^^ Don't use ANSI escape codes in the caveats.
end
end
RUBY
expect_offense(<<~RUBY)
class Foo < Formula
homepage "https://brew.sh/foo"
url "https://brew.sh/foo-1.0.tgz"
def caveats
"\\u001b"
^^^^^^^^ Don't use ANSI escape codes in the caveats.
end
end
RUBY
end
end end
end end