File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change 1
1
# -*- coding: binary -*-
2
2
3
- require 'rubygems'
4
3
require 'bit-struct'
5
4
6
5
module Rex
Original file line number Diff line number Diff line change @@ -133,9 +133,7 @@ def check_nokogiri
133
133
break
134
134
end
135
135
else
136
- if line =~ /^\s *(require|load)\s +['"]nokogiri['"]/
137
- has_nokogiri = true
138
- end
136
+ has_nokogiri = line_has_require? ( line , 'nokogiri' )
139
137
end
140
138
end
141
139
error ( msg ) if has_nokogiri_xml_parser
@@ -201,6 +199,23 @@ def check_ref_identifiers
201
199
end
202
200
end
203
201
202
+ # See if 'require "rubygems"' or equivalent is used, and
203
+ # warn if so. Since Ruby 1.9 this has not been necessary and
204
+ # the framework only suports 1.9+
205
+ def check_rubygems
206
+ @source . each_line do |line |
207
+ if line_has_require? ( line , 'rubygems' )
208
+ warn ( "Explicitly requiring/loading rubygems is not necessary" )
209
+ break
210
+ end
211
+ end
212
+ end
213
+
214
+ # Does the given line contain a require/load of the specified library?
215
+ def line_has_require? ( line , lib )
216
+ line =~ /^\s *(require|load)\s +['"]#{ lib } ['"]/
217
+ end
218
+
204
219
def check_snake_case_filename
205
220
sep = File ::SEPARATOR
206
221
good_name = Regexp . new "^[a-z0-9_#{ sep } ]+\. rb$"
@@ -551,6 +566,7 @@ def run_checks(full_filepath)
551
566
tidy . check_mode
552
567
tidy . check_shebang
553
568
tidy . check_nokogiri
569
+ tidy . check_rubygems
554
570
tidy . check_ref_identifiers
555
571
tidy . check_old_keywords
556
572
tidy . check_verbose_option
You can’t perform that action at this time.
0 commit comments