Class: RuboCop::Cop::Tailwindcss::ClassOrder

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/tailwindcss/class_order.rb

Overview

Keeps Tailwind CSS classes in the official sort order - the same order prettier-plugin-tailwindcss produces - wherever Ruby carries them: class: / classes: string keywords (Phlex components, tag helpers) and the string literals inside class-merging functions like cn and cva.

Examples:

# bad
div(class: "px-4 bg-blue-500 flex")
cn("px-4 flex", active && "bg-muted rounded")

# good
div(class: "flex bg-blue-500 px-4")
cn("flex px-4", active && "rounded bg-muted")

Constant Summary collapse

MSG =
"Sort Tailwind CSS classes in the official order"

Instance Method Summary collapse

Instance Method Details

#on_pair(node) ⇒ Object



25
26
27
28
29
# File 'lib/rubocop/cop/tailwindcss/class_order.rb', line 25

def on_pair(node)
  if target_attribute?(node) && sortable?(node.value)
    check node.value
  end
end

#on_send(node) ⇒ Object



31
32
33
34
35
# File 'lib/rubocop/cop/tailwindcss/class_order.rb', line 31

def on_send(node)
  if class_function?(node)
    node.arguments.each { |argument| sort_within argument }
  end
end