Sha256: bd2579347360d076f3977f08dc31b9710fec4915f5193f3ada85db6198e7ee08

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 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 lint(files, container, options)
        @container, @options = container, options

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

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

      def languages(*classes)
        classes.map(&:new)
      end

      def ==(other)
        name == other.name
      end

      def inspect
        "<#{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(options)
        raise NotImplementedError, 'Method flags must be implemented.'
      end

      def command_name
        name.downcase
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lint_trap-0.0.10 lib/lint_trap/linter/base.rb
lint_trap-0.0.9 lib/lint_trap/linter/base.rb