예제 #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
예제 #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
예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #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
예제 #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)
예제 #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)
예제 #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
예제 #11
0
 def create_command(self, files):
     command = [
         'checkstyle', '-f', 'xml', '-c',
         docker.apply_base(self.options['config'])
     ]
     command += files
     return command
예제 #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
예제 #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
예제 #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
예제 #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
예제 #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)
예제 #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)
예제 #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
예제 #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
예제 #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
예제 #21
0
파일: black.py 프로젝트: jpos15/lint-review
 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
예제 #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)
예제 #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
예제 #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
예제 #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)
예제 #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'))
예제 #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
예제 #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'))
예제 #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'))
예제 #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
예제 #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 []
예제 #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 []
예제 #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)
예제 #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
예제 #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)
예제 #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)
예제 #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)
예제 #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
예제 #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)
예제 #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)
예제 #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)
예제 #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
예제 #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
예제 #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