(file_line_mapping, **extra)
return '\n'.join(result), error_count
Runs CppCheck on the project with the default configured rules. The output
    is reduced to only contain entries from the Git change set.

    :param file_line_mapping: Mapping of files with changed lines (obtained
        `get_git_line_sets()`).
    :param extra: Optional keyword arguments:
        `platform`: A specific platform to test for, as used in
                    `include/mega/` (default: detect local system's platform).
    :return: A tuple containing the formatted string suitable for output and
        an integer containing the number of failed rules.
Runs CppCheck on the project with the default configured rules. The output
    is reduced to only contain entries from the Git change set.
Runs CppCheck on the project with the default configured rules . The output is reduced to only contain entries from the Git change set .
def reduce_cppcheck(file_line_mapping, **extra):
    """
    Runs CppCheck on the project with the default configured rules. The output
    is reduced to only contain entries from the Git change set.

    :param file_line_mapping: Mapping of files with changed lines (obtained
        `get_git_line_sets()`).
    :param extra: Optional keyword arguments:
        `platform`: A specific platform to test for, as used in
                    `include/mega/` (default: detect local system's platform).
    :return: A tuple containing the formatted string suitable for output and
        an integer containing the number of failed rules.
    """
    logging.info('Obtaining CppCheck output ...')
    platform = platform = PLATFORMS[os.name]
    if 'platform' in extra:
        # Override if given.
        platform = extra['platform']

    # Get the CppCheck output.
    os.chdir(PROJECT_PATH)
    command = config.CPPCHECK_COMMAND.format(command=config.CPPCHECK_BIN,
                                             platform=platform)
    output = None
    try:
        output = subprocess.check_output(command.split(),
                                         stderr=subprocess.STDOUT)
    except subprocess.CalledProcessError as ex:
        # CppCheck found something, so it has returned an error code.
        # But we still want the output in the same fashion.
        output = ex.output
    output = output.decode('utf8').split('\n')

    # Go through output and collect only relevant lines to the result.
    logging.debug('Reducing CppCheck output ...')
    result = ['\nCppCheck output:\n================\n']
    cppcheck_expression = re.compile(r'^(.+);(\d+);')
    for line in output:
        parse_result = cppcheck_expression.findall(line)
        # Check if we've got a relevant line.
        if parse_result:
            file_name, line_no = parse_result[0][0], int(parse_result[0][1])
            file_name = tuple(re.split(PATH_SPLITTER, file_name))
            # Check if the line is part of our selection list.
            if line_no in file_line_mapping[file_name]:
                formatted = '; '.join(line.split(';'))
                result.append(formatted)

    # Add the number of errors and return in a nicely formatted way.
    error_count = len(result) - 1
    result.append('\n{} errors'.format(error_count))
    return '\n'.join(result), error_count
def reduce_cppcheck ( file_line_mapping , * * extra ) : logging . info ( 'Obtaining CppCheck output ...' ) platform = platform = PLATFORMS [ os . name ] if 'platform' in extra : # Override if given. platform = extra [ 'platform' ] # Get the CppCheck output. os . chdir ( PROJECT_PATH ) command = config . CPPCHECK_COMMAND . format ( command = config . CPPCHECK_BIN , platform = platform ) output = None try : output = subprocess . check_output ( command . split ( ) , stderr = subprocess . STDOUT ) except subprocess . CalledProcessError as ex : # CppCheck found something, so it has returned an error code. # But we still want the output in the same fashion. output = ex . output output = output . decode ( 'utf8' ) . split ( '\n' ) # Go through output and collect only relevant lines to the result. logging . debug ( 'Reducing CppCheck output ...' ) result = [ '\nCppCheck output:\n================\n' ] cppcheck_expression = re . compile ( r'^(.+);(\d+);' ) for line in output : parse_result = cppcheck_expression . findall ( line ) # Check if we've got a relevant line. if parse_result : file_name , line_no = parse_result [ 0 ] [ 0 ] , int ( parse_result [ 0 ] [ 1 ] ) file_name = tuple ( re . split ( PATH_SPLITTER , file_name ) ) # Check if the line is part of our selection list. if line_no in file_line_mapping [ file_name ] : formatted = '; ' . join ( line . split ( ';' ) ) result . append ( formatted ) # Add the number of errors and return in a nicely formatted way. error_count = len ( result ) - 1 result . append ( '\n{} errors' . format ( error_count ) ) return '\n' . join ( result ) , error_count