Skip to content

Commit

Permalink
Add a RuboCop for shell command stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhongRuoyu committed Jul 15, 2024
1 parent 2ea9e74 commit 8851752
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions Library/Homebrew/rubocops/all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
require_relative "presence"
require_relative "present"
require_relative "safe_navigation_with_blank"
require_relative "shell_command_stub"
require_relative "shell_commands"
require_relative "install_bundler_gems"

Expand Down
24 changes: 24 additions & 0 deletions Library/Homebrew/rubocops/shell_command_stub.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8851752

Please sign in to comment.