예제 #1
0
    def process_files(self, files):
        """
        Run code checks with yamllint.
        Only a single process is made for all files
        to save resources.
        Configuration is not supported at this time
        """
        log.debug('Processing %s files with %s', files, self.name)

        command = ['yamllint', '--format=parsable']
        # Add config file if its present
        if self.options.get('config'):
            command += [
                '-c',
                docker.apply_base(self.options['config'])
            ]
        command += files

        output = docker.run('python2', command, self.base_path)
        if not output:
            log.debug('No yamllint errors found.')
            return False

        if 'No such file' in output and 'Traceback' in output:
            error = output.strip().split("\n")[-1]
            msg = (u'`yamllint` failed with the following error:\n'
                   '```\n'
                   '{}\n'
                   '```\n')
            return self.problems.add(IssueComment(msg.format(error)))

        output = output.split("\n")
        process_quickfix(self.problems, output, docker.strip_base)
예제 #2
0
    def process_files(self, files):
        """
        Run code checks with rubocop
        """
        command = self._create_command()
        command += files
        output = docker.run('ruby2', command, self.base_path)
        if not output:
            return
        output = output.split("\n")

        # rubocop will emit warnings at the beginning of its output.
        if '.rubocop.yml' in output[0]:
            warnings = []
            for i, line in enumerate(output):
                # Stack trace when rubocop fails.
                if line.startswith("/usr/local"):
                    continue
                # Likely a lint error.
                elif line.count(":") >= 2:
                    break
                else:
                    warnings.append(line)
            msg = [
                "Your rubocop configuration output the following error:",
                "```",
                "\n".join(warnings),
                "```",
            ]
            self.problems.add(IssueComment("\n".join(msg)))
            output = output[i:]

        process_quickfix(self.problems, output, docker.strip_base)
예제 #3
0
    def process_files(self, files):
        """
        Run code checks with pep8.
        Only a single process is made for all files
        to save resources.
        """
        log.debug('Processing %s files with %s', files, self.name)
        pep8_options = ['exclude',
                        'filename',
                        'select',
                        'ignore',
                        'max-line-length']
        command = ['pep8', '-r']
        for option, value in self.options.items():
            if option in pep8_options:
                command += [u'--{}'.format(option), value]
            else:
                log.error('%s is not a valid option to pep8', option)
        command += files
        output = run_command(command, split=True, ignore_error=True)
        if not output:
            log.debug('No pep8 errors found.')
            return False

        process_quickfix(self.problems, output, lambda name: name)
예제 #4
0
    def process_files(self, files):
        """
        Run code checks with mypy.
        Only a single process is made for all files
        to save resources.
        """
        log.debug('Processing %s files with %s', files, self.name)

        command = ['mypy', '--no-error-summary', '--show-absolute-path']
        if 'config' in self.options:
            command += ['--config-file', stringify(self.options.get('config'))]
        command += files

        output = docker.run('python3', command, source_dir=self.base_path)
        if not output:
            log.debug('No mypy errors found.')
            return False
        output = output.strip().split("\n")
        if len(output) and output[-1].startswith('mypy: error:'):
            msg = (
                u'Your `mypy` configuration file caused `mypy` to fail with:'
                '\n'
                '```\n'
                '{}\n'
                '```\n'
                'Please correct the error in your configuration file.')
            self.problems.add(IssueComment(msg.format(output[-1])))
            return

        process_quickfix(self.problems, output, docker.strip_base)
예제 #5
0
    def process_files(self, files):
        """
        Run code checks with credo.
        """
        log.debug('Processing %s files with %s', files, self.name)
        credo_options = ['checks', 'config-name', 'ignore-checks']
        credo_flags = ['all', 'all-priorities', 'strict']
        command = ['mix', 'credo', 'list', '--format', 'flycheck']
        for option, value in self.options.items():
            if option in credo_options:
                command += [u'--{}'.format(option), value]
            elif option in credo_flags:
                if self.parse_ini_bool(value):
                    command += [u'--{}'.format(option)]
            else:
                log.error('%s is not a valid option to credo', option)
        command += files
        output = docker.run('credo', command, self.base_path)
        if not output:
            log.debug('No credo errors found.')
            return False

        process_quickfix(self.problems,
                         output.strip().splitlines(),
                         docker.strip_base,
                         columns=4)
예제 #6
0
    def process_files(self, files):
        """
        Run code checks with yamllint.
        Only a single process is made for all files
        to save resources.
        Configuration is not supported at this time
        """

        command = ['yamllint', '--format=parsable']
        # Add config file if its present
        if self.options.get('config'):
            command += [
                '-c',
                docker.apply_base(self.options['config'])
            ]
        command += files

        output = docker.run('python2', command, self.base_path)
        if not output:
            return False

        if 'No such file' in output and 'Traceback' in output:
            error = output.strip().split("\n")[-1]
            msg = (u'`yamllint` failed with the following error:\n'
                   '```\n'
                   '{}\n'
                   '```\n')
            return self.problems.add(IssueComment(msg.format(error)))

        output = output.split("\n")
        process_quickfix(self.problems, output, docker.strip_base)
예제 #7
0
    def process_files(self, files):
        """
        Run code checks with pep8.
        Only a single process is made for all files
        to save resources.
        """
        log.debug('Processing %s files with %s', files, self.name)
        pep8_options = ['exclude',
                        'filename',
                        'select',
                        'ignore',
                        'max-line-length']
        command = ['pep8', '-r']
        for option, value in self.options.items():
            if option in pep8_options:
                command += [u'--{}'.format(option), value]
        command += files

        image = python_image(self.options)
        output = docker.run(image, command, source_dir=self.base_path)
        if not output:
            log.debug('No pep8 errors found.')
            return False
        output = output.split("\n")

        process_quickfix(self.problems, output, docker.strip_base)
예제 #8
0
 def process_files(self, files):
     """
     Run code checks with luacheck.
     """
     log.debug('Processing %s files with %s', files, self.name)
     command = self.create_command(files)
     output = docker.run('luacheck', command, self.base_path)
     output = output.split("\n")
     process_quickfix(self.problems, output, docker.strip_base)
예제 #9
0
    def test_invalid_content(self):
        problems = Problems()
        text = """
Error: No such file or directory: /src/main.rb
/src/readme.txt:8:1: Bad words.
"""
        tools.process_quickfix(problems, text.splitlines(), lambda x: x)
        assert len(problems) == 1
        assert 8 == problems.all('/src/readme.txt')[0].line
예제 #10
0
 def process_files(self, files):
     """
     Run code checks with luacheck.
     """
     log.debug('Processing %s files with %s', files, self.name)
     command = self.create_command(files)
     output = run_command(command, ignore_error=True, split=True)
     filename_converter = functools.partial(self._relativize_filename,
                                            files)
     process_quickfix(self.problems, output, filename_converter)
예제 #11
0
    def test_extra_colons(self):
        problems = Problems()
        text = """
/src/styles.css:8:1: invalid selector .thing::before
"""
        tools.process_quickfix(problems, text.splitlines(), lambda x: x)
        assert len(problems) == 1
        error = problems.all('/src/styles.css')[0]
        assert 8 == error.line
        assert 'invalid selector .thing::before' == error.body
예제 #12
0
 def run_individual_files(self, files, filename_converter):
     """
     If we get an error from golint about different packages
     we have to re-run golint on each file as figuring out package
     relations is hard.
     """
     for filename in files:
         command = self.create_command([filename])
         output = run_command(command, ignore_error=True, split=True)
         process_quickfix(self.problems, output, filename_converter)
예제 #13
0
 def run_individual_files(self, files, filename_converter):
     """
     If we get an error from golint about different packages
     we have to re-run golint on each file as figuring out package
     relations is hard.
     """
     for filename in files:
         command = self.create_command([filename])
         output = run_command(command, ignore_error=True, split=True)
         process_quickfix(self.problems, output, filename_converter)
예제 #14
0
    def process_files(self, files):
        """
        Run code checks with standard.
        """
        command = ['standard'] + list(files)
        output = docker.run('nodejs', command, source_dir=self.base_path)

        output = output.split("\n")
        output = [line for line in output if not line.startswith('standard')]
        process_quickfix(self.problems, output, docker.strip_base)
예제 #15
0
 def run_individual_files(self, files, filename_converter):
     """
     If we get an error from golint about different packages
     we have to re-run golint on each file as figuring out package
     relations is hard.
     """
     for filename in files:
         command = self.create_command([filename])
         output = docker.run('golint', command, self.base_path)
         output = output.split("\n")
         process_quickfix(self.problems, output, filename_converter)
예제 #16
0
    def process_files(self, files):
        """
        Run code checks with flake8.
        """
        command = self.make_command(files)
        image = self.get_image_name(files)

        output = docker.run(image, command, source_dir=self.base_path)

        self._cleanup()
        output = output.split("\n")
        process_quickfix(self.problems, output, docker.strip_base)
예제 #17
0
    def process_files(self, files):
        """
        Run code checks with puppet-lint
        """
        command = self._create_command()
        command += files
        output = docker.run('ruby2', command, self.base_path)

        if not output:
            return False

        output = output.split("\n")
        process_quickfix(self.problems, output, docker.strip_base)
예제 #18
0
    def process_files(self, files):
        """
        Run code checks with flake8.
        Only a single process is made for all files
        to save resources.
        """
        log.debug('Processing %s files with %s', len(files), self.name)
        command = self.make_command(files)
        output = run_command(command, split=True, ignore_error=True)
        if not output:
            log.debug('No flake8 errors found.')
            return False

        process_quickfix(self.problems, output, lambda name: name)
예제 #19
0
    def process_files(self, files):
        """
        Run code checks with credo.
        """
        command = self.create_command()
        command += files
        output = docker.run('credo', command, self.base_path)
        if not output:
            return False

        process_quickfix(self.problems,
                         output.strip().splitlines(),
                         docker.strip_base,
                         columns=4)
예제 #20
0
    def process_files(self, files):
        """
        Run code checks with standard.
        """
        log.debug('Processing %s files with %s', files, self.name)
        command = ['standard'] + list(files)
        output = docker.run(
            'nodejs',
            command,
            source_dir=self.base_path)

        output = output.split("\n")
        output = [line for line in output if not line.startswith('standard')]
        process_quickfix(self.problems, output, docker.strip_base)
예제 #21
0
    def process_files(self, files):
        """
        Run code checks with flake8.
        Only a single process is made for all files
        to save resources.
        """
        log.debug('Processing %s files with %s', len(files), self.name)
        command = self.make_command(files)
        output = run_command(command, split=True, ignore_error=True)
        if not output:
            log.debug('No flake8 errors found.')
            return False

        process_quickfix(self.problems, output, lambda name: name)
예제 #22
0
 def process_files(self, files):
     """
     Run code checks with luacheck.
     """
     command = self.create_command(files)
     output = docker.run('luacheck', command, self.base_path)
     output = output.split("\n")
     if len(output) and 'Critical' in output[0]:
         msg = (u"luacheck failed with the following error:\n"
                u"```\n"
                u"{}\n"
                u"```\n")
         self.problems.add(IssueComment(msg.format(output[0])))
         return
     process_quickfix(self.problems, output, docker.strip_base)
예제 #23
0
    def process_files(self, files):
        """
        Run code checks with puppet-lint
        """
        log.debug('Processing %s files with %s', files, self.name)
        command = self._create_command()
        command += files
        output = docker.run('ruby2', command, self.base_path)

        if not output:
            log.debug('No puppet-lint errors found.')
            return False

        output = output.split("\n")
        process_quickfix(self.problems, output, docker.strip_base)
예제 #24
0
    def process_files(self, files):
        """
        Run code checks with rubocop
        """
        log.debug('Processing %s files with %s', files, self.name)
        command = self._create_command()
        command += files
        output = docker.run('ruby2', command, self.base_path)

        if not output:
            log.debug('No rubocop errors found.')
            return False

        output = output.split("\n")
        process_quickfix(self.problems, output, docker.strip_base)
예제 #25
0
파일: py3k.py 프로젝트: jpos15/lint-review
    def process_files(self, files):
        """
        Run code checks with pylint --py3k.
        Only a single process is made for all files
        to save resources.
        """
        command = self.make_command(files)
        output = docker.run('python2', command, self.base_path)
        if not output:
            return False

        output = output.split("\n")
        output = [line for line in output if not line.startswith("*********")]

        process_quickfix(self.problems, output, docker.strip_base)
예제 #26
0
    def process_files(self, files):
        """
        Run code checks with flake8.
        Only a single process is made for all files
        to save resources.
        """
        log.debug('Processing %s files with %s', len(files), self.name)
        command = self.make_command(files)
        image = python_image(self.options)
        output = docker.run(image, command, source_dir=self.base_path)
        if not output:
            log.debug('No flake8 errors found.')
            return False

        output = output.split("\n")
        process_quickfix(self.problems, output, docker.strip_base)
예제 #27
0
 def process_files(self, files):
     """
     Run code checks with luacheck.
     """
     log.debug('Processing %s files with %s', files, self.name)
     command = self.create_command(files)
     output = docker.run('luacheck', command, self.base_path)
     output = output.split("\n")
     if len(output) and 'Critical' in output[0]:
         msg = (u"luacheck failed with the following error:\n"
                u"```\n"
                u"{}\n"
                u"```\n")
         self.problems.add(IssueComment(msg.format(output[0])))
         return
     process_quickfix(self.problems, output, docker.strip_base)
예제 #28
0
    def process_files(self, files):
        """
        Run code checks with credo.
        """
        log.debug('Processing %s files with %s', files, self.name)
        command = self.create_command()
        command += files
        output = docker.run('credo', command, self.base_path)
        if not output:
            log.debug('No credo errors found.')
            return False

        process_quickfix(self.problems,
                         output.strip().splitlines(),
                         docker.strip_base,
                         columns=4)
예제 #29
0
    def process_files(self, files):
        """
        Run code checks with flake8.
        Only a single process is made for all files
        to save resources.
        """
        log.debug('Processing %s files with %s', len(files), self.name)
        command = self.make_command(files)
        image = python_image(self.options)
        output = docker.run(image, command, source_dir=self.base_path)
        if not output:
            log.debug('No flake8 errors found.')
            return False

        output = output.split("\n")
        process_quickfix(self.problems, output, docker.strip_base)
예제 #30
0
    def process_files(self, files):
        """
        Run code checks with jsonlint.
        Only a single process is made for all files
        to save resources.
        Configuration is not supported at this time
        """
        command = ['jsonlint']
        command += files

        output = docker.run('python2', command, source_dir=self.base_path)
        if not output:
            return False

        output = output.split("\n")
        process_quickfix(self.problems, output, docker.strip_base)
예제 #31
0
 def process_files(self, files):
     """
     Run code checks with stylelint.
     """
     command = self._create_command()
     command += files
     output = docker.run('nodejs', command, source_dir=self.base_path)
     if ('SyntaxError' in output or 'ENOENT' in output
             or 'JSONError' in output):
         msg = (
             u"Your configuration file resulted in the following error:\n"
             "```\n"
             "{}"
             "```\n")
         return self.problems.add(IssueComment(msg.format(output)))
     process_quickfix(self.problems, output.splitlines(), docker.strip_base)
예제 #32
0
    def process_files(self, files):
        """
        Run code checks with credo.
        """
        log.debug('Processing %s files with %s', files, self.name)
        command = self.create_command()
        command += files
        output = docker.run('credo', command, self.base_path)
        if not output:
            log.debug('No credo errors found.')
            return False

        process_quickfix(
            self.problems,
            output.strip().splitlines(),
            docker.strip_base,
            columns=4)
예제 #33
0
    def process_files(self, files):
        """
        Run code checks with standard.
        """
        log.debug('Processing %s files with %s', files, self.name)
        cmd = self.name
        if npm_exists('standard'):
            cmd = os.path.join(os.getcwd(), 'node_modules', '.bin', 'standard')

        filename_converter = functools.partial(self._relativize_filename,
                                               files)

        command = [cmd] + list(files)
        output = run_command(command, split=True, ignore_error=True)

        output = filter(lambda line: not line.startswith('standard'), output)
        process_quickfix(self.problems, output, filename_converter)
예제 #34
0
 def process_files(self, files):
     """
     Run code checks with golint.
     Only a single process is made for all files
     to save resources.
     """
     command = self.create_command(files)
     output = docker.run('golint', command, self.base_path)
     output = output.strip().split("\n")
     # Look for multi-package error message, and re-run tools
     if len(output) == 1 and 'is in package' in output[0]:
         log.info(
             'Re-running golint on individual files '
             'as diff contains files from multiple packages: %s', output[0])
         self.run_individual_files(files, docker.strip_base)
     else:
         process_quickfix(self.problems, output, docker.strip_base)
예제 #35
0
    def process_files(self, files):
        """
        Run code checks with pep8.
        Only a single process is made for all files
        to save resources.
        """
        log.debug('Processing %s files with %s', files, self.name)
        command = ['pep8', '-r']
        if self.options.get('ignore'):
            command += ['--ignore', self.options.get('ignore')]
        command += files
        output = run_command(command, split=True, ignore_error=True)
        if not output:
            log.debug('No pep8 errors found.')
            return False

        process_quickfix(self.problems, output, lambda name: name)
예제 #36
0
    def process_files(self, files):
        """
        Run code checks with pylint --py3k.
        Only a single process is made for all files
        to save resources.
        """
        log.debug('Processing %s files with %s', files, self.name)
        command = self.make_command(files)
        output = docker.run('python2', command, self.base_path)
        if not output:
            log.debug('No py3k errors found.')
            return False

        output = output.split("\n")
        output = [line for line in output if not line.startswith("*********")]

        process_quickfix(self.problems, output, docker.strip_base)
예제 #37
0
    def test(self):
        problems = Problems()
        text = """
/src/file.py:1:1: A message.
/src/dir/file.text:10:1: Another message
"""
        tools.process_quickfix(problems, text.splitlines(), lambda x: x)
        assert len(problems) == 2
        filepy = problems.all('/src/file.py')[0]
        assert 1 == filepy.position
        assert 1 == filepy.line
        assert 'A message.' == filepy.body

        filetext = problems.all('/src/dir/file.text')[0]
        assert 10 == filetext.position
        assert 10 == filetext.line
        assert 'Another message' == filetext.body
예제 #38
0
    def process_files(self, files):
        """
        Run code checks with pylint --py3k.
        Only a single process is made for all files
        to save resources.
        """
        log.debug('Processing %s files with %s', files, self.name)
        command = self.make_command(files)
        output = run_command(command, split=True, ignore_error=True)
        if not output:
            log.debug('No py3k errors found.')
            return False

        output = [line for line in output if not line.startswith("*********")]

        filename_converter = functools.partial(self._relativize_filename,
                                               files)
        process_quickfix(self.problems, output, filename_converter)
예제 #39
0
    def process_files(self, files):
        """
        Run code checks with puppet-lint
        """
        log.debug('Processing %s files with %s', files, self.name)
        command = ['bundle', 'exec', 'puppet-lint']
        command += ['--log-format',
                    '%{path}:%{line}:%{column}:%{KIND}:%{message}']
        if self.options.get('config'):
            command += ['-c', self.apply_base(self.options['config'])]
        command += files
        output = docker.run('ruby2', command, self.base_path)

        if not output:
            log.debug('No puppet-lint errors found.')
            return False

        output = output.split("\n")
        process_quickfix(self.problems, output, docker.strip_base)
예제 #40
0
    def process_files(self, files):
        """
        Run code checks with ansible-lint.
        Only a single process is made for all files
        to save resources.
        """
        command = ['ansible-lint', '-p']
        if self.options.get('ignore'):
            command += ['-x', self.options.get('ignore')]
        command += files
        output = docker.run('python2', command, self.base_path)
        if not output:
            log.debug('No ansible-lint errors found.')
            return False

        output = output.split("\n")
        output.sort()

        process_quickfix(self.problems, output, docker.strip_base)
예제 #41
0
 def process_files(self, files):
     """
     Run code checks with stylelint.
     """
     log.debug('Processing %s files with %s', files, self.name)
     command = self._create_command()
     command += files
     output = docker.run(
         'nodejs',
         command,
         source_dir=self.base_path)
     if 'SyntaxError' in output or 'ENOENT' in output:
         msg = (
             u"Your configuration file resulted in the following error:\n"
             "```\n"
             "{}"
             "```\n"
         )
         return self.problems.add(IssueComment(msg.format(output)))
     process_quickfix(self.problems, output.splitlines(), docker.strip_base)
예제 #42
0
    def process_files(self, files):
        """
        Run code checks with rubocop
        """
        log.debug('Processing %s files with %s', files, self.name)
        command = self._create_command()
        command += files
        output = docker.run('ruby2', command, self.base_path)
        if not output:
            log.debug('No rubocop errors found.')
            return
        output = output.split("\n")
        if '.rubocop.yml' in output[0]:
            msg = u'Your rubocop configuration output the following error:\n' \
                   '```\n' \
                   '{}\n' \
                   '```'
            return self.problems.add(IssueComment(msg.format(output[0])))

        process_quickfix(self.problems, output, docker.strip_base)
예제 #43
0
    def process_files(self, files):
        """
        Run code checks with standard.
        """
        log.debug('Processing %s files with %s', files, self.name)
        cmd = self.name
        if npm_exists('standard'):
            cmd = os.path.join(os.getcwd(), 'node_modules', '.bin', 'standard')

        filename_converter = functools.partial(
            self._relativize_filename,
            files)

        command = [cmd] + list(files)
        output = run_command(
            command,
            split=True,
            ignore_error=True)

        output = [line for line in output if not line.startswith('standard')]
        process_quickfix(self.problems, output, filename_converter)
예제 #44
0
    def process_files(self, files):
        """
        Run code checks with yamllint.
        Only a single process is made for all files
        to save resources.
        Configuration is not supported at this time
        """
        log.debug('Processing %s files with %s', files, self.name)

        command = ['yamllint', '--format=parsable']
        # Add config file if its present
        if self.options.get('config'):
            command += ['-c', self.apply_base(self.options['config'])]
        command += files

        output = run_command(command, split=True, ignore_error=True)
        if not output:
            log.debug('No yamllint errors found.')
            return False

        process_quickfix(self.problems, output, lambda x: x)
예제 #45
0
 def process_files(self, files):
     """
     Run code checks with golint.
     Only a single process is made for all files
     to save resources.
     """
     command = self.create_command(files)
     output = run_command(
         command,
         ignore_error=True,
         split=True)
     filename_converter = functools.partial(
         self._relativize_filename,
         files)
     # Look for multi-package error message, and re-run tools
     if len(output) == 1 and 'is in package' in output[0]:
         log.info('Re-running golint on individual files'
                  'as diff contains files from multiple packages: %s',
                  output[0])
         self.run_individual_files(files, filename_converter)
     else:
         process_quickfix(self.problems, output, filename_converter)
예제 #46
0
    def process_files(self, files):
        """
        Run code checks with jsonlint.
        Only a single process is made for all files
        to save resources.
        Configuration is not supported at this time
        """
        log.debug('Processing %s files with %s', files, self.name)

        command = ['jsonlint']
        command += files

        output = docker.run(
            'python2',
            command,
            source_dir=self.base_path)
        if not output:
            log.debug('No jsonlint errors found.')
            return False

        output = output.split("\n")
        process_quickfix(self.problems, output, docker.strip_base)