Add a RuboCop for shell command stubs

This commit is contained in:
Ruoyu Zhong 2024-07-15 11:41:12 -04:00
parent 22c5bdf2af
commit 5fc0fe21a7
No known key found for this signature in database
2 changed files with 25 additions and 0 deletions

View File

@ -11,6 +11,7 @@ require_relative "negate_include"
require_relative "presence" require_relative "presence"
require_relative "present" require_relative "present"
require_relative "safe_navigation_with_blank" require_relative "safe_navigation_with_blank"
require_relative "shell_command_stub"
require_relative "shell_commands" require_relative "shell_commands"
require_relative "install_bundler_gems" require_relative "install_bundler_gems"

View File

@ -0,0 +1,24 @@
# typed: strict
# frozen_string_literal: true
module RuboCop
module Cop
module Homebrew
class ShellCommandStub < Base
MSG = "Shell command stubs must have a `.sh` counterpart."
RESTRICT_ON_SEND = [:include].freeze
sig { params(node: AST::SendNode).void }
def on_send(node)
return if node.first_argument&.const_name != "ShellCommand"
stub_path = Pathname.new(processed_source.file_path)
sh_cmd_path = Pathname.new("#{stub_path.dirname}/#{stub_path.basename(".rb")}.sh")
return if sh_cmd_path.exist?
add_offense(node)
end
end
end
end
end