43 lines
1.0 KiB
Ruby
Raw Normal View History

# typed: strict
# frozen_string_literal: true
2023-02-20 10:22:39 -08:00
require "rubocops/extend/formula_cop"
module RuboCop
module Cop
module FormulaAudit
# This cop ensures that caveats don't recommend unsupported or unsafe operations.
2020-08-26 02:21:58 +02:00
#
# ### Example
2020-08-26 02:21:58 +02:00
#
# ```ruby
# # bad
# def caveats
# <<~EOS
# Use `setuid` to allow running the executable by non-root users.
# EOS
# end
#
# # good
# def caveats
# <<~EOS
# Use `sudo` to run the executable.
# EOS
# end
# ```
2023-02-20 18:10:59 -08:00
class Caveats < FormulaCop
sig { override.params(_formula_nodes: FormulaNodes).void }
def audit_formula(_formula_nodes)
caveats_strings.each do |n|
if regex_match_group(n, /\bsetuid\b/i)
problem "Instead of recommending `setuid` in the caveats, suggest `sudo`."
end
2018-09-17 02:45:00 +02:00
problem "Don't use ANSI escape codes in the caveats." if regex_match_group(n, /\e/)
end
end
end
end
end
end