Class: ERBLint::Linters::BlankslateApiMigration
- Inherits:
-
Linter
- Object
- Linter
- ERBLint::Linters::BlankslateApiMigration
- Includes:
- ERBLint::LinterRegistry, Helpers::RubocopHelpers
- Defined in:
- lib/primer/view_components/linters/blankslate_api_migration.rb
Overview
Migrates from ‘Primer::BlankslateComponent` to `Primer::Beta::Blankslate`.
Instance Method Summary collapse
Methods included from Helpers::RubocopHelpers
Instance Method Details
#autocorrect(_, offense) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/primer/view_components/linters/blankslate_api_migration.rb', line 34 def autocorrect(_, offense) return unless offense.context lambda do |corrector| corrector.replace(offense.source_range, offense.context) end end |
#run(processed_source) ⇒ Object
13 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/blankslate_api_migration.rb', line 13 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::BlankslateComponent") # Don't fix custom blankslates next if code.end_with?("do", "|") line = erb_node.loc.source_line indent = line.split("<%=").first.size ast = erb_ast(code) kwargs = ast.arguments.first.arguments.last replacement = build_replacement_blankslate(kwargs, indent) add_offense(processed_source.to_source_range(erb_node.loc), "`Primer::BlankslateComponent` is deprecated. `Primer::Beta::Blankslate` should be used instead", replacement) end end |