-
Notifications
You must be signed in to change notification settings - Fork 206
/
configures_ignored_paths.rb
45 lines (40 loc) · 1.16 KB
/
configures_ignored_paths.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
class Standard::CreatesConfigStore
class ConfiguresIgnoredPaths
DEFAULT_IGNORES = [
# Match RuboCop's defaults: https://github.com/rubocop-hq/rubocop/blob/v0.61.1/config/default.yml#L60-L63
".git/**/*",
"node_modules/**/*",
"vendor/**/*",
# Standard's own default ignores:
"bin/*",
"db/schema.rb",
"tmp/**/*"
].map { |path| [path, ["AllCops"]] }.freeze
def call(options_config, standard_config)
ignored_patterns(standard_config).each do |(path, cops)|
cops.each do |cop|
options_config[cop] ||= {}
options_config[cop]["Exclude"] ||= []
options_config[cop]["Exclude"] |= [
absolutify(standard_config[:config_root], path)
]
end
end
end
private
def ignored_patterns(standard_config)
(standard_config[:default_ignores] ? DEFAULT_IGNORES : []) +
standard_config[:ignore]
end
def absolutify(config_root, path)
if !absolute?(path)
File.expand_path(File.join(config_root || Dir.pwd, path))
else
path
end
end
def absolute?(path)
path =~ %r{\A([A-Z]:)?/}
end
end
end