forked from houndci/hound
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruby.rb
55 lines (46 loc) · 1.25 KB
/
ruby.rb
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
# Determine Ruby style guide violations per-line.
module StyleGuide
class Ruby < Base
DEFAULT_CONFIG_FILE = File.join(CONFIG_DIR, "ruby.yml")
def violations_in_file(file)
if config.file_to_exclude?(file.filename)
[]
else
team.inspect_file(parsed_source(file)).map do |violation|
Violation.new(file, violation.line, violation.message)
end
end
end
private
def team
RuboCop::Cop::Team.new(RuboCop::Cop::Cop.all, config, rubocop_options)
end
def parsed_source(file)
RuboCop::ProcessedSource.new(file.content)
end
def config
@config ||= RuboCop::Config.new(merged_config, "")
end
def merged_config
RuboCop::ConfigLoader.merge(default_config, custom_config)
rescue TypeError
default_config
end
def default_config
RuboCop::ConfigLoader.configuration_from_file(DEFAULT_CONFIG_FILE)
end
def custom_config
RuboCop::Config.new(repo_config.for(name), "").tap do |config|
config.add_missing_namespaces
config.make_excludes_absolute
end
rescue NoMethodError
RuboCop::Config.new
end
def rubocop_options
if config["ShowCopNames"]
{ debug: true }
end
end
end
end