Sha256: e4c4b6c93ce795f2550a87ad096ef1ab5aed831509de05eb82cfb3172d86968b

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 KB

Contents

# encoding: utf-8
module Phare
  class Check
    class Eslint < Check
      GLOBAL_BINARY = 'eslint'.freeze
      LOCAL_BINARY = 'node_modules/.bin/eslint'.freeze

      attr_reader :config, :path

      def initialize(directory, options = {})
        @directory = directory
        @config = File.expand_path("#{directory}.eslintrc", __FILE__)
        @path = File.expand_path("#{directory}app/assets/javascripts", __FILE__)
        @extensions = %w(.js)
        @options = options

        super
      end

      def command
        "#{binary} #{input}"
      end

    protected

      def configuration_exists?
        File.exist?(@config)
      end

      def binary
        local_binary_exists? ? @directory + LOCAL_BINARY : GLOBAL_BINARY
      end

      def binary_exists?
        local_binary_exists? || global_binary_exists?
      end

      def local_binary_exists?
        !Phare.system_output("which #{@directory}#{LOCAL_BINARY}").empty?
      end

      def global_binary_exists?
        !Phare.system_output("which #{GLOBAL_BINARY}").empty?
      end

      def input
        @tree.changed? ? files_to_check.join(' ') : "'#{@path}/**/*#{@extensions.first}'"
      end

      def arguments_exists?
        @tree.changed? || Dir.exist?(@path)
      end

      def print_banner
        Phare.banner 'Running ESLint to check for JavaScript style…'
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
phare-1.0.1 lib/phare/check/eslint.rb
phare-1.0.0 lib/phare/check/eslint.rb