nasl-pedant 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/pedant/check.rb +10 -8
- data/lib/pedant/checks/confusing_variable_names.rb +2 -2
- data/lib/pedant/checks/contains_no_tabs.rb +14 -2
- data/lib/pedant/checks/files_parse_without_errors.rb +2 -2
- data/lib/pedant/commands/check.rb +16 -4
- data/lib/pedant/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZmFmYzVkY2QxNzg0Y2U2NGFlZmRhNTQ3NzhkMDExODY2NDU5YzZlYQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NjBhMzY0NDMwZjNlNzA0MzUyN2ZlMWU3MjIzNTQ4ZDAxMWY1OGY2YQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjBjZjQxODJmNDEyZjI4ZDIyYWJmMjk2NjFhMWViNTAzZjBhNWQ0ZjI1OGIz
|
10
|
+
ZTlmNjgzZmQwOGYwZjg4YmYzZWFhNjkxZDkyOGI3ZGMyYTBlYWU1MDZmY2Ex
|
11
|
+
ZjhkOTg3YTQ1MGJmMWM3NDUzYTBjNWIxOGMwMTAzYjlmZmE3OGQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MDM2MjJiZjc3Mzg4ZmM4NTk4ZTdhOWRlZjRiMmEzYmMxMTE4Nzg2NDFlNjUx
|
14
|
+
ZTY3OGViZmE4ZWM3YWQ3YWM5MjdkOWY3M2E5M2MwOTk2Y2JhNDI3OGY3Yzgw
|
15
|
+
OGYxODdkNzAxMzVkYmNjMTkyZGYxOTdkOGMwOTFiN2ZhMTA3M2Y=
|
data/lib/pedant/check.rb
CHANGED
@@ -29,12 +29,12 @@ module Pedant
|
|
29
29
|
attr_reader :result
|
30
30
|
|
31
31
|
@@statuses = {
|
32
|
-
:
|
33
|
-
:fail
|
34
|
-
:pass
|
35
|
-
:skip
|
36
|
-
:warn
|
37
|
-
:void
|
32
|
+
:fatal => Rainbow('DIED').color(:red),
|
33
|
+
:fail => Rainbow('FAIL').color(:red),
|
34
|
+
:pass => Rainbow('PASS').color(:green),
|
35
|
+
:skip => Rainbow('SKIP').color(:green),
|
36
|
+
:warn => Rainbow('WARN').color(:yellow),
|
37
|
+
:void => Rainbow('VOID').color(:magenta)
|
38
38
|
}
|
39
39
|
|
40
40
|
@@levels = [:error, :warn, :info]
|
@@ -92,6 +92,7 @@ module Pedant
|
|
92
92
|
# Try to run each pending check, until we've run all our checks or
|
93
93
|
# deadlocked.
|
94
94
|
fatal = false
|
95
|
+
run_checks = []
|
95
96
|
until checks.empty? || fatal
|
96
97
|
# Find all of the checks that can run right now.
|
97
98
|
ready = checks.select { |cls| cls.ready?(kb) }
|
@@ -106,7 +107,7 @@ module Pedant
|
|
106
107
|
chk.run
|
107
108
|
|
108
109
|
# Yield the results of the finished check
|
109
|
-
|
110
|
+
run_checks << chk
|
110
111
|
|
111
112
|
# Fatal errors mean that no further checks should be processed.
|
112
113
|
if chk.result == :fatal
|
@@ -115,6 +116,7 @@ module Pedant
|
|
115
116
|
end
|
116
117
|
end
|
117
118
|
end
|
119
|
+
run_checks
|
118
120
|
end
|
119
121
|
|
120
122
|
def report(level, text=nil)
|
@@ -151,7 +153,7 @@ module Pedant
|
|
151
153
|
|
152
154
|
def fatal
|
153
155
|
report(:error, "This is a fatal error.")
|
154
|
-
@result = :
|
156
|
+
@result = :fatal
|
155
157
|
end
|
156
158
|
|
157
159
|
def pass
|
@@ -87,9 +87,9 @@ module Pedant
|
|
87
87
|
return if confusable_name_groups.length == 0
|
88
88
|
|
89
89
|
warn
|
90
|
-
report(:
|
90
|
+
report(:warn, "These sets of names differ only by capitalization or underscores:")
|
91
91
|
confusable_name_groups.each do |names|
|
92
|
-
report(:
|
92
|
+
report(:warn, " #{names.join(', ')}")
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
@@ -24,6 +24,8 @@
|
|
24
24
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25
25
|
################################################################################
|
26
26
|
|
27
|
+
require 'rainbow'
|
28
|
+
|
27
29
|
module Pedant
|
28
30
|
class CheckContainsNoTabs < Check
|
29
31
|
def self.requires
|
@@ -31,9 +33,19 @@ module Pedant
|
|
31
33
|
end
|
32
34
|
|
33
35
|
def check(file, code)
|
34
|
-
|
36
|
+
tab_lines = Hash.new
|
37
|
+
code.split("\n").each_with_index do |line, linenum|
|
38
|
+
tab_lines[linenum + 1] = line if line =~ /\t/
|
39
|
+
end
|
40
|
+
|
41
|
+
return if tab_lines.length == 0
|
42
|
+
|
43
|
+
report(:warn, "Tabs were found in #{file}, on these lines: #{tab_lines.keys.sort.join(', ')}")
|
44
|
+
report(:warn, "Showing up to five lines:")
|
45
|
+
tab_lines.keys.sort.first(5).each do |linenum|
|
46
|
+
report(:warn, "#{linenum}: #{tab_lines[linenum].gsub(/\t/, Rainbow(" ").background(:red))}")
|
47
|
+
end
|
35
48
|
|
36
|
-
report(:warn, "Tabs were found in #{file}.")
|
37
49
|
warn
|
38
50
|
end
|
39
51
|
|
@@ -54,7 +54,7 @@ module Pedant
|
|
54
54
|
@kb[:codes][file] = contents
|
55
55
|
report(:info, "Read contents of #{path}.")
|
56
56
|
rescue
|
57
|
-
report(:error, "Failed to read contents #{path}.")
|
57
|
+
report(:error, "Failed to read contents of #{path}.")
|
58
58
|
return fatal
|
59
59
|
end
|
60
60
|
|
@@ -62,7 +62,7 @@ module Pedant
|
|
62
62
|
tree = Nasl::Parser.new.parse(contents, path)
|
63
63
|
@kb[:trees][file] = tree
|
64
64
|
report(:info, "Parsed contents of #{path}.")
|
65
|
-
rescue
|
65
|
+
rescue Nasl::ParseException, Nasl::TokenException
|
66
66
|
# XXX-MAK: Incorporate the error from the parser, as it gives full,
|
67
67
|
# coloured context.
|
68
68
|
report(:error, "Failed to parse #{path}.")
|
@@ -89,6 +89,10 @@ module Pedant
|
|
89
89
|
puts Check.list
|
90
90
|
exit 0
|
91
91
|
end
|
92
|
+
|
93
|
+
opts.on('-q', '--quiet', "Only speak up when something should be fixed.") do
|
94
|
+
options[:quiet] = true
|
95
|
+
end
|
92
96
|
end
|
93
97
|
|
94
98
|
# Load all of the checks.
|
@@ -128,7 +132,6 @@ module Pedant
|
|
128
132
|
end
|
129
133
|
|
130
134
|
def self.run_one(opts, path)
|
131
|
-
puts Rainbow("CHECKING: #{path}").cyan
|
132
135
|
# Get a list of the checks we're going to be running.
|
133
136
|
if not opts[:checks].empty?
|
134
137
|
pending = opts[:checks].to_a
|
@@ -140,14 +143,23 @@ module Pedant
|
|
140
143
|
# other checks.
|
141
144
|
kb = KnowledgeBase.new(:file_mode, path)
|
142
145
|
|
143
|
-
Check.run_checks_in_dependency_order(kb, pending)
|
146
|
+
run_checks = Check.run_checks_in_dependency_order(kb, pending)
|
147
|
+
# When in quiet mode, only make a report for this file if a check did not pass
|
148
|
+
return if opts[:quiet] && run_checks.all? { |chk| [:skip, :pass].include? chk.result }
|
149
|
+
|
150
|
+
puts Rainbow("CHECKING: #{path}").cyan
|
151
|
+
run_checks.each do |chk|
|
152
|
+
next if [:skip, :pass].include?(chk.result) && opts[:quiet]
|
144
153
|
puts chk.report(opts[:verbosity])
|
145
154
|
end
|
146
|
-
|
147
155
|
# Notify the user if any checks did not run due to unsatisfied
|
148
156
|
# dependencies or a fatal error occurring before they had the chance to
|
149
157
|
# run.
|
150
|
-
pending.each
|
158
|
+
pending.each do |cls|
|
159
|
+
# Special case. This check is a shim to set things up for unit tests.
|
160
|
+
next if cls == CheckParseTestCode
|
161
|
+
puts cls.new(kb).report(opts[:verbosity])
|
162
|
+
end
|
151
163
|
puts
|
152
164
|
end
|
153
165
|
end
|
data/lib/pedant/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nasl-pedant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mak Kolybabi
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-
|
13
|
+
date: 2015-05-05 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|