]> git.openstreetmap.org Git - rails.git/blob - lib/tasks/eslint.rake
Merge remote-tracking branch 'upstream/pull/2975' into master
[rails.git] / lib / tasks / eslint.rake
1 task "eslint" => "eslint:check"
2
3 namespace "eslint" do
4   def yarn_path
5     Rails.root.join("bin/yarn").to_s
6   end
7
8   def config_file
9     Rails.root.join("config/eslint.json").to_s
10   end
11
12   def js_files
13     Rails.application.assets.each_file.select do |file|
14       file.ends_with?(".js") && !file.match?(%r{/(gems|vendor|i18n|node_modules)/})
15     end
16   end
17
18   task :check => :environment do
19     system(yarn_path, "run", "eslint", "-c", config_file, *js_files) || abort
20   end
21
22   task :fix => :environment do
23     system(yarn_path, "run", "eslint", "-c", config_file, "--fix", *js_files) || abort
24   end
25 end