Esempio n. 1
0
 def create_command(self, properties_filename, files):
     command = [
         'checkstyle', '-f', 'xml', '-p',
         docker.apply_base(properties_filename), '-c',
         docker.apply_base(self.options['config'])
     ]
     command += files
     return command
Esempio n. 2
0
 def create_command(self, properties_filename, files):
     command = [
         'checkstyle',
         '-f', 'xml',
         '-p', docker.apply_base(properties_filename),
         '-c', docker.apply_base(self.options['config'])
     ]
     command += files
     return command
Esempio n. 3
0
    def setup_properties(self, properties_file):
        config_loc = os.path.dirname(docker.apply_base(self.options['config']))
        project_loc = docker.apply_base('/')

        properties = {
            'config_loc': config_loc,
            'samedir': config_loc,
            'project_loc': project_loc,
            'basedir': project_loc,
        }

        jprops.store_properties(properties_file, properties)
Esempio n. 4
0
    def setup_properties(self, properties_file):
        config_loc = os.path.dirname(docker.apply_base(self.options['config']))
        project_loc = docker.apply_base('/')

        properties = {
            'config_loc': config_loc,
            'samedir': config_loc,
            'project_loc': project_loc,
            'basedir': project_loc,
        }

        jprops.store_properties(properties_file, properties)
Esempio n. 5
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)
Esempio n. 6
0
    def process_files(self, files):
        """
        Run code checks with pep8.
        Only a single process is made for all files
        to save resources.
        """
        command = self.create_command()
        command += map(lambda f: docker.apply_base(f), files)

        output = docker.run('nodejs', command, source_dir=self.base_path)
        if not output:
            return False
        output = output.split("\n")
        filename = None
        # The output from remarklint is a unique format that looks like:
        #
        # >>> file.md
        # >>>   1:1-1:8 warning Some warning
        #
        # We inspect each line to determine if it is a file or warning.
        for line in output:
            if filename_pattern.match(line):
                # Remove the base path as remarklint is fed absolute paths.
                filename = docker.strip_base(line)
            else:
                match = warning_pattern.match(line)
                if match:
                    line = match.group('line')
                    text = match.group('text')
                    self.problems.add(filename, line, text)
Esempio n. 7
0
 def create_command(self, files):
     command = ['jshint', '--checkstyle-reporter']
     # Add config file if its present
     if self.options.get('config'):
         command += ['--config', docker.apply_base(self.options['config'])]
     command += files
     return command
Esempio n. 8
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 = self.create_command()
        command += map(lambda f: docker.apply_base(f), files)

        output = docker.run('nodejs', command, source_dir=self.base_path)
        if not output:
            return False
        output = output.split("\n")
        filename = None
        # The output from remarklint is a unique format that looks like:
        #
        # >>> file.md
        # >>>   1:1-1:8 warning Some warning
        #
        # We inspect each line to determine if it is a file or warning.
        for line in output:
            if filename_pattern.match(line):
                # Remove the base path as remarklint is fed absolute paths.
                filename = docker.strip_base(line)
            else:
                match = warning_pattern.match(line)
                if match:
                    line = match.group('line')
                    text = match.group('text')
                    self.problems.add(filename, line, text)
Esempio n. 9
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)
Esempio n. 10
0
 def _apply_options(self, command):
     if 'config' in self.options:
         command.extend(
             ['--config',
              docker.apply_base(self.options['config'])])
     command.extend(['-o', '/tmp/pytype'])
     return command
Esempio n. 11
0
 def create_command(self, files):
     command = [
         'checkstyle', '-f', 'xml', '-c',
         docker.apply_base(self.options['config'])
     ]
     command += files
     return command
Esempio n. 12
0
    def _create_command(self):
        command = ['eslint', '--format', 'checkstyle']

        # Add config file or default to recommended linters
        if self.options.get('config'):
            command += ['--config', docker.apply_base(self.options['config'])]
        return command
Esempio n. 13
0
 def create_command(self, files):
     command = ['jshint', '--checkstyle-reporter']
     # Add config file if its present
     if self.options.get('config'):
         command += ['--config',
                     docker.apply_base(self.options['config'])]
     command += files
     return command
Esempio n. 14
0
 def create_command(self, files):
     command = ['luacheck']
     command += ['--formatter=plain']
     command += ['--codes']
     if self.options.get('config'):
         command += ['--config', docker.apply_base(self.options['config'])]
     command += files
     return command
Esempio n. 15
0
 def create_command(self):
     command = ['black']
     if 'py36' in self.options:
         command.append('--py36')
     if 'config' in self.options:
         command.extend(['--config',
                         docker.apply_base(self.options['config'])])
     return command
Esempio n. 16
0
 def apply_base(self, path):
     """
     PHPCS supports either standard names, or paths
     to standard files. Assume no os.sep implies a built-in standard name
     """
     if os.sep not in path:
         return path
     return docker.apply_base(path)
Esempio n. 17
0
 def apply_base(self, path):
     """
     PHPCS supports either standard names, or paths
     to standard files. Assume no os.sep implies a built-in standard name
     """
     if os.sep not in path:
         return path
     return docker.apply_base(path)
Esempio n. 18
0
 def create_command(self, files):
     command = ['luacheck']
     command += ['--formatter=plain']
     command += ['--codes']
     if self.options.get('config'):
         command += ['--config', docker.apply_base(self.options['config'])]
     command += files
     return command
Esempio n. 19
0
    def _create_command(self):
        command = ['eslint', '--format', 'checkstyle']

        # Add config file or default to recommended linters
        if self.options.get('config'):
            command += ['--config',
                        docker.apply_base(self.options['config'])]
        return command
Esempio n. 20
0
 def create_command(self, files):
     command = ['jscs', '--reporter=checkstyle']
     # Add config file if its present
     if self.options.get('config'):
         command += ['--config', docker.apply_base(self.options['config'])]
     else:
         command += ['--preset', self.options.get('preset', 'google')]
     command += files
     return command
Esempio n. 21
0
 def create_command(self):
     command = ['black']
     if 'py36' in self.options:
         command.append('--py36')
     if 'config' in self.options:
         command.extend(
             ['--config',
              docker.apply_base(self.options['config'])])
     return command
Esempio n. 22
0
    def process_files(self, files):
        """
        Run code checks with TSLint.
        """
        log.debug('Processing %s files with %s', files, self.name)
        command = ['tslint', '--format', 'checkstyle']

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

        command += files
        output = docker.run('nodejs', command, source_dir=self.base_path)
        self._process_output(output, files)
Esempio n. 23
0
 def _create_command(self):
     command = ['goodcheck', 'check', '--format', 'json']
     if self.options.get('rules'):
         for rule in self.options['rules'].split(','):
             command.extend(['-R', rule.strip()])
     if self.options.get('config'):
         command.extend(
             ['--config',
              docker.apply_base(self.options['config'])])
     return command
Esempio n. 24
0
    def _create_command(self):
        command = [
            'stylelint',
            '--formatter',
            'unix',
            '--config-basedir',
            '/tool',
        ]

        if self.options.get('config'):
            command += ['--config', docker.apply_base(self.options['config'])]
        return command
Esempio n. 25
0
    def process_files(self, files):
        """
        Run code checks with TSLint.
        """
        log.debug('Processing %s files with %s', files, self.name)
        command = ['tslint', '--format', 'checkstyle']

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

        command += files
        output = docker.run(
            'nodejs',
            command,
            source_dir=self.base_path)
        self._process_output(output, files)
Esempio n. 26
0
def test_apply_base():
    eq_('/src', docker.apply_base(''))
    eq_('/src', docker.apply_base('/'))
    eq_('/src/thing.py', docker.apply_base('thing.py'))
    eq_('/src/some/thing.py', docker.apply_base('some/thing.py'))
    eq_('thing.py', docker.apply_base('/some/thing.py'))
    eq_('thing.py', docker.apply_base('/some/../../thing.py'))
Esempio n. 27
0
    def _create_command(self):
        command = [
            'stylelint',
            '--formatter', 'unix',
            '--config-basedir', '/tool',
        ]

        if self.options.get('config'):
            command += [
                '--config',
                docker.apply_base(self.options['config'])
            ]
        return command
Esempio n. 28
0
 def test_apply_base(self):
     self.assertEqual('/src', docker.apply_base(''))
     self.assertEqual('/src', docker.apply_base('/'))
     self.assertEqual('/src/thing.py', docker.apply_base('thing.py'))
     self.assertEqual('/src/some/thing.py',
                      docker.apply_base('some/thing.py'))
     self.assertEqual('thing.py', docker.apply_base('/some/thing.py'))
     self.assertEqual('thing.py', docker.apply_base('/some/../../thing.py'))
Esempio n. 29
0
 def test_apply_base(self):
     self.assertEqual('/src', docker.apply_base(''))
     self.assertEqual('/src', docker.apply_base('/'))
     self.assertEqual('/src/thing.py', docker.apply_base('thing.py'))
     self.assertEqual('/src/some/thing.py',
                      docker.apply_base('some/thing.py'))
     self.assertEqual('thing.py', docker.apply_base('/some/thing.py'))
     self.assertEqual('thing.py', docker.apply_base('/some/../../thing.py'))
Esempio n. 30
0
    def make_command(self, files):
        command = ['flake8']
        if 'config' in self.options:
            self.options['config'] = docker.apply_base(self.options['config'])

        for option in self.options:
            if option in self.PYFLAKE_OPTIONS:
                command.extend(['--%s' % option, self.options.get(option)])
        if 'config' in self.options:
            command.extend(['--format', 'default'])
        else:
            command.append('--isolated')
        command += files
        return command
Esempio n. 31
0
def run_fixers(tools, base_path, files):
    """Run fixer mode of each tool on each file
    Return a DiffCollection based on the parsed diff
    from the fixer changes.

    If no diff is generated an empty list will be returned"""
    log.info('Running fixers on %d files', len(files))

    docker_files = [docker.apply_base(f) for f in files]
    for tool in tools:
        if tool.has_fixer():
            tool.execute_fixer(docker_files)
    diff = git.diff(base_path, files)
    if diff:
        return parse_diff(diff)
    return []
Esempio n. 32
0
def run_fixers(tools, base_path, files):
    """Run fixer mode of each tool on each file
    Return a DiffCollection based on the parsed diff
    from the fixer changes.

    If no diff is generated an empty list will be returned"""
    log.info('Running fixers on %d files', len(files))

    docker_files = [docker.apply_base(f) for f in files]
    for tool in tools:
        if tool.has_fixer():
            tool.execute_fixer(docker_files)
    diff = git.diff(base_path, files)
    if diff:
        return parse_diff(diff)
    return []
Esempio n. 33
0
 def process_files(self, files):
     """
     Run code checks with sass-lint.
     Only a single process is made for all files
     to save resources.
     """
     command = ['sass-lint', '-f', 'checkstyle', '-v', '-q']
     command += files
     if self.options.get('ignore'):
         command += ['--ignore ', self.options.get('ignore')]
     if self.options.get('config'):
         command += ['--config', docker.apply_base(self.options['config'])]
     output = docker.run('nodejs', command, source_dir=self.base_path)
     # sass-lint is very silly and outputs multiple xml documents.
     # One for each file...
     for line in output.split("\n"):
         process_checkstyle(self.problems, line, docker.strip_base)
Esempio n. 34
0
    def make_command(self, files):
        command = ['flake8']
        if 'config' in self.options:
            self.options['config'] = docker.apply_base(self.options['config'])

        for option in self.options:
            if option in self.PYFLAKE_OPTIONS:
                command.extend([
                    '--%s' % option,
                    self.options.get(option)
                ])
        if 'config' in self.options:
            command.extend(['--format', 'default'])
        else:
            command.append('--isolated')
        command += files
        return command
Esempio n. 35
0
def run(lint_tools, files, commits):
    """
    Create and run tools.

    Uses the ReviewConfig, problemset, and list of files to iteratively
    run each tool across the various files in a pull request.

    file paths are converted into docker paths as all
    tools run in docker containers.
    """
    files = [docker.apply_base(f) for f in files]

    log.info('Running lint tools on %d files', len(files))
    for tool in lint_tools:
        log.debug('Runnning %s', tool)
        tool.execute(files)
        tool.execute_commits(commits)
Esempio n. 36
0
    def process_files(self, files):
        command = ['foodcritic', '--no-progress']

        # if no directory is set, assume the root
        path = self.options.get('path', '')
        path = docker.apply_base(path)

        command.append(path)
        output = docker.run('ruby2', command, self.base_path)

        if output[0] == '\n':
            return False

        for line in output.split("\n"):
            if len(line.strip()) == 0:
                return
            filename, line, error = self._parse_line(line)
            self.problems.add(filename, line, error)
Esempio n. 37
0
    def process_files(self, files):
        command = ['foodcritic', '--no-progress']

        # if no directory is set, assume the root
        path = self.options.get('path', '')
        path = docker.apply_base(path)

        command.append(path)
        output = docker.run('ruby2', command, self.base_path)

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

        for line in output.split("\n"):
            if len(line.strip()) == 0:
                return
            filename, line, error = self._parse_line(line)
            self.problems.add(filename, line, error)
Esempio n. 38
0
    def make_command(self, files):
        command = ['flake8']
        if 'config' in self.options:
            self.options['config'] = docker.apply_base(self.options['config'])

        if self.options.get('isort', None):
            plugins = self.options.get('plugins', [])
            if isinstance(plugins, list):
                plugins.append('flake8-isort')
                self.options['plugins'] = plugins

        for option in self.options:
            if option in self.PYFLAKE_OPTIONS:
                command.extend(['--%s' % option, self.options.get(option)])
        if 'config' in self.options:
            command.extend(['--format', 'default'])
        else:
            command.append('--isolated')
        command += files
        return command
Esempio n. 39
0
def run(lint_tools, files, commits):
    """
    Create and run tools.

    Uses the ReviewConfig, problemset, and list of files to iteratively
    run each tool across the various files in a pull request.

    file paths are converted into docker paths as all
    tools run in docker containers.
    """
    files = [docker.apply_base(f) for f in files]

    log.info('Running for %d files', len(files))
    for tool in lint_tools:
        previous_total = len(tool.problems)
        if tool.version:
            buildlog.info('%s version is: %s', tool.name, tool.version)
        tool.execute(files)
        tool.execute_commits(commits)
        buildlog.info('%s added %s review notes', tool.name, len(tool.problems) - previous_total)
Esempio n. 40
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

        output = output.split("\n")
        process_quickfix(self.problems, output, docker.strip_base)
Esempio n. 41
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)
     command = ['sass-lint', '-f', 'checkstyle', '-v', '-q']
     command += files
     if self.options.get('ignore'):
         command += ['--ignore ', self.options.get('ignore')]
     if self.options.get('config'):
         command += ['--config',
                     docker.apply_base(self.options['config'])]
     output = docker.run(
         'nodejs',
         command,
         source_dir=self.base_path)
     # sass-lint is very silly and outputs multiple xml documents.
     # One for each file...
     for line in output.split("\n"):
         process_checkstyle(self.problems, line, docker.strip_base)
Esempio n. 42
0
 def _apply_options(self, command):
     if 'config' in self.options:
         command.extend(['--config', docker.apply_base(self.options['config'])])
     command.extend(['-o', '/tmp/pytype'])
     return command
Esempio n. 43
0
 def create_fixer_command(self, files):
     command = self.create_command()
     command += map(lambda f: docker.apply_base(f), files)
     command.append('-o')
     return command
Esempio n. 44
0
 def create_fixer_command(self, files):
     command = self.create_command()
     command += map(lambda f: docker.apply_base(f), files)
     command.append('-o')
     return command