Class: ERBLint::Linters::BlankslateApiMigration
- Inherits:
-
Linter
- Object
- Linter
- ERBLint::Linters::BlankslateApiMigration
- Includes:
- ERBLint::LinterRegistry, Helpers::RubocopHelpers
- Defined in:
- lib/yattho/view_components/linters/blankslate_api_migration.rb
Overview
Migrates from ‘Yattho::BlankslateComponent` to `Yattho::Beta::Blankslate`.
Instance Method Summary collapse
Methods included from Helpers::RubocopHelpers
Instance Method Details
#autocorrect(_, offense) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/yattho/view_components/linters/blankslate_api_migration.rb', line 35 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 33 |
# File 'lib/yattho/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?("Yattho::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), "`Yattho::BlankslateComponent` is deprecated. `Yattho::Beta::Blankslate` should be used instead", replacement) end end |