Skip to content

Commit 17b0560

Browse files
committed
Add rubygems check to msftidy. remove rubygems.
1 parent 9e5c24a commit 17b0560

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

lib/rex/proto/ntp/modes.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# -*- coding: binary -*-
22

3-
require 'rubygems'
43
require 'bit-struct'
54

65
module Rex

tools/msftidy.rb

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ def check_nokogiri
133133
break
134134
end
135135
else
136-
if line =~ /^\s*(require|load)\s+['"]nokogiri['"]/
137-
has_nokogiri = true
138-
end
136+
has_nokogiri = line_has_require?(line, 'nokogiri')
139137
end
140138
end
141139
error(msg) if has_nokogiri_xml_parser
@@ -201,6 +199,23 @@ def check_ref_identifiers
201199
end
202200
end
203201

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+
204219
def check_snake_case_filename
205220
sep = File::SEPARATOR
206221
good_name = Regexp.new "^[a-z0-9_#{sep}]+\.rb$"
@@ -551,6 +566,7 @@ def run_checks(full_filepath)
551566
tidy.check_mode
552567
tidy.check_shebang
553568
tidy.check_nokogiri
569+
tidy.check_rubygems
554570
tidy.check_ref_identifiers
555571
tidy.check_old_keywords
556572
tidy.check_verbose_option

0 commit comments

Comments
 (0)