]> git.openstreetmap.org Git - rails.git/blob - lib/tasks/eslint.rake
Merge remote-tracking branch 'upstream/pull/4144'
[rails.git] / lib / tasks / eslint.rake
1 task "eslint" => "eslint:check"
2
3 def yarn_path
4   Rails.root.join("bin/yarn").to_s
5 end
6
7 def config_file
8   Rails.root.join("config/eslint.json").to_s
9 end
10
11 def js_files
12   Rails.application.assets.each_file.select do |file|
13     file.ends_with?(".js") && !file.match?(%r{/(gems|vendor|i18n|node_modules)/})
14   end
15 end
16
17 namespace "eslint" do
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