Class: RuboCop::Cask::AST::CaskBlock Private
- Inherits:
-
StanzaBlock
- Object
- StanzaBlock
- RuboCop::Cask::AST::CaskBlock
- Extended by:
- Forwardable
- Defined in:
- rubocops/cask/ast/cask_block.rb,
sorbet/rbi/dsl/rubo_cop/cask/ast/cask_block.rbi
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 class wraps the AST block node that represents the entire cask definition. It includes various helper methods to aid cops in their analysis.
Instance Attribute Summary
Attributes inherited from StanzaBlock
Instance Method Summary collapse
- #cask_body(*args, &block) ⇒ T.untyped private
- #cask_node ⇒ RuboCop::AST::BlockNode private
- #header ⇒ CaskHeader private
- #stanzas ⇒ Array<Stanza> private
- #toplevel_stanzas ⇒ Array<Stanza> private
Methods inherited from StanzaBlock
Constructor Details
This class inherits a constructor from RuboCop::Cask::AST::StanzaBlock
Instance Method Details
#cask_body(*args, &block) ⇒ T.untyped
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.
10 |
# File 'sorbet/rbi/dsl/rubo_cop/cask/ast/cask_block.rbi', line 10 def cask_body(*args, &block); end |
#cask_node ⇒ RuboCop::AST::BlockNode
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.
53 54 55 |
# File 'rubocops/cask/ast/cask_block.rb', line 53 def cask_node block_node end |
#header ⇒ CaskHeader
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.
60 61 62 |
# File 'rubocops/cask/ast/cask_block.rb', line 60 def header @header ||= T.let(CaskHeader.new(block_node.method_node), T.nilable(CaskHeader)) end |
#stanzas ⇒ Array<Stanza>
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.
Use StanzaBlock#stanzas
for all cops, where possible.
66 67 68 69 70 71 72 |
# File 'rubocops/cask/ast/cask_block.rb', line 66 def stanzas return [] unless cask_body @stanzas ||= cask_body.each_node .select(&:stanza?) .map { |node| Stanza.new(node, comments) } end |
#toplevel_stanzas ⇒ Array<Stanza>
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.
75 76 77 78 79 80 81 82 83 84 85 |
# File 'rubocops/cask/ast/cask_block.rb', line 75 def toplevel_stanzas # If a `cask` block only contains one stanza, it is that stanza's direct parent, # otherwise stanzas are grouped in a block and `cask` is that block's parent. is_toplevel_stanza = if cask_body.begin_block? ->(stanza) { stanza.parent_node.parent.cask_block? } else ->(stanza) { stanza.parent_node.cask_block? } end @toplevel_stanzas ||= T.let(stanzas.select(&is_toplevel_stanza), T.nilable(T::Array[Stanza])) end |