Class: ERBLint::Linters::DisallowComponentCssCounter
- Inherits:
-
BaseLinter
- Object
- Linter
- BaseLinter
- ERBLint::Linters::DisallowComponentCssCounter
- Defined in:
- lib/primer/view_components/linters/disallow_component_css_counter.rb
Overview
Counts the number of times a class reserved for ViewComponents is used
Constant Summary collapse
- CLASSES_COVERED_BY_OTHER_LINTERS =
BaseLinter.subclasses.reduce([]) do |html_classes, klass| html_classes.concat(klass.const_get(:CLASSES)) end
- CLASSES =
( JSON.parse( File.read( File.join(__dir__, "..", "..", "..", "..", "static", "classes.json") ) ).reject do |html_class, _ruby_classes| CLASSES_COVERED_BY_OTHER_LINTERS.include?(html_class) end ).freeze
Constants inherited from BaseLinter
BaseLinter::DISALLOWED_CLASSES, BaseLinter::DUMP_FILE, BaseLinter::REQUIRED_ARGUMENTS
Constants included from TagTreeHelpers
TagTreeHelpers::SELF_CLOSING_TAGS
Instance Method Summary collapse
Methods inherited from BaseLinter
Methods included from Helpers::RuleHelpers
#erb_nodes, #extract_ruby_from_erb_node, #generate_node_offense, #generate_offense, #tags
Methods included from TagTreeHelpers
#build_tag_tree, #self_closing?
Instance Method Details
#run(processed_source) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/primer/view_components/linters/disallow_component_css_counter.rb', line 31 def run(processed_source) @total_offenses = 0 @offenses_not_corrected = 0 processed_source .parser .nodes_with_type(:tag) .each do |node| tag = BetterHtml::Tree::Tag.from_node(node) tag.attributes["class"]&.value&.split(/\s+/)&.each do |class_name| if CLASSES.key? class_name @total_offenses += 1 @offenses_not_corrected += 1 add_offense( processed_source.to_source_range(tag.loc), (class_name) ) end end end counter_correct?(processed_source) dump_data(processed_source) if ENV["DUMP_LINT_DATA"] == "1" end |