forked from houndci/hound
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruby.rb
67 lines (56 loc) · 1.55 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
56
57
58
59
60
61
62
63
64
65
66
67
# Determine Ruby style guide violations per-line.
module StyleGuide
class Ruby < Base
DEFAULT_CONFIG_FILENAME = "ruby.yml"
def violations_in_file(file)
if config.file_to_exclude?(file.filename)
[]
else
team.inspect_file(parsed_source(file)).map do |violation|
line = file.line_at(violation.line)
Violation.new(
filename: file.filename,
patch_position: line.patch_position,
line: line,
line_number: violation.line,
messages: [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
def default_config_file
DefaultConfigFile.new(DEFAULT_CONFIG_FILENAME, repository_owner).path
end
end
end