Class: RuboCop::Cop::Yardoc::TagOrder
- Includes:
- RuboCop::Cop::YardHelp
- Defined in:
- lib/rubocop/cop/yardoc/tag_order.rb
Overview
Ensures YARD tags appear in the configured order.
Override with the Order config option.
Constant Summary collapse
- MSG =
'YARD tags are out of order. Expected order: %<order>s. Found `@%<current>s` after `@%<previous>s`.'- DEFAULT_ORDER =
Default expected order corresponding to the "Order" option
%w[param option yieldparam yieldreturn return raise see since deprecated note example].freeze
Instance Method Summary collapse
-
#on_def(node) ⇒ Object
(also: #on_defs, #on_module, #on_class)
Executed for every module/class/method definition (with aliases).
Instance Method Details
#on_def(node) ⇒ Object Also known as: on_defs, on_module, on_class
Executed for every module/class/method definition (with aliases)
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rubocop/cop/yardoc/tag_order.rb', line 42 def on_def(node) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity = (node) return if .empty? tag_names = .map(&:tag_name).select { |t| order.include?(t) } tag_names.each_cons(2) do |prev_tag, curr_tag| prev_idx = order.index(prev_tag) curr_idx = order.index(curr_tag) # Unknown tags (not in order list) are skipped next if prev_idx.nil? || curr_idx.nil? next if curr_idx >= prev_idx add_offense( node, message: format( MSG, order: order.map { |t| "@#{t}" }.join(', '), current: curr_tag, previous: prev_tag ) ) break end end |