Beispiel #1
0
    def process_files(self, files):
        """
        Run code checks with ESLint.
        """
        log.debug('Processing %s files with %s', files, self.name)
        cmd = self.name
        if npm_exists('eslint'):
            cmd = os.path.join(os.getcwd(), 'node_modules', '.bin', 'eslint')
        command = [cmd, '--format', 'checkstyle']

        # Add config file or default to recommended linters
        if self.options.get('config'):
            command += ['--config', self.apply_base(self.options['config'])]

        command += files
        output = run_command(
            command,
            ignore_error=True)

        if output.startswith('Cannot read config file'):
            msg = u'Your eslint config file is missing or invalid. ' \
                   u'Please ensure that `{}` exists and is valid.'
            msg = msg.format(self.options['config'])
            return self.problems.add(IssueComment(msg))

        filename_converter = functools.partial(
            self._relativize_filename,
            files)
        self._process_checkstyle(output, filename_converter)
Beispiel #2
0
    def process_files(self, files):
        """
        Run code checks with swiftlit.
        """
        log.debug('Processing %s files with %s', files, self.name)

        command = [
            'swiftlint', 'lint', '--quiet', '--reporter', 'checkstyle',
            '--use-script-input-files'
        ]

        # swiftlint uses a set of environment variables
        # to lint multiple files at once.
        env = os.environ.copy()
        for index, name in enumerate(files):
            env['SCRIPT_INPUT_FILE_%s' % (index, )] = name
        env['SCRIPT_INPUT_FILE_COUNT'] = str(len(files))

        output = run_command(command,
                             env=env,
                             cwd=self.base_path,
                             ignore_error=True)

        filename_converter = functools.partial(self._relativize_filename,
                                               files)
        process_checkstyle(self.problems, output, filename_converter)
Beispiel #3
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', files, self.name)
        command = ['flake8']
        for option in self.PYFLAKE_OPTIONS:
            if self.options.get(option):
                command.extend([
                    '--%(option)s' % {
                        'option': option
                    },
                    self.options.get(option)
                ])

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

        for line in output:
            filename, line, error = self._parse_line(line)
            self.problems.add(filename, line, error)
Beispiel #4
0
    def process_files(self, files):
        """
        Run code checks with checkstyle.
        Only a single process is made for all files
        to save resources.
        """
        log.debug('Processing %s files with %s', files, self.name)
        if 'config' not in self.options:
            msg = ("We could not run `checkstyle` you did not set "
                   "the `config` option to a valid checkstyle XML file.")
            return self.problems.add(IssueComment(msg))
        command = self.create_command(files)
        output = run_command(command, ignore_error=True)

        # Only one line is generally a config error. Replay the error
        # to the user.
        lines = output.strip().split('\n')
        if not lines[0].startswith('<'):
            msg = ("Running `checkstyle` failed with:\n"
                   "```\n"
                   "%s\n"
                   "```\n"
                   "Ensure your config file exists and is valid XML.")
            return self.problems.add(IssueComment(msg % (lines[0], )))

        # Remove the last line if it is not XML
        # Checkstyle outputs text after the XML if there are errors.
        if not lines[-1].strip().startswith('<'):
            lines = lines[0:-1]
        output = ''.join(lines)

        filename_converter = functools.partial(self._relativize_filename,
                                               files)
        process_checkstyle(self.problems, output, filename_converter)
Beispiel #5
0
    def process_files(self, files):
        """
        Run code checks with rubocop
        """
        log.debug('Processing %s files with %s', files, self.name)
        command = ['rubocop']
        if bundle_exists('rubocop'):
            command = ['bundle', 'exec', 'rubocop']
        command += ['--format', 'emacs']
        if self.options.get('display_cop_names', '').lower() == 'true':
            command += ['--display-cop-names']
        command += files
        output = run_command(
            command,
            split=True,
            ignore_error=True,
            include_errors=False
        )

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

        for line in output:
            filename, line, error = self._parse_line(line)
            self.problems.add(filename, line, error)
Beispiel #6
0
 def process_files(self, files):
     """
     Run code checks with sass-lint.
     Only a single process is made for all files
     to save resources.
     """
     log.debug('Processing %s files with %s', files, self.name)
     cmd = 'sass-lint'
     if npm_exists('sass-lint'):
         cmd = os.path.join(
             os.getcwd(),
             'node_modules',
             '.bin',
             'sass-lint')
     command = [cmd, '-f', 'checkstyle', '-v']
     command += files
     if self.options.get('ignore'):
         command += ['--ignore ', self.options.get('ignore')]
     if self.options.get('config'):
         command += ['--config', self.apply_base(self.options['config'])]
     output = run_command(
         command,
         ignore_error=True)
     filename_converter = functools.partial(
         self._relativize_filename,
         files)
     self._process_checkstyle(output, filename_converter)
Beispiel #7
0
    def process_files(self, files):
        """
        Run code checks with pylint --p3k.
        Only a single process is made for all files
        to save resources.
        """
        log.debug('Processing %s files with %s', files, self.name)
        command = ['pylint', '--py3k']
        for option in self.PYLINT3K_OPTIONS:
            if self.options.get(option):
                command.extend(
                    ['--%(option)s' % {'option': option},
                     self.options.get(option)])

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

        for line in output:
            if line.startswith("******"):
                continue
            filename, line, error = self._parse_line(line)
            self.problems.add(filename, line, error)
Beispiel #8
0
    def process_files(self, files):
        """
        Run code checks with puppet-lint
        """
        log.debug('Processing %s files with %s', files, self.name)
        command = ['puppet-lint']
        if bundle_exists('puppet-lint'):
            command = ['bundle', 'exec', 'puppet-lint']
        command += ['--log-format',
                    '%{path}:%{linenumber}:%{KIND}:%{message}']
        command += files
        output = run_command(
            command,
            split=True,
            ignore_error=True,
            include_errors=False
        )

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

        for line in output:
            filename, line, error = self._parse_line(line)
            self.problems.add(filename, line, error)
Beispiel #9
0
    def process_files(self, files):
        """
        Run code checks with phpcs.
        Only a single process is made for all files
        to save resources.
        """
        log.debug('Processing %s files with %s', files, self.name)
        command = self.create_command(files)
        output = run_command(
            command,
            ignore_error=True,
            include_errors=False)
        filename_converter = functools.partial(
            self._relativize_filename,
            files)

        # Check for errors from PHPCS
        if output.startswith('ERROR'):
            msg = ('Your PHPCS configuration output the following error:\n'
                   '```\n'
                   '{}\n'
                   '```')
            error = '\n'.join(output.split('\n')[0:1])
            return self.problems.add(IssueComment(msg.format(error)))
        process_checkstyle(self.problems, output, filename_converter)
Beispiel #10
0
    def process_files(self, files):
        """
        Run code checks with ESLint.
        """
        log.debug('Processing %s files with %s', files, self.name)
        cmd = self.name
        if npm_exists('eslint'):
            cmd = os.path.join(os.getcwd(), 'node_modules', '.bin', 'eslint')
        command = [cmd, '--format', 'checkstyle']

        # Add config file or default to recommended linters
        if self.options.get('config'):
            command += ['--config', self.apply_base(self.options['config'])]

        command += files
        output = run_command(command, ignore_error=True)

        if output.startswith('Cannot read config file'):
            msg = u'Your eslint config file is missing or invalid. ' \
                   u'Please ensure that `{}` exists and is valid.'
            msg = msg.format(self.options['config'])
            return self.problems.add(IssueComment(msg))

        filename_converter = functools.partial(self._relativize_filename,
                                               files)
        self._process_checkstyle(output, filename_converter)
Beispiel #11
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)
Beispiel #12
0
    def execute_commits(self, commits):
        """
        Check that HEAD commit has gpg signature
        """
        cmd = "git log HEAD^..HEAD --show-signature --format=%H | "
        cmd += "grep -q 'Signature made'"

        try:
            run_command(cmd, split=False, shell=True,
                        ignore_error=False, cwd=self.base_path)
            log.debug('Signature found in HEAD commit')
            return False
        except Exception as e:
            log.debug("Exception: %s" % str(e))
            body = 'No gpg signature for tip of the branch.'
            self.problems.add(IssueComment(body))
Beispiel #13
0
    def process_files(self, files):
        """
        Run code checks with swiftlit.
        """
        log.debug('Processing %s files with %s', files, self.name)

        command = [
            'swiftlint',
            'lint',
            '--quiet',
            '--reporter', 'checkstyle',
            '--use-script-input-files'
        ]

        # swiftlint uses a set of environment variables
        # to lint multiple files at once.
        env = os.environ.copy()
        for index, name in enumerate(files):
            env['SCRIPT_INPUT_FILE_%s' % (index,)] = name
        env['SCRIPT_INPUT_FILE_COUNT'] = str(len(files))

        output = run_command(
            command,
            env=env,
            cwd=self.base_path,
            ignore_error=True)

        filename_converter = functools.partial(
            self._relativize_filename,
            files)
        process_checkstyle(self.problems, output, filename_converter)
Beispiel #14
0
    def process_files(self, files):
        """
        Run code checks with gjslint.
        Only a single process is made for all files
        to save resources.
        """
        log.debug('Processing %s files with %s', files, self.name)
        command = self.create_command(files)
        output = run_command(
            command,
            split=True,
            ignore_error=True)

        if re.search(r'no errors found', output[0]):
            log.debug('No gjslint errors found.')
            return False

        """
        Lint Errors are reports as follows:
        ----- FILE  :  /private/tmp/workspace/repo/repo_name/pr_number/path/to/file.js -----
        Line 546, E:0007: Should have 2 blank lines between top-level blocks.
        Line 550, E:0210: Missing docs for parameter: "parameters"
        Line 550, E:0210: Missing docs for parameter: "url"
        Found 9 errors, including 1 new error, in 3 files (0 files OK).
        """
        filename = ''
        for line in output:
            if 'FILE' in line:
                filename = self._parse_filename(line)
            elif re.match(r'Found .* errors', line):
                break;
            else:
                line_number, error = self._parse_line(line)
                self.problems.add(filename, line_number, error)
Beispiel #15
0
    def process_files(self, files):
        """
        Run code smell checks with reek
        """
        log.debug('Processing %s files with %s', files, self.name)
        command = ['reek']
        if bundle_exists('reek'):
            command = ['bundle', 'exec', 'reek']
        command += ['--single-line','--no-color']
        command += files
        output = run_command(
            command,
            split=True,
            ignore_error=True,
            include_errors=False
        )

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

        for line in output:
            """
            Reek -s outputs warnings with leading spaces
            """
            if isinstance(line, basestring) and line.startswith(' '):
                filename, line, error = self._parse_line(line)
                self.problems.add(filename, line, error)
Beispiel #16
0
 def execute_fixer(self, files):
     """
     Run PHPCS in the fixer mode.
     """
     log.debug('Fixing %s files with %s', files, self.name)
     command = self.create_fixer_command(files)
     output = run_command(command, ignore_error=True, include_errors=False)
     log.error(output)
Beispiel #17
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)
Beispiel #18
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)
Beispiel #19
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)
Beispiel #20
0
 def process_files(self, files):
     """
     Run code checks with jscs.
     Only a single process is made for all files
     to save resources.
     """
     log.debug('Processing %s files with %s', files, self.name)
     command = self.create_command(files)
     output = run_command(command, ignore_error=True)
     process_checkstyle(self.problems, output, None)
Beispiel #21
0
 def process_files(self, files):
     """
     Run code checks with shellcheck.
     """
     log.debug('Processing %s files with %s', files, self.name)
     command = self.create_command(files)
     output = run_command(command, ignore_error=True, include_errors=False)
     filename_converter = functools.partial(self._relativize_filename,
                                            files)
     process_checkstyle(self.problems, output, filename_converter)
     list(map(self.escape_backtick, self.problems))
Beispiel #22
0
 def execute_fixer(self, files):
     """
     Run PHPCS in the fixer mode.
     """
     log.debug('Fixing %s files with %s', files, self.name)
     command = self.create_fixer_command(files)
     output = run_command(
         command,
         ignore_error=True,
         include_errors=False)
     log.error(output)
Beispiel #23
0
 def process_files(self, files):
     """
     Run code checks with phpcs.
     Only a single process is made for all files
     to save resources.
     """
     log.debug('Processing %s files with %s', files, self.name)
     command = self.create_command(files)
     output = run_command(command, ignore_error=True)
     filename_converter = functools.partial(self._get_filename, files)
     self._process_checkstyle(output, filename_converter)
Beispiel #24
0
 def process_files(self, files):
     """
     Run code checks with jshint.
     Only a single process is made for all files
     to save resources.
     """
     log.debug('Processing %s files with %s', files, self.name)
     command = self.create_command(files)
     output = run_command(
         command,
         ignore_error=True)
     self._process_checkstyle(output)
Beispiel #25
0
 def process_files(self, files):
     """
     Run code checks with phpcs.
     Only a single process is made for all files
     to save resources.
     """
     log.debug('Processing %s files with %s', files, self.name)
     command = self.create_command(files)
     output = run_command(
         command,
         ignore_error=True)
     filename_converter = functools.partial(self._get_filename, files)
     self._process_checkstyle(output, filename_converter)
Beispiel #26
0
    def process_files(self, files):
        """
        Run code checks with XO.
        """
        log.debug('Processing %s files with %s', files, self.name)
        cmd = self.name
        if npm_exists('xo'):
            cmd = os.path.join(os.getcwd(), 'node_modules', '.bin', 'xo')
        command = [cmd, '--reporter', 'checkstyle']

        command += files
        output = run_command(command, ignore_error=True)
        self._process_output(output, files)
Beispiel #27
0
    def process_files(self, files):
        """
        Run code checks with XO.
        """
        log.debug('Processing %s files with %s', files, self.name)
        cmd = self.name
        if npm_exists('xo'):
            cmd = os.path.join(os.getcwd(), 'node_modules', '.bin', 'xo')
        command = [cmd, '--reporter', 'checkstyle']

        command += files
        output = run_command(command, ignore_error=True)
        self._process_output(output, files)
Beispiel #28
0
 def process_files(self, files):
     """
     Run code checks with shellcheck.
     """
     log.debug('Processing %s files with %s', files, self.name)
     command = self.create_command(files)
     output = run_command(
         command,
         ignore_error=True,
         include_errors=False)
     filename_converter = functools.partial(
         self._relativize_filename,
         files)
     self._process_checkstyle(output, filename_converter)
Beispiel #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)
        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)
Beispiel #30
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)
Beispiel #31
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)
     # Look for multi-package error message
     if len(output) == 1 and 'is in package' in output[0]:
         self.add_review_issue(output[0], files)
     else:
         filename_converter = functools.partial(self._relativize_filename,
                                                files)
         process_quickfix(self.problems, output, filename_converter)
Beispiel #32
0
 def process_files(self, files):
     """
     Run code checks with ESLint.
     """
     log.debug('Processing %s files with %s', files, self.name)
     cmd = self.name
     if npm_exists('eslint'):
         cmd = os.path.join(os.getcwd(), 'node_modules', '.bin', 'eslint')
     command = [cmd, '--format', 'checkstyle']
     # Add config file if it's present
     if self.options.get('config'):
         command += ['--config', self.apply_base(self.options['config'])]
     command += files
     output = run_command(command, ignore_error=True)
     self._process_checkstyle(output)
Beispiel #33
0
    def process_files(self, files):
        command = ['foodcritic']
        if bundle_exists('foodcritic'):
            command = ['bundle', 'exec', 'foodcritic']
        # if no directory is set, assume the root
        path = os.path.join(self.base_path, self.options.get('path', ''))
        command += [path]
        output = run_command(command, split=True, ignore_error=False)

        if output[0] == '\n':
            log.debug('No foodcritic errors found.')
            return False

        for line in output:
            filename, line, error = self._parse_line(line)
            self.problems.add(filename, line, error)
Beispiel #34
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)
Beispiel #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)
Beispiel #36
0
    def process_files(self, files):
        """
        Run code checks with csslint.
        Only a single process is made for all files
        to save resources.
        """
        log.debug('Processing %s files with %s', files, self.name)
        cmd = 'csslint'
        if npm_exists('csslint'):
            cmd = os.path.join(os.getcwd(), 'node_modules', '.bin', 'csslint')
        command = [cmd, '--format=checkstyle-xml']

        if self.options.get('ignore'):
            command += ['--ignore=' + self.options.get('ignore')]
        command += files
        output = run_command(command, ignore_error=True)
        self._process_checkstyle(output)
Beispiel #37
0
    def process_files(self, files):
        command = ['foodcritic']
        if bundle_exists('foodcritic'):
            command = ['bundle', 'exec', 'foodcritic']
        command.append('--no-progress')
        # if no directory is set, assume the root
        path = os.path.join(self.base_path, self.options.get('path', ''))
        command += [path]
        output = run_command(command, split=True, ignore_error=True)

        if output[0] == '\n':
            log.debug('No foodcritic errors found.')
            return False

        for line in output:
            filename, line, error = self._parse_line(line)
            self.problems.add(filename, line, error)
Beispiel #38
0
 def process_files(self, files):
     """
     Run code checks with ESLint.
     """
     log.debug('Processing %s files with %s', files, self.name)
     cmd = self.name
     if npm_exists('eslint'):
         cmd = os.path.join(os.getcwd(), 'node_modules', '.bin', 'eslint')
     command = [cmd, '--format', 'checkstyle']
     # Add config file if it's present
     if self.options.get('config'):
         command += ['--config', self.apply_base(self.options['config'])]
     command += files
     output = run_command(
         command,
         ignore_error=True)
     self._process_checkstyle(output)
Beispiel #39
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)
Beispiel #40
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

        for line in output:
            filename, line, error = self._parse_line(line)
            self.problems.add(filename, line, error)
Beispiel #41
0
    def process_files(self, files):
        """
        Run code checks with csslint.
        Only a single process is made for all files
        to save resources.
        """
        log.debug('Processing %s files with %s', files, self.name)
        cmd = 'csslint'
        if npm_exists('csslint'):
            cmd = os.path.join(os.getcwd(), 'node_modules', '.bin', 'csslint')
        command = [cmd, '--format=checkstyle-xml']

        if self.options.get('ignore'):
            command += ['--ignore=' + self.options.get('ignore')]
        command += files
        output = run_command(
            command,
            ignore_error=True)
        self._process_checkstyle(output)
Beispiel #42
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']
        command += files

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

        for line in output:
            filename, line, error = self._parse_line(line)
            self.problems.add(filename, line, error)
Beispiel #43
0
    def process_files(self, files):
        """
        Run code checks with rubocop
        """
        log.debug('Processing %s files with %s', files, self.name)
        command = ['rubocop', '--format', 'emacs']
        command += files
        output = run_command(
            command,
            split=True,
            ignore_error=True,
            include_errors=False
        )

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

        for line in output:
            filename, line, error = self._parse_line(line)
            self.problems.add(filename, line, error)
Beispiel #44
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)
Beispiel #45
0
    def process_files(self, files):
        """
        Run code checks with phpcs.
        Only a single process is made for all files
        to save resources.
        """
        log.debug('Processing %s files with %s', files, self.name)
        command = self.create_command(files)
        output = run_command(command, ignore_error=True, include_errors=False)
        filename_converter = functools.partial(self._relativize_filename,
                                               files)

        # Check for errors from PHPCS
        if output.startswith('ERROR'):
            msg = ('Your PHPCS configuration output the following error:\n'
                   '```\n'
                   '{}\n'
                   '```')
            error = '\n'.join(output.split('\n')[0:1])
            return self.problems.add(IssueComment(msg.format(error)))
        process_checkstyle(self.problems, output, filename_converter)
Beispiel #46
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)
Beispiel #47
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", files, self.name)
        command = ["flake8"]
        for option in self.PYFLAKE_OPTIONS:
            if self.options.get(option):
                command.extend(["--%(option)s" % {"option": option}, self.options.get(option)])

        command += files
        output = run_command(command, split=True, ignore_error=True)
        if not output:
            log.debug("No flake8 errors found.")
            return False

        for line in output:
            filename, line, error = self._parse_line(line)
            self.problems.add(filename, line, error)
Beispiel #48
0
    def process_files(self, files):
        """
        Run code checks with puppet-lint
        """
        log.debug('Processing %s files with %s', files, self.name)
        command = ['puppet-lint']
        if bundle_exists('puppet-lint'):
            command = ['bundle', 'exec', 'puppet-lint']
        command += ['--log-format', '%{path}:%{linenumber}:%{KIND}:%{message}']
        command += files
        output = run_command(command,
                             split=True,
                             ignore_error=True,
                             include_errors=False)

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

        for line in output:
            filename, line, error = self._parse_line(line)
            self.problems.add(filename, line, error)
Beispiel #49
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)
Beispiel #50
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 = ['flake8']
        for option in self.options:
            if option in self.PYFLAKE_OPTIONS:
                command.extend(
                    ['--%s' % option, self.options.get(option)])
            else:
                log.warning('Set non-existent flake8 option: %s', option)

        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)
Beispiel #51
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)
Beispiel #52
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 = run_command(command, split=True, ignore_error=True)
        if not output:
            log.debug('No jsonlint errors found.')
            return False

        for line in output:
            if (line[0] == ' ' or line.find(': has errors') >= 0
                    or line.find(': ok') >= 0):
                continue
            filename, line, error = self._parse_line(line)
            self.problems.add(filename, line, error)
Beispiel #53
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)
Beispiel #54
0
    def process_files(self, files):
        """
        Run code checks with checkstyle.
        Only a single process is made for all files
        to save resources.
        """
        log.debug('Processing %s files with %s', files, self.name)
        if 'config' not in self.options:
            msg = ("We could not run `checkstyle` you did not set "
                   "the `config` option to a valid checkstyle XML file.")
            return self.problems.add(IssueComment(msg))
        command = self.create_command(files)
        output = run_command(
            command,
            ignore_error=True)

        # Only one line is generally a config error. Replay the error
        # to the user.
        lines = output.strip().split('\n')
        if not lines[0].startswith('<'):
            msg = ("Running `checkstyle` failed with:\n"
                   "```\n"
                   "%s\n"
                   "```\n"
                   "Ensure your config file exists and is valid XML.")
            return self.problems.add(IssueComment(msg % (lines[0],)))

        # Remove the last line if it is not XML
        # Checkstyle outputs text after the XML if there are errors.
        if not lines[-1].strip().startswith('<'):
            lines = lines[0:-1]
        output = ''.join(lines)

        filename_converter = functools.partial(
            self._relativize_filename,
            files)
        process_checkstyle(self.problems, output, filename_converter)