Class: ERBLint::Linters::TwoColumnLayoutMigrationCounter

Inherits:
BaseLinter
  • Object
show all
Includes:
TagTreeHelpers, LinterRegistry
Defined in:
lib/yattho/view_components/linters/two_column_layout_migration_counter.rb

Overview

Counts the number of times a two column layout using col-* CSS classes is used instead of the layout component.

Defined Under Namespace

Classes: Breakpoints, Column, Container

Constant Summary collapse

WIDTH_RANGE =
(8..10).freeze
(2..4).freeze
CONTAINER_CLASSES =
%w[container-xl container-lg container-md container-sm].freeze
MESSAGE =
"We are migrating two-column layouts to use " \
"[Yattho::Alpha::Layout](https://yattho.com/view-components/components/layout), " \
"please use that instead of raw HTML."

Constants included from TagTreeHelpers

ERBLint::Linters::TagTreeHelpers::SELF_CLOSING_TAGS

Constants inherited from BaseLinter

BaseLinter::CLASSES, BaseLinter::DISALLOWED_CLASSES, BaseLinter::DUMP_FILE, BaseLinter::REQUIRED_ARGUMENTS

Instance Method Summary collapse

Methods included from TagTreeHelpers

#build_tag_tree, #self_closing?

Methods inherited from BaseLinter

#autocorrect, inherited

Instance Method Details

#run(processed_source) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/yattho/view_components/linters/two_column_layout_migration_counter.rb', line 77

def run(processed_source)
  @total_offenses = 0
  @offenses_not_corrected = 0

  tags, tag_tree = build_tag_tree(processed_source)

  tags.each do |tag|
    next if tag.closing?
    next unless tag.name == "div"

    classes = classes_from(tag)
    next if (CONTAINER_CLASSES & classes).empty?

    next unless (tag_tree[tag])

    @total_offenses += 1
    @offenses_not_corrected += 1

    generate_offense(self.class, processed_source, tag, MESSAGE)
  end

  counter_correct?(processed_source)
end