43 lines
1.0 KiB
Ruby
Raw Normal View History

2020-10-10 14:16:11 +02:00
# typed: true
# frozen_string_literal: true
2023-02-20 10:22:39 -08:00
require "rubocops/extend/formula_cop"
module RuboCop
module Cop
module FormulaAudit
2020-08-26 02:21:58 +02:00
# This cop makes sure that caveats don't recommend unsupported or unsafe operations.
#
# @example
# # bad
# def caveats
# <<~EOS
# Use `setuid` to allow running the exeutable by non-root users.
# EOS
# end
#
# # good
# def caveats
# <<~EOS
# Use `sudo` to run the executable.
# EOS
# end
#
# @api private
2023-02-20 10:22:39 -08:00
class Caveats < Base
include FormulaCop
def audit_formula(_node, _class_node, _parent_class_node, _body_node)
caveats_strings.each do |n|
if regex_match_group(n, /\bsetuid\b/i)
problem "Don't recommend setuid in the caveats, suggest sudo instead."
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