@@ -36,8 +36,9 @@ def initialize(source_file)
36
36
37
37
##
38
38
#
39
- # The following two functions only print what you throw at them.
40
- # With an option of displaying the line number.
39
+ # The following two functions only print what you throw at them,
40
+ # with the option of displying the line number. error() is meant
41
+ # for mistakes that might actually break something.
41
42
#
42
43
##
43
44
@@ -58,6 +59,70 @@ def error(txt, line=0)
58
59
#
59
60
##
60
61
62
+ def check_badchars
63
+ badchars = %Q|&<=>|
64
+
65
+ in_super = false
66
+ in_author = false
67
+
68
+ @source . each_line do |line |
69
+ #
70
+ # Mark our "super" code block
71
+ #
72
+ if !in_super and line =~ /[\n \t ]+super\( /
73
+ in_super = true
74
+ elsif in_super and line =~ /[[:space:]]*def \w +[\( \w +\) ]*/
75
+ in_super = false
76
+ break
77
+ end
78
+
79
+ #
80
+ # While in super() code block
81
+ #
82
+ if in_super and line =~ /'Name'[[:space:]]*=>[[:space:]]*['|"](.+)['|"]/
83
+ # Now we're checking the module titlee
84
+ mod_title = $1
85
+ mod_title . each_char do |c |
86
+ if badchars . include? ( c )
87
+ error ( "'#{ c } ' is a bad character in module title." )
88
+ end
89
+ end
90
+
91
+ if not mod_title . ascii_only?
92
+ error ( "Please avoid unicode in module title." )
93
+ end
94
+
95
+ # Since we're looking at the module title, this line clearly cannot be
96
+ # the author block, so no point to run more code below.
97
+ next
98
+ end
99
+
100
+ #
101
+ # Mark our 'Author' block
102
+ #
103
+ if in_super and !in_author and line =~ /'Author'[[:space:]]*=>/
104
+ in_author = true
105
+ elsif in_super and in_author and line =~ /\] ,*\n /
106
+ in_author = false
107
+ end
108
+
109
+
110
+ #
111
+ # While in 'Author' block, check for Twitter handles
112
+ #
113
+ if in_super and in_author and line =~ /['|"](.+)['|"]/
114
+ author_name = $1
115
+ if author_name =~ /^@.+$/
116
+ error ( "No Twitter handle, please. Try leaving it in a comment instead." )
117
+ end
118
+
119
+ if not author_name . ascii_only?
120
+ error ( "Please avoid unicode in Author" )
121
+ end
122
+ end
123
+ end
124
+ end
125
+
61
126
def check_extname
62
127
if File . extname ( @name ) != '.rb'
63
128
error ( "Module should be a '.rb' file, or it won't load." )
@@ -126,7 +191,7 @@ def check_title_format
126
191
[ words . first , words . last ] . each do |word |
127
192
if word [ 0 , 1 ] =~ /[a-z]/ and word [ 1 , 1 ] !~ /[A-Z0-9]/
128
193
next if word =~ /php[A-Z]/
129
- next if %w{ iseemedia activePDF freeFTPd osCommerce myBB qdPM } . include? word
194
+ next if %w{ iseemedia activePDF freeFTPd osCommerce myBB qdPM inetd wallet.dat } . include? word
130
195
warn ( "Improper capitalization in module title: '#{ word } ...'" )
131
196
end
132
197
end
@@ -234,6 +299,7 @@ def load_file(file)
234
299
235
300
def run_checks ( f_rel )
236
301
tidy = Msftidy . new ( f_rel )
302
+ tidy . check_badchars
237
303
tidy . check_extname
238
304
tidy . test_old_rubies ( f_rel )
239
305
tidy . check_ranking
0 commit comments