Class: RuboCop::Cop::Cask::FontOrder Private
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 checks that a font cask's font stanzas are ordered alphabetically.
Example
# bad
font "Foo-Regular.ttf"
font "Foo-Bold.ttf"
# good
font "Foo-Bold.ttf"
font "Foo-Regular.ttf"
Constant Summary collapse
- MESSAGE =
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.
"`font` stanzas should be ordered alphabetically"
Instance Method Summary collapse
Methods included from CaskHelp
#cask_tap, #inner_stanzas, #on_block, #on_cask, #on_system_methods
Instance Method Details
#on_cask_stanza_block(cask_stanza_block) ⇒ 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.
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'rubocops/cask/font_order.rb', line 27 def on_cask_stanza_block(cask_stanza_block) stanzas = cask_stanza_block.stanzas.select(&:font?) sorted_stanzas = stanzas.sort_by(&:source) stanzas.each_with_index do |stanza, index| sorted_stanza = sorted_stanzas.fetch(index) next if stanza == sorted_stanza add_offense(stanza.method_node, message: MESSAGE) do |corrector| corrector.replace(stanza.source_range_with_comments, sorted_stanza.source_with_comments) end end end |