Class: ERBLint::Linters::DeprecatedComponentsCounter
- Inherits:
-
Linter
- Object
- Linter
- ERBLint::Linters::DeprecatedComponentsCounter
- Includes:
- CustomHelpers, ERBLint::LinterRegistry, Helpers::DeprecatedComponentsHelpers
- Defined in:
- lib/primer/view_components/linters/deprecated_components_counter.rb
Overview
Lints against deprecated components
Constant Summary
Constants included from Helpers::DeprecatedComponentsHelpers
Helpers::DeprecatedComponentsHelpers::COMPONENT_TO_USE_INSTEAD
Instance Method Summary collapse
Methods included from Helpers::DeprecatedComponentsHelpers
#deprecated_components, #message, #statuses_json
Instance Method Details
#autocorrect(processed_source, offense) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/primer/view_components/linters/deprecated_components_counter.rb', line 34 def autocorrect(processed_source, offense) return unless offense.context lambda do |corrector| if processed_source.file_content.include?("erblint:counter #{self.class.name.gsub('ERBLint::Linters::', '')}") # update the counter if exists corrector.replace(offense.source_range, offense.context) else # add comment with counter if none corrector.insert_before(processed_source.source_buffer.source_range, "#{offense.context}\n") end end end |
#run(processed_source) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/primer/view_components/linters/deprecated_components_counter.rb', line 14 def run(processed_source) processed_source.ast.descendants(:erb).each do |erb_node| _, _, code_node = *erb_node code = code_node.children.first.strip next unless code.include?("Primer::") deprecated_components.each do |component| next unless code.include?(component) add_offense( erb_node.loc, (component) ) end end counter_correct?(processed_source) end |