forked from shakacode/react-webpack-rails-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinters.rake
71 lines (58 loc) · 1.93 KB
/
linters.rake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
if %w(development test).include? Rails.env
namespace :lint do
# require "rubocop/rake_task"
# require "slim_lint/rake_task"
require "scss_lint/rake_task"
# This fails: https://github.com/bbatsov/rubocop/issues/1840
# RuboCop::RakeTask.new
desc "Run Rubocop lint as shell. Specify option fix to auto-correct (and don't have uncommitted files!)."
task :rubocop, [:fix] => [] do |_t, args|
def to_bool(str)
return true if str =~ (/^(true|t|yes|y|1)$/i)
return false if str.blank? || str =~ (/^(false|f|no|n|0)$/i)
fail ArgumentError, "invalid value for Boolean: \"#{str}\""
end
fix = (args.fix == "fix") || to_bool(args.fix)
cmd = "rubocop -S -D#{fix ? ' -a' : ''} ."
puts "Running Rubocop Linters via `#{cmd}`#{fix ? ' auto-correct is turned on!' : ''}"
sh cmd
end
desc "Run ruby-lint as shell"
task :ruby do
cmd = "ruby-lint app config spec lib"
puts "Running ruby-lint Linters via `#{cmd}`"
sh cmd
end
# SlimLint::RakeTask.new do |t|
# t.files = ["app/views"]
# end
SCSSLint::RakeTask.new do |t|
t.files = ["app/assets/stylesheets/", "client/"]
end
desc "eslint"
task :eslint do
cmd = "cd client && npm run eslint . -- --ext .jsx,.js"
puts "Running eslint via `#{cmd}`"
sh cmd
end
desc "jscs"
task :jscs do
cmd = "cd client && npm run jscs ."
puts "Running jscs via `#{cmd}`"
sh cmd
end
desc "JS Linting"
task js: [:eslint, :jscs] do
puts "Completed running all JavaScript Linters"
end
# desc "See docs for task 'slim_lint'"
# task slim: :slim_lint
desc "See docs for task 'scss_lint'"
task scss: :scss_lint
task lint: [:rubocop, :ruby, :js, :scss] do
puts "Completed all linting"
end
end
desc "Runs all linters. Run `rake -D lint` to see all available lint options"
task lint: ["lint:lint"]
end