appfolio / eslint-rails

MIT License
39 stars 22 forks source link

Support for multiple files at once #41

Open Mtihc opened 5 years ago

Mtihc commented 5 years ago

Is it true that rake eslint:run[filename] can only check one single file at a time?

It would be nice if there was support for checking multiple files at once. Right now I have solved this by adding a file to my config/initializers/ folder. The file contains the following code:

require 'eslint-rails'

ESLintRails::Runner.class_eval do
  def initialize(files)
    @files = files.split(' ').map do |file|
      normalize_infile(file)
    end if files.present?
  end

  def assets
    all_js_assets = Rails.application.assets.each_file.to_a.map { |path| Pathname.new(path) }.select do |asset|
      ESLintRails::Runner::JAVASCRIPT_EXTENSIONS.include?(asset.extname)
    end

    assets =
      if @files.present?
        all_js_assets.select { |a| a.in?(@files) }
      else
        all_js_assets
      end

    assets.reject { |a| a.to_s =~ /eslint.js|vendor|gems|min.js|editorial/ }
  end
end

It overrides overwrites the initialize and assets methods. Now I can do: rake eslint:run["filename1 filename2 filename3"] 👍

But it would be nice if I can do that out-of-the-box.

Thanks for reading.