コード例 #1
0
def js_lint(files_list=None):
    eslint_errors_found = False

    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')
    exec_command = [
        devtools_paths.node_path(),
        devtools_paths.eslint_path(),
        '--config',
        to_platform_path_exact(eslintconfig_path),
        '--ignore-path',
        to_platform_path_exact(eslintignore_path),
        '--fix',
    ] + 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
コード例 #2
0
def main():
    eslintconfig_path = path.join(ROOT_DIRECTORY, '.eslintrc.js')
    scripts_eslintconfig_path = path.join(ROOT_DIRECTORY, 'scripts',
                                          '.eslintrc.js')
    eslintignore_path = path.join(ROOT_DIRECTORY, '.eslintignore')

    directories_or_files_to_lint = sys.argv[1:]

    if len(directories_or_files_to_lint) == 0:
        directories_or_files_to_lint = DEFAULT_DIRECTORIES_TO_LINT

    exec_command = [
        devtools_paths.node_path(),
        devtools_paths.eslint_path(),
        '--config',
        test_helpers.to_platform_path_exact(eslintconfig_path),
        '--config',
        test_helpers.to_platform_path_exact(scripts_eslintconfig_path),
        '--ignore-path',
        test_helpers.to_platform_path_exact(eslintignore_path),
        '--ext',
        '.js,.ts',
        '--fix',
    ] + directories_or_files_to_lint

    eslint_proc = Popen(exec_command, cwd=ROOT_DIRECTORY)
    eslint_proc.communicate()

    sys.exit(eslint_proc.returncode)
コード例 #3
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 devtools_paths
    finally:
        sys.path = original_sys_path

    ignore_files = []
    eslint_ignore_path = input_api.os_path.join(input_api.PresubmitLocalPath(), '.eslintignore')
    with open(eslint_ignore_path, 'r') as ignore_manifest:
        for line in ignore_manifest:
            ignore_files.append(input_api.os_path.normpath(line.strip()))
    formattable_files = [
        affected_file for affected_file in affected_files if all(ignore_file not in affected_file for ignore_file in ignore_files)
    ]
    if len(formattable_files) == 0:
        return []

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

    format_args = ['git', 'cl', 'format', '--js'] + formattable_files
    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.
    # Also fix semicolon to avoid confusing clang-format.
    eslint_process = popen(
        [devtools_paths.node_path(), devtools_paths.eslint_path(), '--config', '.eslintrc.js', '--fix'] + 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.\n'
                                  'Ran clang-format on diff\n'
                                  'Use git status to check the formatting changes'),
        output_api.PresubmitError(format_out),
    ]