forked from sds/overcommit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrails_best_practices.rb
More file actions
34 lines (28 loc) · 826 Bytes
/
Copy pathrails_best_practices.rb
File metadata and controls
34 lines (28 loc) · 826 Bytes
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
# frozen_string_literal: true
module Overcommit
module Hook
module PreCommit
# Runs `rails_best_practices` against Ruby files
#
# @see https://github.com/railsbp/rails_best_practices
class RailsBestPractices < Base
ERROR_REGEXP = /^(?<file>(?:\w:)?[^:]+):(?<line>\d+)\s-\s(?<type>.+)/
def run
result = execute(command, args: applicable_files)
return :pass if result.success?
return [:fail, result.stderr] unless result.stderr.empty?
extract_messages(
filter_output(result.stdout),
ERROR_REGEXP
)
end
private
def filter_output(stdout)
stdout.split("\n").select do |message|
message.match ERROR_REGEXP
end
end
end
end
end
end