nasl-pedant 0.0.7 → 0.0.8

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTNkZDBhYzc5YzY5MjE1ZGFmMzgxZDViMDg0YmEwNGQyODE2ODlmMA==
4
+ ZmFmYzVkY2QxNzg0Y2U2NGFlZmRhNTQ3NzhkMDExODY2NDU5YzZlYQ==
5
5
  data.tar.gz: !binary |-
6
- MWI3Njg1YzY0ODMyNzJhZWViOGFiMzI3NDg1YjU1ZGI1NjY2NWNkOA==
6
+ NjBhMzY0NDMwZjNlNzA0MzUyN2ZlMWU3MjIzNTQ4ZDAxMWY1OGY2YQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NTViZDYwZWUxOWRhZWQ3OWZlNmRlZTYwYmVhMDY0ZjkzYmIwZmY5YTg5NWM2
10
- NjU1NmEwYmM0YmFlNjkwZjNlMzhjNzFmMmZkMzkzOTU0Nzg3YzA3ZjcwOWM4
11
- MWEwZTkwOGExY2IzNDEwOWZmN2JkNjRjNGI4OTI1YzJhNmY2OTI=
9
+ ZjBjZjQxODJmNDEyZjI4ZDIyYWJmMjk2NjFhMWViNTAzZjBhNWQ0ZjI1OGIz
10
+ ZTlmNjgzZmQwOGYwZjg4YmYzZWFhNjkxZDkyOGI3ZGMyYTBlYWU1MDZmY2Ex
11
+ ZjhkOTg3YTQ1MGJmMWM3NDUzYTBjNWIxOGMwMTAzYjlmZmE3OGQ=
12
12
  data.tar.gz: !binary |-
13
- OGJlYTZiODkxZWQwZWU2MTk3YTg1NmM1OTdkNTZjNzdkYWQ1YjFkYmNiMzZi
14
- YmQxYTI2YTVjNGJhMTQ0OTMxNjZiYjBlZmJkMDAwY2RmMmQ3NDQyNTU4MzBk
15
- NTVjZjcyZmJhMTM5OWQ4MDZjYTdiMjAzNDNmNzZlZWUwMDI3MjU=
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
- :died => 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)
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
- yield chk if block_given?
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 = :died
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(:error, "These sets of names differ only by capitalization or underscores:")
90
+ report(:warn, "These sets of names differ only by capitalization or underscores:")
91
91
  confusable_name_groups.each do |names|
92
- report(:error, " #{names.join(', ')}")
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
- return unless code =~ /\t/
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) do |chk|
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 { |cls| puts cls.new(kb).report(opts[:verbosity]) }
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
@@ -1,3 +1,3 @@
1
1
  module Pedant
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
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.7
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-04-08 00:00:00.000000000 Z
13
+ date: 2015-05-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake