Sha256: 9957a9adb5dd303acb41fa388dc9aceec216577337666df11fdbb7ad7d0f485a

Contents?: true

Size: 1.16 KB

Versions: 4

Compression:

Stored size: 1.16 KB

Contents

require_relative '../parser/standard'
require_relative '../command'

module LintTrap
  module Linter
    # The base class for all linters. Provides a template for linter execution.
    class Base
      CONFIG_PATH = File.expand_path('../../../../config', __FILE__)

      def self.canonical_name
        name.split('::').last
      end

      def initialize(container:, **options)
        @container = container
        @options = options
      end

      def lint(files)
        command(files).run(container) do |stdout|
          parser(stdout).parse do |violation|
            yield violation
          end
        end
      end

      def name
        self.class.canonical_name
      end

    protected

      attr_reader :container, :options

    private

      def command(files)
        Command.new(command_name, flags, files)
      end

      def parser(stdout)
        LintTrap::Parser::Standard.new(stdout, container)
      end

      def config_path(path)
        container.config_path(path)
      end

      def flags
        raise NotImplementedError, 'Method flags must be implemented.'
      end

      def command_name
        name.downcase
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lint_trap-0.0.6 lib/lint_trap/linter/base.rb
lint_trap-0.0.5 lib/lint_trap/linter/base.rb
lint_trap-0.0.4 lib/lint_trap/linter/base.rb
lint_trap-0.0.3 lib/lint_trap/linter/base.rb