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
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
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)
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)
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)
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)
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
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)
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)
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
def create_command(self, files): command = [ 'checkstyle', '-f', 'xml', '-c', docker.apply_base(self.options['config']) ] command += files return command
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
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
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
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
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)
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)
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
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
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
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
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)
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
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
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)
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'))
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
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'))
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'))
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
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 []
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 []
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)
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
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)
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)
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)
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
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)
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)
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)
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
def create_fixer_command(self, files): command = self.create_command() command += map(lambda f: docker.apply_base(f), files) command.append('-o') return command
def create_fixer_command(self, files): command = self.create_command() command += map(lambda f: docker.apply_base(f), files) command.append('-o') return command