brew/Library/Homebrew/rubocops/move_to_extend_os.rb
Issy Long 0fc1eb534b
More Sorbet typed: strict RuboCops
- Some of these I bumped to `typed: strict`, some of them I added
  intermediary type signatures to some of the methods to make my life
  easier in the (near, hopefully) future.
- Turns out that RuboCop node matchers that end in `?`
  can return `nil` if they don't match anything, not `false`.
2025-02-08 23:38:12 +00:00

25 lines
582 B
Ruby

# typed: strict
# frozen_string_literal: true
module RuboCop
module Cop
module Homebrew
# This cop ensures that platform specific code ends up in `extend/os`.
class MoveToExtendOS < Base
MSG = "Move `OS.linux?` and `OS.mac?` calls to `extend/os`."
def_node_matcher :os_check?, <<~PATTERN
(send (const nil? :OS) {:mac? | :linux?})
PATTERN
sig { params(node: RuboCop::AST::Node).void }
def on_send(node)
return unless os_check?(node)
add_offense(node)
end
end
end
end
end