-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a RuboCop for shell command stubs
- Loading branch information
1 parent
2ea9e74
commit 8851752
Showing
2 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |