Beispiel #1
0
def main():
    targets = sys.argv[1:]
    targets = common.get_all_files(targets)

    if len(targets) == 0:
        print("""
\t**** No input provided ****
\tTakes a list of files/directories as input and performs specific style checking on all files/directories.

\tGives warnings if the file does not contain a valid license text. It does not check if Copyright statements are included.
""")
        exit(0)

    path = os.path.realpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", ".."))
    for t in targets:
        file_contents, _ = common.read_file(t)
        check_license_for_file(t, file_contents, path)
import sys
from common_modules import common


def check_last_line_newline(filename, file_lines):
    """
    Checks if file ends in newline
    """
    if len(file_lines) > 0 and file_lines[-1] != "\n":
        common.log_warning("check_last_line_newline", filename,
                           len(file_lines), "no newline at end of file")


if __name__ == "__main__":
    targets = sys.argv[1:]
    targets = common.get_all_files(targets)

    if len(targets) == 0:
        print("""
\t**** No input provided ****
\tTakes a list of files/directories as input and performs specific style checking on all files/directories.

\tGives warnings if no newline at end of file
""")
        exit(0)

    for t in targets:
        _, file_lines = common.read_file(t)
        check_last_line_newline(t, file_lines)
Beispiel #3
0
    # find the pragma once guard
    pragma_re = re.compile(r"(\s*)#pragma(\s+)once(\s*)", re.MULTILINE)
    pragma_match = re.findall(pragma_re, file_contents)
    if len(pragma_match) == 0:
        common.log_warning("check_header_guards", filename, 1, "header guard missing")

    if len(pragma_match) > 1:
        common.log_warning("check_header_guards", filename, 1, "more than one occurance of header guard found")

    return None


if __name__ == "__main__":
    targets = sys.argv[1:]
    targets = common.get_all_files(targets)

    if len(targets) == 0:
        print("""
\t**** No input provided ****
\tTakes a list of files/directories as input and performs specific style checking on all files/directories

\tGives warnings if header guards does not exist in header files. Header files must have a #ifndef and #define guards directly after the license.
\tThe names of the header guards must match together and match with the name of the file in uppercase letters.
""")
        exit(0)

    for t in targets:
        if t[-2:] == ".h":
            file_contents, _ = common.read_file(t)
            check_header_guards(t, file_contents)
Beispiel #4
0
            if is_enum_class:
                if v.startswith(enum_name):
                    common.log_warning(
                        "check_enum_style", filename, line_number,
                        "enum class value may not begin with " + enum_name +
                        ": " + v)
            else:
                if not v.startswith(enum_name):
                    common.log_warning(
                        "check_enum_style", filename, line_number,
                        "enum value must begin with " + enum_name + "_ : " + v)


if __name__ == "__main__":
    targets = sys.argv[1:]
    targets = common.get_all_files(targets)

    if len(targets) == 0:
        print("""
\t**** No input provided ****
\tTakes a list of files/directories as input and performs specific style checking on all files/directories.

\tGives warnings if a file contains more than one class definition or if class name is not identical to file name
""")
        exit(0)

    for t in targets:
        clean_file_contents, _ = common.clean_file_content(
            common.read_file(t)[0])
        check_enum_style(t, clean_file_contents)
                               i + 1, "curly brace after while",
                               file_lines[i].strip(" "))
        elif re_for.search(line):
            common.log_warning(
                "check_curly_braces_alone_on_line", filename, i + 1,
                "curly brace or statement on same line with for",
                file_lines[i].strip(" "))


if __name__ == "__main__":
    targets = sys.argv[1:]
    targets = common.get_all_files(targets)

    if len(targets) == 0:
        print("""
\t**** No input provided ****
\tTakes a list of files/directories as input and performs specific style checking on all files/directories

\tGives warnings if unnecessary code exists on the same line with curly braces.
""")
        exit(0)

    for t in targets:
        if t[-2:] == ".h" or t[-4:] == ".cpp" or t[-2] == ".c":
            file_contents, file_lines = common.read_file(t)
            clean_file_contents, clean_file_lines = common.clean_file_content(
                file_contents)
            check_curly_braces_alone_on_line(t, file_contents,
                                             clean_file_contents, file_lines,
                                             clean_file_lines)