Class: ERBLint::Linters::TwoColumnLayoutMigrationCounter
- Inherits:
-
BaseLinter
- Object
- Linter
- BaseLinter
- ERBLint::Linters::TwoColumnLayoutMigrationCounter
- Includes:
- TagTreeHelpers, LinterRegistry
- Defined in:
- lib/primer/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
- SIDEBAR_WIDTH_RANGE =
(2..4).freeze
- CONTAINER_CLASSES =
%w[container-xl container-lg container-md container-sm].freeze
- MESSAGE =
"We are migrating two-column layouts to use "\ "[Primer::Alpha::Layout](https://primer.style/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
Methods included from Helpers::RuleHelpers
#erb_nodes, #extract_ruby_from_erb_node, #generate_node_offense, #generate_offense, #tags
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/primer/view_components/linters/two_column_layout_migration_counter.rb', line 77 def run(processed_source) @total_offenses = 0 @offenses_not_corrected = 0 , tag_tree = build_tag_tree(processed_source) .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 |