Class: RuboCop::Cop::Cask::NoNestedOSDependency Private

Inherits:
Base
  • Object
show all
Defined in:
rubocops/cask/no_nested_os_dependency.rb

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

This cop disallows bare operating-system dependencies inside OS blocks. It also disallows Linux dependencies inside architecture-only blocks, where the DSL ignores their platform restriction. macOS dependencies remain allowed there because they change the cask's supported platforms. There is no autocorrection because choosing between moving and removing the dependency requires knowing the cask's intended platform support.

Constant Summary collapse

OS_DEPENDENCIES =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

[:macos, :linux].freeze
ARCH_BLOCK_METHODS =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

[:on_arm, :on_intel].freeze
OS_BLOCK_METHODS =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

T.let(
  [
    *RuboCop::Cask::Constants::ON_SYSTEM_METHODS.reject { |method| ARCH_BLOCK_METHODS.include?(method) },
    :on_system,
  ].freeze,
  T::Array[Symbol],
)
OS_DISPLAY_NAMES =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

T.let({ macos: "macOS", linux: "Linux" }.freeze, T::Hash[Symbol, String])
MSG =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

"A bare %<os_name>s dependency must not be nested in this conditional block. " \
"Move it to the top level if the cask is %<os_name>s-only; otherwise remove it."
RESTRICT_ON_SEND =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

[:depends_on].freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:

  • node (RuboCop::AST::SendNode)


30
31
32
33
34
35
36
# File 'rubocops/cask/no_nested_os_dependency.rb', line 30

def on_send(node)
  return if node.receiver
  return unless (os = os_dependency(node))
  return unless inside_disallowed_block_in_cask?(node, os)

  add_offense(node, message: format(MSG, os_name: OS_DISPLAY_NAMES.fetch(os)))
end