Class: GLRubocop::GLCops::TailwindNoContradictingClassName
- Inherits:
-
RuboCop::Cop::Cop
- Object
- RuboCop::Cop::Cop
- GLRubocop::GLCops::TailwindNoContradictingClassName
- Includes:
- ErbContentHelper, HamlContentHelper
- Defined in:
- lib/gl_rubocop/gl_cops/tailwind_no_contradicting_class_name.rb
Overview
rubocop:disable Metrics/ClassLength
Constant Summary collapse
- MSG =
'Contradicting Tailwind CSS classes found: %<classes>s both affect the same CSS property'- GIVELIVELY_TAILWIND_CLASS_PREFIX =
'tw:'- CONTRADICTION_GROUPS =
Tailwind CSS property groups that should not contradict
{ width: %w[w], height: %w[h], max_width: %w[max-w], max_height: %w[max-h], min_width: %w[min-w], min_height: %w[min-h], margin_top: %w[m my mt], margin_right: %w[m mx mr], margin_bottom: %w[m my mb], margin_left: %w[m mx ml], padding_top: %w[p py pt], padding_right: %w[p px pr], padding_bottom: %w[p py pb], padding_left: %w[p px pl], display: %w[block hidden flex inline inline-block inline-flex grid inline-grid table], position: %w[static relative absolute fixed sticky], text_align: %w[text-left text-center text-right text-justify], flex_direction: %w[flex-row flex-row-reverse flex-col flex-col-reverse], flex_wrap: %w[flex-nowrap flex-wrap flex-wrap-reverse], justify_content: %w[ justify-start justify-end justify-center justify-between justify-around justify-evenly ], align_items: %w[items-start items-end items-center items-baseline items-stretch], place_content: %w[ place-content-center place-content-start place-content-end place-content-between place-content-around place-content-evenly ], place_items: %w[ place-items-start place-items-end place-items-center place-items-baseline place-items-stretch ], place_self: %w[ place-self-auto place-self-start place-self-end place-self-center place-self-stretch ], align_content: %w[ content-center content-start content-end content-between content-around content-evenly ], align_self: %w[ self-auto self-start self-end self-center self-stretch self-baseline ], justify_items: %w[ justify-items-start justify-items-end justify-items-center justify-items-stretch ], justify_self: %w[ justify-self-auto justify-self-start justify-self-end justify-self-center justify-self-stretch ], font_size: %w[ text-xs text-sm text-base text-lg text-xl text-2xl text-3xl text-4xl text-5xl text-6xl ], font_weight: %w[ font-thin font-extralight font-light font-normal font-medium font-semibold font-bold font-extrabold font-black ], font_style: %w[italic not-italic], letter_spacing: %w[ tracking-tighter tracking-tight tracking-normal tracking-wide tracking-wider tracking-widest ], line_height: %w[ leading-none leading-tight leading-snug leading-normal leading-relaxed leading-loose ], text_decoration_line: %w[underline line-through no-underline], text_transform: %w[uppercase lowercase capitalize normal-case], text_decoration_style: %w[ decoration-solid decoration-dashed decoration-dotted decoration-double decoration-wavy ], text_wrap: %w[break-normal break-words break-all], vertical_align: %w[ align-baseline align-top align-middle align-bottom align-text-top align-text-bottom ], text_overflow: %w[truncate overflow-ellipsis overflow-clip], overflow: %w[ overflow-auto overflow-hidden overflow-visible overflow-scroll ], visibility: %w[visible invisible collapse], border_style: %w[ border-solid border-dashed border-dotted border-double border-none ], box_shadow: %w[ shadow-sm shadow shadow-md shadow-lg shadow-xl shadow-2xl shadow-inner shadow-none ] # Add more property groups as needed, currently we have chosen to omit color-related properties and border-radius classes # to reduce false positives in common use cases. }.freeze
- BREAKPOINT_ORDER =
%w[sm md lg xl 2xl].freeze
Instance Method Summary collapse
Methods included from ErbContentHelper
Methods included from HamlContentHelper
Instance Method Details
#on_send(node) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/gl_rubocop/gl_cops/tailwind_no_contradicting_class_name.rb', line 121 def on_send(node) return unless render_method?(node) if haml_file? haml_content = read_haml_file return unless haml_content check_haml_content(haml_content, node) elsif erb_file? erb_content = read_erb_file return unless erb_content check_erb_content(erb_content, node) end end |
#on_str(node) ⇒ Object
137 138 139 140 |
# File 'lib/gl_rubocop/gl_cops/tailwind_no_contradicting_class_name.rb', line 137 def on_str(node) # Check string literals for Tailwind classes check_string_for_tailwind_classes(node) end |