Sha256: ba6dfe569559e7d9f7b4c766aa4b7fc432e4eb21ed62c7886d47bc5376f4adc3

Contents?: true

Size: 1.15 KB

Versions: 88

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

require_relative "argument_mappers/conversion_error"

module ERBLint
  module Linters
    # Provides the autocorrection functionality for the linter. Once included, you should define the following constants:
    # * `ARGUMENT_MAPPER` - required - The class responsible for transforming classes and attributes into arguments for the component.
    # * `COMPONENT` - required - The component name for the linter. It will be used to generate the correction.
    module Autocorrectable
      def map_arguments(tag, _tag_tree)
        self.class::ARGUMENT_MAPPER.new(tag).to_s
      rescue ArgumentMappers::ConversionError
        nil
      end

      def correction(args)
        return if args.nil?

        correction = "<%= render #{self.class::COMPONENT}.new"
        correction += "(#{args})" if args.present?
        "#{correction} do %>"
      end

      def message(args, processed_source)
        return self.class::MESSAGE if args.nil?

        "#{self.class::MESSAGE}\nTry using:\n\n#{correction(args)}\n\nYou can also run erblint in autocorrect mode:\n\nbundle exec erblint -a #{processed_source.filename}\n"
      end
    end
  end
end

Version data entries

88 entries across 88 versions & 1 rubygems

Version Path
ariadne_view_components-0.0.92 lib/ariadne/view_components/linters/autocorrectable.rb
ariadne_view_components-0.0.91 lib/ariadne/view_components/linters/autocorrectable.rb
ariadne_view_components-0.0.90 lib/ariadne/view_components/linters/autocorrectable.rb
ariadne_view_components-0.0.89.1 lib/ariadne/view_components/linters/autocorrectable.rb
ariadne_view_components-0.0.89 lib/ariadne/view_components/linters/autocorrectable.rb
ariadne_view_components-0.0.88 lib/ariadne/view_components/linters/autocorrectable.rb
ariadne_view_components-0.0.87 lib/ariadne/view_components/linters/autocorrectable.rb
ariadne_view_components-0.0.86.9 lib/ariadne/view_components/linters/autocorrectable.rb
ariadne_view_components-0.0.86.8 lib/ariadne/view_components/linters/autocorrectable.rb
ariadne_view_components-0.0.86.7 lib/ariadne/view_components/linters/autocorrectable.rb
ariadne_view_components-0.0.86.6 lib/ariadne/view_components/linters/autocorrectable.rb
ariadne_view_components-0.0.86.5 lib/ariadne/view_components/linters/autocorrectable.rb
ariadne_view_components-0.0.86.4 lib/ariadne/view_components/linters/autocorrectable.rb
ariadne_view_components-0.0.86.3 lib/ariadne/view_components/linters/autocorrectable.rb
ariadne_view_components-0.0.86.2 lib/ariadne/view_components/linters/autocorrectable.rb
ariadne_view_components-0.0.86.1 lib/ariadne/view_components/linters/autocorrectable.rb
ariadne_view_components-0.0.86 lib/ariadne/view_components/linters/autocorrectable.rb
ariadne_view_components-0.0.85 lib/ariadne/view_components/linters/autocorrectable.rb
ariadne_view_components-0.0.84 lib/ariadne/view_components/linters/autocorrectable.rb
ariadne_view_components-0.0.83.3 lib/ariadne/view_components/linters/autocorrectable.rb