Class: ERBLint::Linters::DisallowActionList
- Inherits:
-
Linter
- Object
- Linter
- ERBLint::Linters::DisallowActionList
- Includes:
- ERBLint::LinterRegistry, TagTreeHelpers
- Defined in:
- lib/primer/view_components/linters/disallow_action_list.rb
Overview
Finds usages of ActionList CSS classes.
Defined Under Namespace
Classes: ConfigSchema
Constant Summary
Constants included from TagTreeHelpers
TagTreeHelpers::SELF_CLOSING_TAGS
Instance Method Summary collapse
Methods included from TagTreeHelpers
#build_tag_tree, #self_closing?
Instance Method Details
#run(processed_source) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 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 57 |
# File 'lib/primer/view_components/linters/disallow_action_list.rb', line 19 def run(processed_source) return if ignored?(processed_source.filename) class_regex = /ActionList[\w-]*/ , * = build_tag_tree(processed_source) .each do |tag| next if tag.closing? classes = if (class_attrib = tag.attributes["class"]) loc = class_attrib.value_node.loc loc.source_buffer.source[loc.begin_pos...loc.end_pos] else "" end indices = [].tap do |results| classes.scan(class_regex) do results << Regexp.last_match.offset(0) end end next if indices.empty? indices.each do |(start_idx, end_idx)| new_loc = class_attrib.value_node.loc.with( begin_pos: class_attrib.value_node.loc.begin_pos + start_idx, end_pos: class_attrib.value_node.loc.begin_pos + end_idx ) add_offense( new_loc, "ActionList classes are only designed to be used by Primer View Components and " \ "should be considered private. Please reach out in the #primer-rails Slack channel." ) end end end |