@@ -58,6 +58,73 @@ def error(txt, line=0)
58
58
#
59
59
##
60
60
61
+ def check_badchars
62
+ badchars = %Q|&<=>|
63
+
64
+ in_super = false
65
+ in_author = false
66
+
67
+ # First off, we need to capture the "super()" code block.
68
+ # That's where we want to check our badchars.
69
+ @source . each_line do |line |
70
+ #
71
+ # Mark our "super" code block
72
+ #
73
+ if !in_super and line =~ /[\n \t ]+super\( /
74
+ in_super = true
75
+ elsif in_super and line =~ /(.+)\) \n /
76
+ if $1 !~ /#/
77
+ in_super = false
78
+ end
79
+ end
80
+
81
+ #
82
+ # While in super() code block
83
+ #
84
+ if in_super and line =~ /'Name'[[:space:]]*=>[[:space:]]*['|"](.+)['|"]/
85
+ # Now we're checking the module titlee
86
+ mod_title = $1
87
+ mod_title . each_char do |c |
88
+ if badchars . include? ( c )
89
+ error ( "'#{ c } ' is a bad character in module title." )
90
+ end
91
+ end
92
+
93
+ if not mod_title . ascii_only?
94
+ error ( "Please avoid unicode in module title." )
95
+ end
96
+
97
+ # Since we're looking at the module title, this line clearly cannot be
98
+ # the author block, so no point to run more code below.
99
+ next
100
+ end
101
+
102
+ #
103
+ # Mark our 'Author' block
104
+ #
105
+ if in_super and !in_author and line =~ /'Author'[[:space:]]*=>/
106
+ in_author = true
107
+ elsif in_super and in_author and line =~ /\] ,*\n /
108
+ in_author = false
109
+ end
110
+
111
+
112
+ #
113
+ # While in 'Author' block, check for Twitter handles
114
+ #
115
+ if in_super and in_author and line =~ /['|"](.+)['|"]/
116
+ author_name = $1
117
+ if author_name =~ /^@.+$/
118
+ error ( "No Twitter handle, please. Try leaving it in a comment instead." )
119
+ end
120
+
121
+ if not author_name . ascii_only?
122
+ error ( "Please avoid unicode in Author" )
123
+ end
124
+ end
125
+ end
126
+ end
127
+
61
128
def check_extname
62
129
if File . extname ( @name ) != '.rb'
63
130
error ( "Module should be a '.rb' file, or it won't load." )
@@ -234,6 +301,7 @@ def load_file(file)
234
301
235
302
def run_checks ( f_rel )
236
303
tidy = Msftidy . new ( f_rel )
304
+ tidy . check_badchars
237
305
tidy . check_extname
238
306
tidy . test_old_rubies ( f_rel )
239
307
tidy . check_ranking
0 commit comments