"""
    # get yamllint version
    command = ['yamllint', '--version']
    version_info = run_command(command, verbose=False)[0]
    print('USING              : {0}'.format(version_info))

    def has_failed(returncode, _stdout, _stderr):
        """Determine if yamllint ran correctly."""
        return not 0 <= returncode < 2

    messages = []
    if len(filenames) > 0:
        command = ['yamllint', '-f', 'parsable'] + filenames
        if config['config'] is not None:
            command += ['-c', config['config']]
        output = run_command(command, has_failed=has_failed)[0]
        if len(output) > 0:
            for line in output.splitlines():
                words = line.split(':')
                messages.append(
                    Message(words[0], int(words[1]), int(words[2]),
                            words[3].strip()))
    return messages


# pylint: disable=invalid-name
linter_yamllint = Linter('yamllint',
                         run_yamllint,
                         DEFAULT_CONFIG,
                         language='yaml')
        A list of filenames to check

    Returns
    -------
    messages : list
        The list of messages generated by the external linter.

    """
    # get flake8 version
    command = ['flake8', '--version']
    version_info = run_command(command, verbose=False)[0]
    print('USING              : {0}'.format(version_info))

    messages = []
    if len(filenames) > 0:
        command = ['flake8'] + filenames
        if config['config'] is not None:
            command += ['--config={0}'.format(config['config'])]
        output = run_command(command, has_failed=_has_failed)[0]
        if len(output) > 0:
            for line in output.splitlines():
                words = line.split(':')
                messages.append(
                    Message(words[0], int(words[1]), int(words[2]),
                            words[3].strip()))
    return messages


# pylint: disable=invalid-name
linter_flake8 = Linter('flake8', run_flake8, DEFAULT_CONFIG, language='python')
        if '__all__' in names:
            for name in names:
                if name in module.__all__:
                    namespace.setdefault(name, []).append(filename)
                    if name in config['forbidden']:
                        messages.append(
                            Message(
                                filename, None, None,
                                'Invalid name in namespace: {0}'.format(name)))
        else:
            messages.append(Message(filename, None, None, 'Missing __all__'))

    # Fix sys.path
    del sys.path[0]

    # Detect collisions
    for name, sourcefiles in namespace.items():
        if len(sourcefiles) > 1:
            text = "Name '{0}' found in more than one module: {1}".format(
                name, ' '.join(sourcefiles))
            messages.append(Message(sourcefiles[0], None, None, text))
    return messages


# pylint: disable=invalid-name
linter_namespace = Linter('namespace',
                          run_namespace,
                          DEFAULT_CONFIG,
                          style='dynamic',
                          language='python')
    version_info = run_command(command, verbose=False)[0]
    print('USING              : {0}'.format(version_info))

    def has_failed(returncode, _stdout, _stderr):
        """Determine if pydocstyle ran correctly."""
        return not 0 <= returncode < 2

    messages = []
    if len(filenames) > 0:
        command = ['pydocstyle'] + filenames
        if config['config'] is not None:
            command += ['--config={0}'.format(config['config'])]
        output = run_command(command, has_failed=has_failed)[0]
        lines = output.split('\n')[:-1]
        while len(lines) > 0:
            if 'WARNING: ' in lines[0]:
                lines.pop(0)
            else:
                words = lines.pop(0).split()
                filename, lineno = words[0].split(':')
                code, description = lines.pop(0).split(':', 1)
                code = code.strip()
                description = description.strip()
                messages.append(Message(
                    filename, int(lineno), None, '%s %s' % (code, description)))
    return messages


# pylint: disable=invalid-name
linter_pydocstyle = Linter('pydocstyle', run_pydocstyle, DEFAULT_CONFIG, language='python')
                messages.append(Message(filename, None, None, str(err)))
    return messages


def _check_file(filename: str, config: dict, messages: List[str]):
    """Look for bad imports in the given file.

    Parameters
    ----------
    filename
        File to be checked
    config
        Dictionary with configuration of the linters.
    messages
        A list of messages to append to. (output arg)

    """
    with codecs.open(filename, encoding='utf-8') as f:
        for lineno, line in enumerate(f):
            for package in config['packages']:
                # skip version import
                if line == u'from {0} import __version__\n'.format(package):
                    continue
                if u'from {0} import'.format(package) in line:
                    text = 'Wrong import from {0}'.format(package)
                    messages.append(Message(filename, lineno + 1, None, text))


# pylint: disable=invalid-name
linter_import = Linter('import', run_import, DEFAULT_CONFIG, language='python')
Exemple #6
0
        """Determine if pylint ran correctly."""
        return not 0 <= returncode < 32

    messages = []
    if len(filenames) > 0:
        command = ['pylint'] + filenames
        command += ['--jobs=2', '--output-format=json']
        if config['config'] is not None:
            command += ['--rcfile={0}'.format(config['config'])]
        output = run_command(command, has_failed=has_failed)[0]
        if len(output) > 0:
            for plmap in json.loads(output):
                charno = plmap['column']
                if charno in [0, -1]:
                    charno = None
                messages.append(
                    Message(
                        plmap['path'], plmap['line'], charno,
                        '{0} {1}'.format(plmap['symbol'], plmap['message'])))
    return messages


# Pylint should be considered dynamic, which is in practice only true for projects with
# extension modules.
# pylint: disable=invalid-name
linter_pylint = Linter('pylint',
                       run_pylint,
                       DEFAULT_CONFIG,
                       style='dynamic',
                       language='python')
    messages = []
    for filename in filenames:
        with codecs.open(filename, encoding='utf-8') as f:
            iterator = iter(enumerate(f))
            header_counter = 0
            while header_counter < len(header_lines):
                try:
                    lineno, line = next(iterator)
                except StopIteration:
                    break
                if lineno == 0 and line.startswith(
                        '#!') and config['shebang'] is not None:
                    if line[:-1] != config['shebang']:
                        messages.append(
                            Message(
                                filename, lineno + 1, None,
                                'Shebang line should be {}.'.format(
                                    config['shebang'])))
                else:
                    expected = header_lines[header_counter]
                    if line[:-1] != expected:
                        messages.append(
                            Message(filename, lineno + 1, None,
                                    'Line should be: {}'.format(expected)))
                    header_counter += 1
    return messages


# pylint: disable=invalid-name
linter_header = Linter('header', run_header, DEFAULT_CONFIG)
Exemple #8
0
    command = ['doxygen', '--version']
    print('USING              : doxygen',
          run_command(command, verbose=False)[0].strip())

    messages = []
    if len(filenames) > 0:
        # Call doxygen in the doc subdirectory, mute output because it only confuses
        command = ['doxygen', '-']
        stdin = DOXYGEN_CONFIG.format(' '.join(filenames))
        print('STDIN              :')
        print(stdin)
        output = run_command(command, stdin=stdin)[1]

        # Parse the file doxygen_warnings
        prefix = os.getcwd() + '/'

        lines = output.split('\n')
        for line in lines:
            if line.startswith('~~WARN~~'):
                location, description = line[9:].split(None, 1)
                filename, lineno = location.split(':')[:2]
                if filename.startswith(prefix):
                    filename = filename[len(prefix):]
                message = Message(filename, int(lineno), None, description)
                messages.append(message)
    return messages


# pylint: disable=invalid-name
linter_doxygen = Linter('doxygen', run_doxygen, DEFAULT_CONFIG, language='cpp')
        lineno = -1
        for lineno, line in enumerate(f):
            # Check for tabs
            charno = line.find('\t')
            if charno >= 0:
                messages.append(
                    Message(filename, lineno + 1, charno + 1, 'tab'))
            # Check for carriage return
            charno = line.find('\r')
            if charno >= 0:
                messages.append(
                    Message(filename, lineno + 1, charno + 1,
                            'carriage return'))
            # Check for trailing whitespace
            if line[:-1] != line.rstrip():
                messages.append(
                    Message(filename, lineno + 1, None, 'trailing whitespace'))
        # Perform some checks on the last line
        if line is not None:
            if len(line.strip()) == 0:
                messages.append(
                    Message(filename, lineno + 1, None, 'trailing empty line'))
            if not line.endswith("\n"):
                messages.append(
                    Message(filename, lineno + 1, None,
                            'last line missing \\n'))


# pylint: disable=invalid-name
linter_whitespace = Linter('whitespace', run_whitespace, DEFAULT_CONFIG)
Exemple #10
0
    print('USING VERSION      : {0}'.format(
        run_command(['cppcheck', '--version'], verbose=False)[0].strip()))

    messages = []
    if len(filenames) > 0:
        # Call Cppcheck
        command = (['cppcheck'] + filenames +
                   ['-q', '--enable=all', '--language=c++', '--std=c++11', '--xml',
                    '--suppress=missingIncludeSystem', '--suppress=unusedFunction'])
        xml_str = run_command(command)[1]
        etree = ElementTree.fromstring(xml_str)

        # Parse the output of Cppcheck into standard return values
        for error in etree:
            if 'file' not in error.attrib:
                continue
            # key = '{:<15}  {:<40}  {:<30}' % (error.attrib['severity'],
            #                                   error.attrib['file'],
            #                                   error.attrib['id'])
            text = '{} {} {}'.format(
                error.attrib['severity'], error.attrib['id'], error.attrib['msg'])
            lineno = int(error.attrib['line'])
            if lineno == 0:
                lineno = None
            messages.append(Message(error.attrib['file'], lineno, None, text))
    return messages


# pylint: disable=invalid-name
linter_cppcheck = Linter('cppcheck', run_cppcheck, DEFAULT_CONFIG, language='cpp')
Exemple #11
0
    messages : list
        The list of messages generated by the external linter.

    """
    messages = []
    if len(filenames) > 0:
        # Call cpplint
        command = ([config['script'], '--linelength=100', '--filter=-runtime/int'] +
                   filenames)
        output = run_command(command, has_failed=_has_failed)[1]

        # Parse the output of cpplint into standard return values
        for line in output.split('\n')[:-1]:
            words = line.split()
            if len(words) == 0 or words[0].count(':') != 2:
                continue
            filename, lineno = words[0].split(':')[:2]
            description = ' '.join(words[1:-2])
            tag = words[-2]
            priority = words[-1]
            lineno = int(lineno)
            if lineno == 0:
                lineno = None
            messages.append(Message(filename, lineno, None, '%s %s %s' % (
                priority, tag, description)))
    return messages


# pylint: disable=invalid-name
linter_cpplint = Linter('cpplint', run_cpplint, DEFAULT_CONFIG, language='cpp')