excellent 2.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +11 -0
- data/bin/excellent +26 -8
- data/lib/simplabs/excellent.rb +1 -1
- data/lib/simplabs/excellent/runner.rb +16 -5
- metadata +1 -1
data/README.md
CHANGED
@@ -104,6 +104,17 @@ You can get a list of the enabled checks and their configurations by running:
|
|
104
104
|
excellent --checks
|
105
105
|
```
|
106
106
|
|
107
|
+
You can also place a `.excellent.yml` file in your home directory that contains default settings you always
|
108
|
+
want to apply. Settings in project-specific configuration files will override these default settings.
|
109
|
+
|
110
|
+
Excellent now also supports ignore paths. Simple place a `.excellentignore` file in the root directory of
|
111
|
+
your project and these directories will be ignored, e.g.:
|
112
|
+
|
113
|
+
```
|
114
|
+
vendor
|
115
|
+
some/specific/file.rb
|
116
|
+
```
|
117
|
+
|
107
118
|
Static analysis
|
108
119
|
---------------
|
109
120
|
|
data/bin/excellent
CHANGED
@@ -39,12 +39,23 @@ else
|
|
39
39
|
formatter = Simplabs::Excellent::Formatters::Text.new
|
40
40
|
end
|
41
41
|
|
42
|
-
custom_config
|
43
|
-
|
44
|
-
|
42
|
+
custom_config = {}
|
43
|
+
custom_config_file = File.join(Dir.pwd, '.excellent.yml')
|
44
|
+
default_config_file = File.join(File.expand_path('~'), '.excellent.yml')
|
45
|
+
if File.exists?(default_config_file) || File.exists?(custom_config_file)
|
45
46
|
require 'yaml'
|
46
47
|
begin
|
47
|
-
|
48
|
+
default_config = if File.exists?(default_config_file)
|
49
|
+
YAML.load(File.open(default_config_file)) || {}
|
50
|
+
else
|
51
|
+
{}
|
52
|
+
end
|
53
|
+
custom_config = if File.exists?(custom_config_file)
|
54
|
+
YAML.load(File.open(custom_config_file)) || {}
|
55
|
+
else
|
56
|
+
{}
|
57
|
+
end
|
58
|
+
custom_config = default_config.merge(custom_config)
|
48
59
|
config_valid = custom_config.is_a?(Hash) && custom_config.all? do |key, value|
|
49
60
|
key.is_a?(String) || key.is_a?(Symbol)
|
50
61
|
end
|
@@ -52,7 +63,7 @@ if File.exists?(config_file)
|
|
52
63
|
config_valid = false
|
53
64
|
end
|
54
65
|
unless config_valid
|
55
|
-
puts "\n ** The configuration
|
66
|
+
puts "\n ** The configuration is not valid!\n\n"
|
56
67
|
puts " Please make sure you specify a hash with check names as keys and hashes or truthy/falsy values as hash values, e.g.:\n\n"
|
57
68
|
puts " AbcMetricMethodCheck:"
|
58
69
|
puts " false"
|
@@ -63,6 +74,12 @@ if File.exists?(config_file)
|
|
63
74
|
end
|
64
75
|
end
|
65
76
|
|
77
|
+
ignore_paths = []
|
78
|
+
ignore_file = File.join(Dir.pwd, '.excellentignore')
|
79
|
+
if File.exists?(ignore_file)
|
80
|
+
ignore_paths = File.readlines(ignore_file).map(&:strip).select { |line| !line.empty? }
|
81
|
+
end
|
82
|
+
|
66
83
|
excellent = Simplabs::Excellent::Runner.new(custom_config)
|
67
84
|
|
68
85
|
if options[:print_checks]
|
@@ -76,7 +93,7 @@ if options[:print_checks]
|
|
76
93
|
exit 0
|
77
94
|
end
|
78
95
|
|
79
|
-
paths
|
96
|
+
paths = ARGV.dup
|
80
97
|
if paths.empty?
|
81
98
|
puts "\n **You must specify one or more directories to analyse, e.g.:\n"
|
82
99
|
puts "\n excellent lib/\n\n"
|
@@ -84,8 +101,9 @@ if paths.empty?
|
|
84
101
|
end
|
85
102
|
|
86
103
|
begin
|
87
|
-
excellent.check_paths(paths, formatter)
|
88
|
-
rescue ArgumentError
|
104
|
+
excellent.check_paths(paths, formatter, ignore_paths)
|
105
|
+
rescue ArgumentError => e
|
106
|
+
puts e.inspect
|
89
107
|
puts "\n** Excellent cannot find the paths specified!\n\n"
|
90
108
|
exit 1
|
91
109
|
end
|
data/lib/simplabs/excellent.rb
CHANGED
@@ -94,9 +94,10 @@ module Simplabs
|
|
94
94
|
#
|
95
95
|
# * <tt>paths</tt> - The paths to process (specify file names or directories; will recursively process all ruby files if a directory is given).
|
96
96
|
# * <tt>formatter</tt> - The formatter to use. If a formatter is specified, its +start+, +file+, +warning+ and +end+ methods will be called
|
97
|
-
|
97
|
+
# * <tt>ignore_paths</tt> - The paths to ignore
|
98
|
+
def check_paths(paths, formatter = nil, ignore_paths = [])
|
98
99
|
formatter.start if formatter
|
99
|
-
collect_files(paths).each do |path|
|
100
|
+
collect_files(paths, ignore_paths).each do |path|
|
100
101
|
check_file(path)
|
101
102
|
format_file_and_warnings(formatter, path) if formatter
|
102
103
|
end
|
@@ -130,8 +131,9 @@ module Simplabs
|
|
130
131
|
check_objects
|
131
132
|
end
|
132
133
|
|
133
|
-
def collect_files(paths)
|
134
|
-
files
|
134
|
+
def collect_files(paths, ignore_paths)
|
135
|
+
files = []
|
136
|
+
ignored_files = []
|
135
137
|
paths.each do |path|
|
136
138
|
if File.file?(path)
|
137
139
|
files << path
|
@@ -141,7 +143,16 @@ module Simplabs
|
|
141
143
|
raise ArgumentError.new("#{path} is neither a File nor a directory!")
|
142
144
|
end
|
143
145
|
end
|
144
|
-
|
146
|
+
ignore_paths.each do |path|
|
147
|
+
if File.file?(path)
|
148
|
+
ignored_files << path
|
149
|
+
elsif File.directory?(path)
|
150
|
+
ignored_files += Dir.glob(File.join(path, '**/*.{rb,erb}'))
|
151
|
+
else
|
152
|
+
raise ArgumentError.new("#{path} is neither a File nor a directory!")
|
153
|
+
end
|
154
|
+
end
|
155
|
+
files - ignored_files
|
145
156
|
end
|
146
157
|
|
147
158
|
def format_file_and_warnings(formatter, filename)
|