comparison contrib/check-code.py @ 35324:e223c0438f89

check-code: allow tabs in heredoc
author Yuya Nishihara <yuya@tcha.org>
date Sat, 09 Dec 2017 00:39:15 +0900
parents 91a7204631f1
children 5feb782c7a95
comparison
equal deleted inserted replaced
35323:1fe3c8296cfe 35324:e223c0438f89
133 (r'\[\[\s+[^\]]*\]\]', "don't use '[[ ]]', use '[ ]'"), 133 (r'\[\[\s+[^\]]*\]\]', "don't use '[[ ]]', use '[ ]'"),
134 (r'^alias\b.*=', "don't use alias, use a function"), 134 (r'^alias\b.*=', "don't use alias, use a function"),
135 (r'if\s*!', "don't use '!' to negate exit status"), 135 (r'if\s*!', "don't use '!' to negate exit status"),
136 (r'/dev/u?random', "don't use entropy, use /dev/zero"), 136 (r'/dev/u?random', "don't use entropy, use /dev/zero"),
137 (r'do\s*true;\s*done', "don't use true as loop body, use sleep 0"), 137 (r'do\s*true;\s*done', "don't use true as loop body, use sleep 0"),
138 (r'^( *)\t', "don't use tabs to indent"),
139 (r'sed (-e )?\'(\d+|/[^/]*/)i(?!\\\n)', 138 (r'sed (-e )?\'(\d+|/[^/]*/)i(?!\\\n)',
140 "put a backslash-escaped newline after sed 'i' command"), 139 "put a backslash-escaped newline after sed 'i' command"),
141 (r'^diff *-\w*[uU].*$\n(^ \$ |^$)', "prefix diff -u/-U with cmp"), 140 (r'^diff *-\w*[uU].*$\n(^ \$ |^$)', "prefix diff -u/-U with cmp"),
142 (r'^\s+(if)? diff *-\w*[uU]', "prefix diff -u/-U with cmp"), 141 (r'^\s+(if)? diff *-\w*[uU]', "prefix diff -u/-U with cmp"),
143 (r'[\s="`\']python\s(?!bindings)', "don't use 'python', use '$PYTHON'"), 142 (r'[\s="`\']python\s(?!bindings)', "don't use 'python', use '$PYTHON'"),
223 (r'^ (?!.*\$LOCALIP)[^*?/\n]* \(glob\)$', 222 (r'^ (?!.*\$LOCALIP)[^*?/\n]* \(glob\)$',
224 "glob match with no glob string (?, *, /, and $LOCALIP)"), 223 "glob match with no glob string (?, *, /, and $LOCALIP)"),
225 ] 224 ]
226 ] 225 ]
227 226
227 # transform plain test rules to unified test's
228 for i in [0, 1]: 228 for i in [0, 1]:
229 for tp in testpats[i]: 229 for tp in testpats[i]:
230 p = tp[0] 230 p = tp[0]
231 m = tp[1] 231 m = tp[1]
232 if p.startswith(r'^'): 232 if p.startswith(r'^'):
233 p = r"^ [$>] (%s)" % p[1:] 233 p = r"^ [$>] (%s)" % p[1:]
234 else: 234 else:
235 p = r"^ [$>] .*(%s)" % p 235 p = r"^ [$>] .*(%s)" % p
236 utestpats[i].append((p, m) + tp[2:]) 236 utestpats[i].append((p, m) + tp[2:])
237
238 # don't transform the following rules:
239 # " > \t" and " \t" should be allowed in unified tests
240 testpats[0].append((r'^( *)\t', "don't use tabs to indent"))
241 utestpats[0].append((r'^( ?)\t', "don't use tabs to indent"))
237 242
238 utestfilters = [ 243 utestfilters = [
239 (r"<<(\S+)((.|\n)*?\n > \1)", rephere), 244 (r"<<(\S+)((.|\n)*?\n > \1)", rephere),
240 (r"( +)(#([^!][^\n]*\S)?)", repcomment), 245 (r"( +)(#([^!][^\n]*\S)?)", repcomment),
241 ] 246 ]