def __init__(self): Check.__init__(self) self.name = "C:Import" self.example = "#import <sys/file.h>" self.add_language("c") self.add_language("cpp") self.c_std_includes = [ "assert.h", "complex.h", "ctype.h", "errno.h", "fenv.h", "float.h", "inttypes.h", "iso646.h", "limits.h" "locale.h", "math.h", "setjmp.h", "signal.h", "stdarg.h", "stdbool.h" "stddef.h", "stdint.h", "stdio.h", "stdlib.h", "string.h", "tgmath.h", "time.h", "wchar.h", "wctype.h" ] self.cpp_std_includes = [ "ios", "iostream", "iomanip", "fstream", "sstream", "vector", "deque", "list", "map", "set", "stack", "queue", "bitset", "algorithm", "memory", "functional", "iterator", "cassert", "cctype", "cerrno", "climits", "clocale", "cmath", "csetjmp", "csignal", "cstdarg", "cstddef", "cstdio", "cstdint", "cstdlib", "cstring", "ctime" "cwchar", "cwctype" ] res_import = """#\s*include\s+(?:"|\<|')(.*?)(?:"|\<|')(?:\n|\r)""" self.re_import = re.compile(res_import)
def __init__(self): Check.__init__(self) self.name = "Ruby:StrangeFunctionNames" self.example = ".do_it!" self.type = Check.kTYPE_MICRO self.add_language("ruby") self.add_multiple_matches("\.[a-zA-Z_][a-zA-Z_0-9](\?|!)", 20)
def __init__(self): Check.__init__(self) self.name = "Ruby:Module/Declaration" self.example = "module CoolModule" self.add_language("ruby") self.add_multiple_matches( "(^|\r|\n)\s*module\s+[a-zA-Z_][a-zA-Z_0-9]*", 20)
def __init__ (self): Check.__init__ (self) self.name = "Php:ClosingTag" self.example = "?>" self.add_language("php") self.add_one_time_match("(^|\n|\r)\s*?\?>", 80)
def __init__ (self): Check.__init__(self) self.name = "Xml:Declaration" self.example = "<?xml" self.type = Check.kTYPE_FINAL self.add_language("xml") self.add_one_time_match("^<\?xml\s+", 100)
def __init__(self): Check.__init__(self) self.name = "Ruby:Require" self.example = "require 'dude.rb'" self.add_language("ruby") self.add_multiple_matches("(^|\n|\r)\s*require\s+'[^']+'\s*(\r|\n|$)", 40)
def __init__(self): Check.__init__(self) self.name = "Sql:Commands" self.example = "create table sql_commands;" sql_commands = [] #sql_commands.append("GROUP BY") #sql_commands.append("HAVING") #sql_commands.append("ORDER BY") #sql_commands.append("ALTER") sql_commands.append("CREATE TABLE") sql_commands.append("COMMIT") sql_commands.append("DELETE FROM") sql_commands.append("DROP") sql_commands.append("GRANT") sql_commands.append("INSERT INTO") sql_commands.append("MERGE") sql_commands.append("REVOKE") sql_commands.append("ROLLBACK") sql_commands.append("SELECT") sql_commands.append("TRUNCATE") sql_commands.append("UPDATE") re_commands = "" for command in sql_commands: if re_commands != "": re_commands += "|" re_commands += "(?:" + command + ")" re = "(^|;|\r|\n)\s*(" + re_commands + ")\s+" self.add_language("sql") self.add_multiple_matches(re, 20)
def __init__ (self): Check.__init__(self) self.name = "Ruby:StrangeFunctionNames" self.example = ".do_it!" self.type = Check.kTYPE_MICRO self.add_language("ruby") self.add_multiple_matches("\.[a-zA-Z_][a-zA-Z_0-9](\?|!)", 20)
def __init__ (self): Check.__init__(self) self.name = "Sql:Commands" self.example = "create table sql_commands;" sql_commands = [] #sql_commands.append("GROUP BY") #sql_commands.append("HAVING") #sql_commands.append("ORDER BY") #sql_commands.append("ALTER") sql_commands.append("CREATE TABLE") sql_commands.append("COMMIT") sql_commands.append("DELETE FROM") sql_commands.append("DROP") sql_commands.append("GRANT") sql_commands.append("INSERT INTO") sql_commands.append("MERGE") sql_commands.append("REVOKE") sql_commands.append("ROLLBACK") sql_commands.append("SELECT") sql_commands.append("TRUNCATE") sql_commands.append("UPDATE") re_commands = "" for command in sql_commands: if re_commands != "": re_commands += "|" re_commands += "(?:" + command + ")" re = "(^|;|\r|\n)\s*(" + re_commands + ")\s+" self.add_language("sql") self.add_multiple_matches(re, 20)
def __init__(self): Check.__init__(self) self.name = "Php:ClosingTag" self.example = "?>" self.add_language("php") self.add_one_time_match("(^|\n|\r)\s*?\?>", 80)
def __init__(self): Check.__init__(self) self.name = "Xml:Declaration" self.example = "<?xml" self.type = Check.kTYPE_FINAL self.add_language("xml") self.add_one_time_match("^<\?xml\s+", 100)
def __init__ (self): Check.__init__(self) self.name = "Ruby:Function/Declaration" self.example = "def do_it!" self.add_language("ruby") res_sol = "(?:^|\r|\n)" res_name = "(?:self\.)?[a-zA-Z_][a-zA-Z0-9_]*(?:!|\?)?" res_arg = "(?:&|\*)?\s*[a-zA-Z0-9_]+" res_args = "(?:\(\s*(" + res_arg + "(?:\s*,\s*" + res_arg + ")*)?\s*\))?" res_eol = "\s*(?:\r|\n)" res_func = res_sol + "\s*" res_func += "def\s+" res_func += "(" + res_name + ")\s*" res_func += res_args res_func += res_eol self.re_func = re.compile(res_func) self.special_methods = [ "initialize", "inspect", "method_missing", "respond_to?", "to_a", "to_enum", "to_s" ]
def __init__ (self): Check.__init__(self) self.name = "Perl:Subroutine" self.example = "sub do_as_i_say {" self.add_language("perl") self.add_multiple_matches("(?:^|\n|\r|;)\s*sub\s+([a-zA-Z_][a-zA-Z_0-8]*)\s*{", 10)
def __init__ (self): Check.__init__ (self) self.name = "Html:Doctype" self.example = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' self.type = Check.kTYPE_FINAL self.add_language("html") self.add_one_time_match("(?:\r|\n|^)<!DOCTYPE (HTML|html) PUBLIC \"", 200)
def __init__(self): Check.__init__(self) self.name = "Php:GetPostVariables" self.example = "$_GET" self.type = Check.kTYPE_MICRO self.add_language("php") self.add_multiple_matches("\$_(GET)|(POST)", 20)
def __init__ (self): Check.__init__ (self) self.name = "Php:Class/Declaration" self.example = "class MyClassIsColl extends Dad {" self.add_language("php") re_id = "[a-zA-Z_][a-zA-Z0-9_]*" self.add_multiple_matches("class\s+" + re_id + "\s+(implements)|(extends)\s+" + re_id + "\s*{", 60)
def __init__(self): Check.__init__(self) self.name = "Php:InstanceMember" self.example = "$my_var->is_cool" self.type = Check.kTYPE_MICRO self.add_language("php") self.add_multiple_matches("\$[a-zA-Z_][a-zA-Z0-9]*->[a-zA-Z_][a-zA-Z0-9]*", 20)
def __init__ (self): Check.__init__ (self) self.name = "Php:GetPostVariables" self.example = "$_GET"; self.type = Check.kTYPE_MICRO self.add_language("php") self.add_multiple_matches("\$_(GET)|(POST)", 20)
def __init__ (self): Check.__init__(self) self.name = "Ruby:Class/Declaration" self.example = "CoolClass < CoolClassDad" self.add_language("ruby") re_class = "[a-zA-Z_][a-zA-Z_0-9]+" self.add_multiple_matches("(^|\r|\n)\s*class\s+" + re_class + "\s*<<?\s*" + re_class + "\s*(\r|\n|$)", 30)
def __init__(self): Check.__init__(self) self.name = "Php:Class/Declaration" self.example = "class MyClassIsColl extends Dad {" self.add_language("php") re_id = "[a-zA-Z_][a-zA-Z0-9_]*" self.add_multiple_matches("class\s+" + re_id + "\s+(implements)|(extends)\s+" + re_id + "\s*{", 60)
def __init__ (self): Check.__init__ (self) self.name = "Php:InstanceMember" self.example = "$my_var->is_cool" self.type = Check.kTYPE_MICRO self.add_language("php") self.add_multiple_matches("\$[a-zA-Z_][a-zA-Z0-9]*->[a-zA-Z_][a-zA-Z0-9]*", 20)
def __init__ (self): Check.__init__ (self) self.name = "Sh:ControlFlow" self.example = "if [ -f ./myfile ] ;" self.add_language("sh") self.add_multiple_matches("(?:^|\r|\n|;)\s*(el)?if\s*\[(?:[^\]]+?)\]\s*(?:;|\r|\n|$)", 20) self.add_multiple_matches("(?:^|\r|\n|;)fi(?:;|\r|\n|$)", 10)
def __init__ (self): Check.__init__(self) self.name = "Namespace" self.example = "namespace dude.this.rocks {" self.add_language("c#") self.add_language("c++") res_package = "(?:^|\n|\r|;)\s*namespace\s*([a-zA-Z_][a-zA-Z_0-9.]*)\s*(?:$|\n|\r|;)\s*{" self.re_package = re.compile(res_package)
def __init__(self): Check.__init__(self) self.name = "Shebang" self.example = "#!/usr/bin/python" self.type = Check.kTYPE_FINAL self.add_language("perl") self.add_language("php") self.add_language("python") self.add_language("ruby")
def __init__(self): Check.__init__(self) self.name = "Perl:Subroutine" self.example = "sub do_as_i_say {" self.add_language("perl") self.add_multiple_matches( "(?:^|\n|\r|;)\s*sub\s+([a-zA-Z_][a-zA-Z_0-8]*)\s*{", 10)
def __init__ (self): Check.__init__ (self) self.name = "Shebang" self.example = "#!/usr/bin/python" self.type = Check.kTYPE_FINAL self.add_language("perl") self.add_language("php") self.add_language("python") self.add_language("ruby")
def __init__(self): Check.__init__(self) self.name = "Namespace" self.example = "namespace dude.this.rocks {" self.add_language("c#") self.add_language("c++") res_package = "(?:^|\n|\r|;)\s*namespace\s*([a-zA-Z_][a-zA-Z_0-9.]*)\s*(?:$|\n|\r|;)\s*{" self.re_package = re.compile(res_package)
def __init__(self): Check.__init__(self) self.name = "Html:Doctype" self.example = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">' self.type = Check.kTYPE_FINAL self.add_language("html") self.add_one_time_match("(?:\r|\n|^)<!DOCTYPE (HTML|html) PUBLIC \"", 200)
def __init__ (self): Check.__init__(self) self.name = "Import" self.example = "import org.apache.hadoop.conf.Configuration;" self.add_language("java") self.add_language("python") self.add_language("scala") res_package = "\s*import\s+([a-zA-Z_.]+)\s*(?:\n|\r|;)" self.re_package = re.compile(res_package)
def __init__(self): Check.__init__(self) self.name = "Package" self.example = "package com::my::dear" self.add_language("ada") self.add_language("java") self.add_language("perl") res_package = "(?:^|\n|\r|;)\s*package(?:\s*body)?\s*([a-zA-Z_0-9:.]+)\s*($|\n|\r|;|is)" self.re_package = re.compile(res_package)
def __init__(self): Check.__init__(self) self.name = "Ruby:Class/Declaration" self.example = "CoolClass < CoolClassDad" self.add_language("ruby") re_class = "[a-zA-Z_][a-zA-Z_0-9]+" self.add_multiple_matches( "(^|\r|\n)\s*class\s+" + re_class + "\s*<<?\s*" + re_class + "\s*(\r|\n|$)", 30)
def __init__ (self): Check.__init__(self) self.name = "Ada:Raise" self.example = "raise Name_Absent;" self.add_language("ada") self.add_multiple_matches("(?:^|\r|\n|;)\s*raise\s*([a-zA-Z0-9_'.]+)\s*;", 50)
def __init__ (self): Check.__init__(self) self.name = "Package" self.example = "package com::my::dear" self.add_language("ada") self.add_language("java") self.add_language("perl") res_package = "(?:^|\n|\r|;)\s*package(?:\s*body)?\s*([a-zA-Z_0-9:.]+)\s*($|\n|\r|;|is)" self.re_package = re.compile(res_package)
def __init__ (self): Check.__init__(self) self.name = "Python:Import" self.example = "from subprocess import Popen, PIPE" self.add_language("python") res_class = "[a-zA-Z][a-zA-Z0-9_]*" res_full_class = res_class + "(\." + res_class + ")*" res_class_list = res_class + "(\s*,\s*" + res_class + ")*" self.add_multiple_matches("from\s+" + res_full_class + "\s+import\s+" + res_class_list + "\s*(\n|\r|;)", 40)
def __init__(self): Check.__init__(self) self.name = "Import" self.example = "import org.apache.hadoop.conf.Configuration;" self.add_language("java") self.add_language("python") self.add_language("scala") res_package = "\s*import\s+([a-zA-Z_.]+)\s*(?:\n|\r|;)" self.re_package = re.compile(res_package)
def __init__ (self): Check.__init__(self) self.name = "Ada:RaiseException" self.example = "Raise_Exception (Valve_Failure'Identity, \"Failure while closing\");" self.add_language("ada") self.add_multiple_matches("(?:^|\r|\n|;)\s*Raise_Exception\s*\(([a-zA-Z0-9_'.]+)\s*,", 50)
def __init__(self): Check.__init__(self) self.name = "Sh:ControlFlow" self.example = "if [ -f ./myfile ] ;" self.add_language("bash") self.add_multiple_matches( "(?:^|\r|\n|;)\s*(el)?if\s*\[(?:[^\]]+?)\]\s*(?:;|\r|\n|$)", 20) self.add_multiple_matches("(?:^|\r|\n|;)fi(?:;|\r|\n|$)", 10)
def __init__ (self): Check.__init__(self) self.name = "Perl:Use" self.example = "use File::Spec;" self.add_language("perl") re_ns = "[a-zA-Z_][a-zA-Z_0-9]*" re_full_ns = re_ns + "(?:\s*::\s*" + re_ns + ")*" self.add_multiple_matches("(?:^|\n|\r|;)\s*use\s*(" + re_full_ns + ")\s*(?:$|\n|\r|;)", 10)
def __init__ (self): Check.__init__(self) self.name = "Begin" self.example = "begin" self.add_language("ada") self.add_language("ruby") self.add_multiple_matches("(?:^|\r|\n|;)\s*begin\s*(?:\r|\n)", 10)
def __init__(self): Check.__init__(self) self.name = "Ada:Raise" self.example = "raise Name_Absent;" self.add_language("ada") self.add_multiple_matches( "(?:^|\r|\n|;)\s*raise\s*([a-zA-Z0-9_'.]+)\s*;", 50)
def __init__ (self): Check.__init__(self) self.name = "Exception/Try" self.example = "try {" self.type = Check.kTYPE_MICRO self.add_language("c++") self.add_language("c#") self.add_multiple_matches("(?:\n|^|;)\s*try[\s\n\r]*{", 20)
def __init__(self): Check.__init__(self) self.name = "Begin" self.example = "begin" self.add_language("ada") self.add_language("ruby") self.add_multiple_matches("(?:^|\r|\n|;)\s*begin\s*(?:\r|\n)", 10)
def __init__(self): Check.__init__(self) self.name = "Ada:RaiseException" self.example = "Raise_Exception (Valve_Failure'Identity, \"Failure while closing\");" self.add_language("ada") self.add_multiple_matches( "(?:^|\r|\n|;)\s*Raise_Exception\s*\(([a-zA-Z0-9_'.]+)\s*,", 50)
def __init__(self): Check.__init__(self) self.name = "Perl:Use" self.example = "use File::Spec;" self.add_language("perl") re_ns = "[a-zA-Z_][a-zA-Z_0-9]*" re_full_ns = re_ns + "(?:\s*::\s*" + re_ns + ")*" self.add_multiple_matches( "(?:^|\n|\r|;)\s*use\s*(" + re_full_ns + ")\s*(?:$|\n|\r|;)", 10)
def __init__(self): Check.__init__(self) self.name = "Ada:With" self.example = "private with Ada.Strings.Unbounded" self.add_language("ada") res_sol = "(?:\r|\n|^|;)" res_scope = "(?:(?:private|limited)\s+)?" res_id = "([a-zA-Z_][a-zA-Z0-9_.]*)" res_with = res_sol + "\s*" + res_scope + "\s*with\s+" + res_id + "\s*;" self.re_with = re.compile(res_with)
def __init__ (self): Check.__init__ (self) self.name = "Ada:With" self.example = "private with Ada.Strings.Unbounded" self.add_language("ada") res_sol = "(?:\r|\n|^|;)" res_scope = "(?:(?:private|limited)\s+)?" res_id = "([a-zA-Z_][a-zA-Z0-9_.]*)" res_with = res_sol + "\s*" + res_scope + "\s*with\s+" + res_id + "\s*;" self.re_with = re.compile(res_with)
def __init__ (self): Check.__init__(self) self.name = "Python:Class/Declaration" self.example = "class CoolClass:" self.add_language("python") res_name = "(?:[a-zA-Z_][a-zA-Z0-9_]*)" res_full_name = res_name + "(?:\." + res_name + ")*" res_class = "\s*class\s+" + res_name + "\s*" res_class += "(\(\s*" + res_full_name + "\s*\))?\s*:" self.add_multiple_matches(res_class, 50)
def __init__ (self): Check.__init__ (self) self.name = "Exception/Catch" self.example = "catch (std::exception &e) {" self.type = Check.kTYPE_MICRO res_class = "[a-zA-Z0-9_][a-zA-Z0-9_:.]*" res_var = "[a-zA-Z0-9_]+" self.add_language("c++") res_catch = "(?:\n|^|;|})\s*catch\s*\(\s*(?:" + res_class + "[\s&]+(" + res_var + ")?)|(?:\.\.\.)\s*\)[\s\n\r]*{" self.add_multiple_matches(res_catch, 20)
def __init__(self): Check.__init__(self) self.name = "Lua:Function/Declaration" self.example = "function Knot:load(stream)" self.add_language("lua") res_sol = "(?:\n|\r|=)" res_var = "[a-zA-Z0-9_.:]+" res_args = "(" + res_var + "(?:\s*,\s*" + res_var + "|...)*)?" res_func = res_sol res_func += "\s*(local\s*)?" res_func += "function(\s*" + res_var + ")?\s*" res_func += "\(" + res_args + "\)(?:\r|\n)" self.add_multiple_matches(res_func, 50)
def __init__ (self): Check.__init__(self) self.name = "Lua:Function/Declaration" self.example = "function Knot:load(stream)" self.add_language("lua") res_sol = "(?:\n|\r|=)" res_var = "[a-zA-Z0-9_.:]+" res_args = "(" + res_var + "(?:\s*,\s*" + res_var + "|...)*)?" res_func = res_sol res_func += "\s*(local\s*)?" res_func += "function(\s*" + res_var + ")?\s*" res_func += "\(" + res_args + "\)(?:\r|\n)" self.add_multiple_matches(res_func, 50)
def __init__(self): Check.__init__(self) self.name = "Class" self.example = "public class GreatClassRight : DadClass" self.add_language("csharp") self.add_language("java") self.add_language("python") self.add_language("php") self.add_language("scala") # http://www.javacamp.org/javaI/Modifier.html self.java_modifiers = [ "abstract", "final", "public", "private", "static", "strictfp" ] self.java_tokens = ["extends"] # http://msdn.microsoft.com/en-us/library/0b0thckt%28VS.71%29.aspx self.csharp_modifiers = [ "abstract", "new", "public", "private", "protected", "internal", "sealed" ] self.csharp_tokens = ["where"] self.php_modifiers = ["abstract"] self.php_tokens = ["implements", "extends"] self.scala_modifiers = ["private", "protected"] self.scala_tokens = [] prefix_modifiers = [] prefix_modifiers.extend(self.csharp_modifiers) prefix_modifiers.extend(self.java_modifiers) prefix_modifiers.extend(self.php_modifiers) res_modifiers = "" for modifier in prefix_modifiers: if res_modifiers != "": res_modifiers += "|" res_modifiers += "(?:" + modifier + "\s+)" res_modifiers = "((?:" + res_modifiers + ")*)" res_class_name = "[a-zA-Z0-9_\.]+" res_class = "(?:\n|\r|;|^)\s*" + res_modifiers + "class (" + res_class_name + ")" self.re_class = re.compile(res_class)
def __init__ (self): Check.__init__(self) self.name = "Class" self.example = "public class GreatClassRight : DadClass" self.add_language("csharp") self.add_language("java") self.add_language("python") self.add_language("php") self.add_language("scala") # http://www.javacamp.org/javaI/Modifier.html self.java_modifiers = ["abstract", "final", "public", "private", "static", "strictfp"] self.java_tokens = ["extends"] # http://msdn.microsoft.com/en-us/library/0b0thckt%28VS.71%29.aspx self.csharp_modifiers = ["abstract", "new", "public", "private", "protected", "internal", "sealed"] self.csharp_tokens = ["where"] self.php_modifiers = ["abstract"] self.php_tokens = ["implements", "extends"] self.scala_modifiers = ["private", "protected"] self.scala_tokens = [] prefix_modifiers = [] prefix_modifiers.extend(self.csharp_modifiers) prefix_modifiers.extend(self.java_modifiers) prefix_modifiers.extend(self.php_modifiers) res_modifiers = "" for modifier in prefix_modifiers: if res_modifiers != "": res_modifiers += "|" res_modifiers += "(?:" + modifier + "\s+)" res_modifiers = "((?:" + res_modifiers + ")*)" res_class_name = "[a-zA-Z0-9_\.]+" res_class = "(?:\n|\r|;|^)\s*" + res_modifiers + "class (" + res_class_name + ")" self.re_class = re.compile(res_class)
def __init__(self): Check.__init__(self) self.name = "While" self.example = "while true do" self.add_language("c") self.add_language("c++") self.add_language("csharp") self.add_language("lua") self.add_language("perl") self.add_language("php") self.add_language("python") self.add_language("ruby") res_sol = "(?:^|\n|\r|;)" res_eol = "(do|:|{)" res_while = res_sol + "\s*while(\s+|\(\s*).*?(\))?" + res_eol self.re_while = re.compile(res_while)
def __init__ (self): Check.__init__(self) self.name = "While" self.example = "while true do" self.add_language("c") self.add_language("c++") self.add_language("csharp") self.add_language("lua") self.add_language("perl") self.add_language("php") self.add_language("python") self.add_language("ruby") res_sol = "(?:^|\n|\r|;)" res_eol = "(do|:|{)" res_while = res_sol + "\s*while(\s+|\(\s*).*?(\))?" + res_eol self.re_while = re.compile(res_while)
def __init__ (self): Check.__init__(self) self.name = "Python:InitMethod" self.add_language("python") self.add_multiple_matches("\s+def\s+__init__\s*\(\s*self\s*,", 40)
def __init__(self): Check.__init__(self) self.name = "Php:OpeningTag" self.example = "<?php" self.add_language("php") self.add_one_time_match("\<\?php\\s|\n|\r", 80)