Sha256: fc7c8d69ba32e7ab2d5b2dc367d00676531df1022003ea2d8fa1b1125ddcf33e

Contents?: true

Size: 1.43 KB

Versions: 29

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

require_relative "helpers/deprecated_components_helpers"
require "erblint-github/linters/custom_helpers"

module ERBLint
  module Linters
    # Lints against deprecated components
    class DeprecatedComponentsCounter < Linter
      include CustomHelpers
      include ERBLint::LinterRegistry
      include Helpers::DeprecatedComponentsHelpers

      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,
              message(component)
            )
          end
        end

        counter_correct?(processed_source)
      end

      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
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
primer_view_components-0.0.111 lib/primer/view_components/linters/deprecated_components_counter.rb
primer_view_components-0.0.110 lib/primer/view_components/linters/deprecated_components_counter.rb
primer_view_components-0.0.109 lib/primer/view_components/linters/deprecated_components_counter.rb
primer_view_components-0.0.108 lib/primer/view_components/linters/deprecated_components_counter.rb
primer_view_components-0.0.107 lib/primer/view_components/linters/deprecated_components_counter.rb
primer_view_components-0.0.106 lib/primer/view_components/linters/deprecated_components_counter.rb
primer_view_components-0.0.105 lib/primer/view_components/linters/deprecated_components_counter.rb
primer_view_components-0.0.104 lib/primer/view_components/linters/deprecated_components_counter.rb
primer_view_components-0.0.103 lib/primer/view_components/linters/deprecated_components_counter.rb
primer_view_components-0.0.102 lib/primer/view_components/linters/deprecated_components_counter.rb
primer_view_components-0.0.101 lib/primer/view_components/linters/deprecated_components_counter.rb
primer_view_components-0.0.100 lib/primer/view_components/linters/deprecated_components_counter.rb
primer_view_components-0.0.99 lib/primer/view_components/linters/deprecated_components_counter.rb
primer_view_components-0.0.98 lib/primer/view_components/linters/deprecated_components_counter.rb
primer_view_components-0.0.97 lib/primer/view_components/linters/deprecated_components_counter.rb
primer_view_components-0.0.96 lib/primer/view_components/linters/deprecated_components_counter.rb
primer_view_components-0.0.95 lib/primer/view_components/linters/deprecated_components_counter.rb
primer_view_components-0.0.94 lib/primer/view_components/linters/deprecated_components_counter.rb
primer_view_components-0.0.93 lib/primer/view_components/linters/deprecated_components_counter.rb
primer_view_components-0.0.92 lib/primer/view_components/linters/deprecated_components_counter.rb