Example #1
0
def js_lint(files_list=None):
    eslint_errors_found = False
    if not path.isfile(eslint_path):
        print("Failed to run eslint, run ./scripts/install_node_deps.py to install eslint")
        eslint_errors_found = True
        return eslint_errors_found

    if files_list is None:
        files_list = [devtools_frontend_path]
    files_list = [file_name for file_name in files_list if not file_name.endswith(".eslintrc.js")]

    eslintconfig_path = path.join(devtools_path, "front_end/.eslintrc.js")
    eslintignore_path = path.join(devtools_path, "front_end/.eslintignore")
    (node_path, _) = install_node_deps.resolve_node_paths()
    exec_command = [
        node_path,
        eslint_path,
        "--config", to_platform_path_exact(eslintconfig_path),
        "--ignore-path", to_platform_path_exact(eslintignore_path),
    ] + files_list

    eslint_proc = popen(exec_command)
    (eslint_proc_out, _) = eslint_proc.communicate()
    if eslint_proc.returncode != 0:
        eslint_errors_found = True
    else:
        print("eslint exited successfully")

    print(eslint_proc_out)
    return eslint_errors_found
Example #2
0
def js_lint(files_list=None):
    eslint_errors_found = False
    if not path.isfile(eslint_path):
        print("Failed to run eslint, run ./scripts/install_node_deps.py to install eslint")
        eslint_errors_found = True
        return eslint_errors_found

    if files_list is None:
        files_list = [devtools_frontend_path]
    files_list = [file_name for file_name in files_list if not file_name.endswith(".eslintrc.js")]

    eslintconfig_path = path.join(devtools_path, ".eslintrc.js")
    eslintignore_path = path.join(devtools_path, ".eslintignore")
    (node_path, _) = install_node_deps.resolve_node_paths()
    exec_command = [
        node_path,
        eslint_path,
        "--config", to_platform_path_exact(eslintconfig_path),
        "--ignore-path", to_platform_path_exact(eslintignore_path),
    ] + files_list

    eslint_proc = popen(exec_command, cwd=devtools_path)
    (eslint_proc_out, _) = eslint_proc.communicate()
    if eslint_proc.returncode != 0:
        eslint_errors_found = True
    else:
        print("eslint exited successfully")

    print(eslint_proc_out)
    return eslint_errors_found
Example #3
0
def _FormatDevtools(input_api, output_api):
    affected_front_end_files = _getAffectedFrontEndFiles(input_api)
    if len(affected_front_end_files) == 0:
        return CheckOutput([], has_errors=False)
    original_sys_path = sys.path
    try:
        sys.path = sys.path + [input_api.os_path.join(input_api.PresubmitLocalPath(), "scripts")]
        import install_node_deps
    finally:
        sys.path = original_sys_path

    node_path, _ = install_node_deps.resolve_node_paths()
    format_path = input_api.os_path.join(input_api.PresubmitLocalPath(), "scripts", "format.js")
    glob_arg = "--glob=" + ",".join(affected_front_end_files)
    check_formatting_process = _inputPopen(
        input_api, args=[node_path, format_path] + [glob_arg, "--output-replacements-xml"]
    )
    check_formatting_out, _ = check_formatting_process.communicate()
    if check_formatting_process.returncode != 0:
        return CheckOutput([output_api.PresubmitError(check_formatting_out)], has_errors=True)
    if "</replacement>" not in check_formatting_out:
        return CheckOutput([output_api.PresubmitNotifyResult("CL is properly formatted")], has_errors=False)

    format_args = [node_path, format_path] + [glob_arg]
    format_process = _inputPopen(input_api, format_args)
    format_process_out, _ = format_process.communicate()

    # Use eslint to autofix the braces
    eslint_path = input_api.os_path.join(input_api.PresubmitLocalPath(), "node_modules", ".bin", "eslint")
    eslint_process = _inputPopen(
        input_api,
        [
            node_path,
            eslint_path,
            "--no-eslintrc",
            "--fix",
            "--env=es6",
            '--rule={"curly": [2, "multi-or-nest", "consistent"]}',
        ]
        + affected_front_end_files,
    )
    eslint_process.communicate()

    # Need to run clang-format again to align the braces
    reformat_process = _inputPopen(input_api, format_args)
    reformat_process.communicate()

    return CheckOutput(
        [
            output_api.PresubmitError(
                "ERROR: Found formatting violations.\n"
                "Ran clang-format on files changed in CL\n"
                "Use git status to check the formatting changes"
            ),
            output_api.PresubmitError(format_process_out),
        ],
        has_errors=True,
    )
Example #4
0
def _CheckFormat(input_api, output_api):
    def popen(args):
        return input_api.subprocess.Popen(args=args,
                                          stdout=input_api.subprocess.PIPE,
                                          stderr=input_api.subprocess.STDOUT)

    affected_files = _getAffectedJSFiles(input_api)
    if len(affected_files) == 0:
        return []
    original_sys_path = sys.path
    try:
        sys.path = sys.path + [
            input_api.os_path.join(input_api.PresubmitLocalPath(), "scripts")
        ]
        import install_node_deps
    finally:
        sys.path = original_sys_path

    node_path, _ = install_node_deps.resolve_node_paths()

    check_formatting_process = popen([
        'git', 'cl', 'format', '--js', '--dry-run',
        input_api.PresubmitLocalPath()
    ])
    check_formatting_process.communicate()
    if check_formatting_process.returncode == 0:
        return []

    format_args = [
        'git', 'cl', 'format', '--js',
        input_api.PresubmitLocalPath()
    ]
    format_process = popen(format_args)
    format_out, _ = format_process.communicate()
    if format_process.returncode != 0:
        return [output_api.PresubmitError(format_out)]

    # Use eslint to autofix the braces
    eslint_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
                                         "node_modules", ".bin", "eslint")
    eslint_process = popen([
        node_path, eslint_path, '--no-eslintrc', '--fix', '--env=es6',
        '--rule={"curly": [2, "multi-or-nest", "consistent"]}'
    ] + affected_files)
    eslint_process.communicate()

    # Need to run clang-format again to align the braces
    popen(format_args).communicate()

    return [
        output_api.PresubmitError(
            "ERROR: Found formatting violations in third_party/WebKit/Source/devtools.\n"
            "Ran clang-format on diff\n"
            "Use git status to check the formatting changes"),
        output_api.PresubmitError(format_out),
    ]
Example #5
0
def _FormatDevtools(input_api, output_api):
    affected_files = _getAffectedJSFiles(input_api)
    if len(affected_files) == 0:
        return CheckOutput([], has_errors=False)
    original_sys_path = sys.path
    try:
        sys.path = sys.path + [
            input_api.os_path.join(input_api.PresubmitLocalPath(), "scripts")
        ]
        import install_node_deps
    finally:
        sys.path = original_sys_path

    node_path, _ = install_node_deps.resolve_node_paths()
    format_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
                                         "scripts", "format.js")
    glob_arg = "--glob=" + ",".join(affected_files)
    check_formatting_process = _inputPopen(
        input_api,
        args=[node_path, format_path] +
        [glob_arg, "--output-replacements-xml"])
    check_formatting_out, _ = check_formatting_process.communicate()
    if check_formatting_process.returncode != 0:
        return CheckOutput([output_api.PresubmitError(check_formatting_out)],
                           has_errors=True)
    if "</replacement>" not in check_formatting_out:
        return CheckOutput(
            [output_api.PresubmitNotifyResult("CL is properly formatted")],
            has_errors=False)

    format_args = [node_path, format_path] + [glob_arg]
    format_process = _inputPopen(input_api, format_args)
    format_process_out, _ = format_process.communicate()

    # Use eslint to autofix the braces
    eslint_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
                                         "node_modules", ".bin", "eslint")
    eslint_process = _inputPopen(input_api, [
        node_path, eslint_path, '--no-eslintrc', '--fix', '--env=es6',
        '--rule={"curly": [2, "multi-or-nest", "consistent"]}'
    ] + affected_files)
    eslint_process.communicate()

    # Need to run clang-format again to align the braces
    reformat_process = _inputPopen(input_api, format_args)
    reformat_process.communicate()

    return CheckOutput([
        output_api.PresubmitError(
            "ERROR: Found formatting violations.\n"
            "Ran clang-format on files changed in CL\n"
            "Use git status to check the formatting changes"),
        output_api.PresubmitError(format_process_out)
    ],
                       has_errors=True)
def _checkWithNodeScript(input_api, output_api, script_path):
    original_sys_path = sys.path
    try:
        sys.path = sys.path + [input_api.os_path.join(input_api.PresubmitLocalPath(), "scripts")]
        import install_node_deps
    finally:
        sys.path = original_sys_path

    node_path, _ = install_node_deps.resolve_node_paths()

    process = input_api.subprocess.Popen(
        [node_path, script_path], stdout=input_api.subprocess.PIPE, stderr=input_api.subprocess.STDOUT)
    out, _ = process.communicate()

    if process.returncode != 0:
        return [output_api.PresubmitError(out)]
    return [output_api.PresubmitNotifyResult(out)]
def _CheckFormat(input_api, output_api):

    def popen(args):
        return input_api.subprocess.Popen(args=args, stdout=input_api.subprocess.PIPE, stderr=input_api.subprocess.STDOUT)

    affected_files = _getAffectedJSFiles(input_api)
    if len(affected_files) == 0:
        return []
    original_sys_path = sys.path
    try:
        sys.path = sys.path + [input_api.os_path.join(input_api.PresubmitLocalPath(), "scripts")]
        import install_node_deps
    finally:
        sys.path = original_sys_path

    node_path, _ = install_node_deps.resolve_node_paths()

    check_formatting_process = popen(['git', 'cl', 'format', '--js', '--dry-run', input_api.PresubmitLocalPath()])
    check_formatting_process.communicate()
    if check_formatting_process.returncode == 0:
        return []

    format_args = ['git', 'cl', 'format', '--js', input_api.PresubmitLocalPath()]
    format_process = popen(format_args)
    format_out, _ = format_process.communicate()
    if format_process.returncode != 0:
        return [output_api.PresubmitError(format_out)]

    # Use eslint to autofix the braces
    eslint_path = input_api.os_path.join(input_api.PresubmitLocalPath(), "node_modules", ".bin", "eslint")
    eslint_process = popen([
        node_path, eslint_path, '--no-eslintrc', '--fix', '--env=es6', '--rule={"curly": [2, "multi-or-nest", "consistent"]}'
    ] + affected_files)
    eslint_process.communicate()

    # Need to run clang-format again to align the braces
    popen(format_args).communicate()

    return [
        output_api.PresubmitError("ERROR: Found formatting violations in third_party/WebKit/Source/devtools.\n"
                                  "Ran clang-format on diff\n"
                                  "Use git status to check the formatting changes"),
        output_api.PresubmitError(format_out),
    ]
Example #8
0
def _checkWithNodeScript(input_api, output_api, script_path):
    original_sys_path = sys.path
    try:
        sys.path = sys.path + [
            input_api.os_path.join(input_api.PresubmitLocalPath(), "scripts")
        ]
        import install_node_deps
    finally:
        sys.path = original_sys_path

    node_path, _ = install_node_deps.resolve_node_paths()

    process = input_api.subprocess.Popen([node_path, script_path],
                                         stdout=input_api.subprocess.PIPE,
                                         stderr=input_api.subprocess.STDOUT)
    out, _ = process.communicate()

    if process.returncode != 0:
        return [output_api.PresubmitError(out)]
    return [output_api.PresubmitNotifyResult(out)]