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) process_checkstyle(self.problems, output, filename_converter)
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)
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 = docker.run('checkstyle', command, self.base_path) # 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) process_checkstyle(self.problems, output, docker.strip_base)
def _process_output(self, output, files): missing_ruleset = 'Could not find implementations' if missing_ruleset in output: msg = u'Your tslint configuration output the following error:\n' \ '```\n' \ '{}\n' \ '```' # When tslint fails the error message is trailed by # multiple newlines with some bonus space. Use that to segment # out the error error = re.split(r'\n\s*\n', output)[0] return self.problems.add(IssueComment(msg.format(error.strip()))) if (output.startswith('No valid rules') or not output.startswith('<?xml')): msg = u'Your tslint config file is missing or invalid. ' \ u'Please ensure that `{}` exists and is valid JSON.' config = self.options.get('config', 'tslint.json') msg = msg.format(config) return self.problems.add(IssueComment(msg)) filename_converter = functools.partial( self._relativize_filename, files) process_checkstyle(self.problems, output, filename_converter)
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)
def _process_output(self, output, files): if '<?xml' not in output: return self._config_error(output) filename_converter = functools.partial(self._relativize_filename, files) process_checkstyle(self.problems, output, filename_converter)
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)
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 = {} for index, name in enumerate(files): env['SCRIPT_INPUT_FILE_%s' % (index,)] = name env['SCRIPT_INPUT_FILE_COUNT'] = str(len(files)) output = docker.run( 'swiftlint', command, self.base_path, env=env) process_checkstyle(self.problems, output, docker.strip_base)
def _process_output(self, output, files): if '<?xml' not in output: return self._config_error(output) filename_converter = functools.partial( self._relativize_filename, files) process_checkstyle(self.problems, output, filename_converter)
def process_files(self, files): """ Run code checks with shellcheck. """ command = self.create_command(files) output = docker.run('shellcheck', command, self.base_path) process_checkstyle(self.problems, output, docker.strip_base) list(map(self.escape_backtick, self.problems))
def _process_output(self, output, files): # Strip deprecations off as they break XML parsing if re.match(r'.*?DeprecationWarning', output): output = self._handle_deprecation_warning(output) if not output.strip().startswith('<?xml'): return self._config_error(output) process_checkstyle(self.problems, output, docker.strip_base)
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 = docker.run('shellcheck', command, self.base_path) process_checkstyle(self.problems, output, docker.strip_base) list(map(self.escape_backtick, self.problems))
def process_files(self, files): """ Run code checks with jshint. Only a single process is made for all files to save resources. """ command = self.create_command(files) output = docker.run('nodejs', command, source_dir=self.base_path) process_checkstyle(self.problems, output, False)
def process_files(self, files): """ Run code checks with ktlint. """ command = self._create_command() command += files output = docker.run('ktlint', command, self.base_path) process_checkstyle(self.problems, output, docker.strip_base)
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)
def process_files(self, files): """ Run code checks with XO. """ log.debug('Processing %s files with %s', files, self.name) command = ['xo', '--reporter', 'checkstyle'] command += files output = docker.run('nodejs', command, source_dir=self.base_path) process_checkstyle(self.problems, output, docker.strip_base)
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 = docker.run('nodejs', command, source_dir=self.base_path) process_checkstyle(self.problems, output, None)
def _process_output(self, output, files): # Strip deprecations off as they break XML parsing if re.match(r'.*?DeprecationWarning', output): log.warning( "Received deprecation warning from eslint which should not happen in eslint7." ) output = self._handle_deprecation_warning(output) if not output.strip().startswith('<?xml'): return self._config_error(output) process_checkstyle(self.problems, output, docker.strip_base)
def test_process_checkstyle__non_int(): problems = Problems() xml = """ <checkstyle> <file name="other_things.py"> <error line="undefined" message="Not good" /> </file> </checkstyle> """ tools.process_checkstyle(problems, xml, lambda x: x) eq_(0, len(problems))
def test_process_checkstyle__non_int(self): problems = Problems() xml = """ <checkstyle> <file name="other_things.py"> <error line="undefined" message="Not good" /> </file> </checkstyle> """ tools.process_checkstyle(problems, xml, lambda x: x) self.assertEqual(0, len(problems))
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))
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) process_checkstyle(self.problems, output, False)
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 = docker.run( 'nodejs', command, source_dir=self.base_path) process_checkstyle(self.problems, output, False)
def _process_output(self, output, files): missing_ruleset = 'Could not find implementations' if missing_ruleset in output: msg = u'Your tslint configuration output the following error:\n' \ '```\n' \ '{}\n' \ '```' # When tslint fails the error message is trailed by # multiple newlines with some bonus space. Use that to segment # out the error error = re.split(r'\n\s*\n', output)[0] return self.problems.add(IssueComment(msg.format(error.strip()))) missing_module = re.search(r'Failed to load .*?: Invalid.*', output) if missing_module: msg = (u'Your tslint configuration output the following error:\n' '```\n' '{}\n' '```') error = missing_module.group(0) return self.problems.add(IssueComment(msg.format(error))) # tslint outputs warnings when rule constraints are violated if output.startswith('Warning'): lines = output.split('\n') warnings = [] xml = [] for line in lines: if line.startswith('Warning'): warnings.append('* ' + line[9:]) else: xml.append(line) # Recreate the xml output without warnings output = '\n'.join(xml) msg = u'`tslint` output the following warnings:\n\n{}' warning_bullets = '\n'.join(warnings) self.problems.add(IssueComment(msg.format(warning_bullets))) if (output.startswith('No valid rules') or not output.startswith('<?xml')): msg = u'Your tslint configuration file is missing or invalid. ' \ u'Please ensure that `{}` exists and is valid JSON.' config = self.options.get('config', 'tslint.json') msg = msg.format(config) return self.problems.add(IssueComment(msg)) process_checkstyle(self.problems, output, docker.strip_base)
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)) props_path = os.path.join(self.base_path, '_lintreview.properties') # Close the file before trying to read. # There have been problems with reading properties while # the file handle is still open. with open(props_path, 'w+') as f: self.setup_properties(f) properties_filename = os.path.basename(f.name) command = self.create_command(properties_filename, files) output = docker.run('checkstyle', command, self.base_path) # Cleanup the generated properties file. os.remove(props_path) # Only one line is generally a config error. Replay the error # to the user. lines = output.strip().split('\n') # Checkstyle >=8.28 outputs non-xml summary data at the beginning. if lines[0].startswith('Checkstyle ends with'): lines = lines[1:] 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 may output text after the XML if there are errors. if not lines[-1].strip().startswith('<'): lines = lines[0:-1] output = ''.join(lines) process_checkstyle(self.problems, output, docker.strip_base)
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) map(self.escape_backtick, self.problems)
def test_process_undefined(self): problems = Problems() xml = """ <checkstyle> <file name="other_things.py"> <error line="undefined" message="Not good" /> </file> </checkstyle> """ tools.process_checkstyle(problems, xml, lambda x: x) self.assertEqual(1, len(problems)) errors = problems.all('other_things.py') assert len(errors) == 1, errors assert errors[0].line == Comment.FIRST_LINE_IN_DIFF assert errors[0].body == 'Not good'
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 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)) props_path = os.path.join(self.base_path, '_lintreview.properties') # Close the file before trying to read. # There have been problems with reading properties while # the file handle is still open. with open(props_path, 'w+') as f: self.setup_properties(f) properties_filename = os.path.basename(f.name) command = self.create_command(properties_filename, files) output = docker.run('checkstyle', command, self.base_path) # Cleanup the generated properties file. os.remove(props_path) # 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) process_checkstyle(self.problems, output, docker.strip_base)
def _process_output(self, output, files): 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)) missing_ruleset = 'Cannot find module' if missing_ruleset in output: msg = u'Your eslint configuration output the following error:\n' \ '```\n' \ '{}\n' \ '```' error = '\n'.join(output.split('\n')[0:2]) return self.problems.add(IssueComment(msg.format(error))) filename_converter = functools.partial(self._relativize_filename, files) process_checkstyle(self.problems, output, filename_converter)
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 = docker.run('phpcs', command, source_dir=self.base_path) # 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, docker.strip_base)
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' command = [cmd, '--format=checkstyle-xml'] if self.options.get('ignore'): command += ['--ignore=' + self.options.get('ignore')] command += files output = docker.run( 'nodejs', command, source_dir=self.base_path) process_checkstyle(self.problems, output, docker.strip_base)
def test_process_checkstyle(self): problems = Problems() xml = """ <checkstyle> <file name="things.py"> <error line="1" message="Not good" /> <error line="2" message="Also not good" /> </file> <file name="other_things.py"> <error line="3" message="Not good" /> </file> </checkstyle> """ tools.process_checkstyle(problems, xml, lambda x: x) self.assertEqual(3, len(problems)) things = problems.all('things.py') self.assertEqual(2, len(things)) self.assertEqual(1, things[0].line) self.assertEqual('Not good', things[0].body)
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 = {} for index, name in enumerate(files): env['SCRIPT_INPUT_FILE_%s' % (index, )] = name env['SCRIPT_INPUT_FILE_COUNT'] = str(len(files)) output = docker.run('swiftlint', command, self.base_path, env=env) process_checkstyle(self.problems, output, docker.strip_base)
def _process_output(self, output, files): 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)) missing_ruleset = 'Cannot find module' if missing_ruleset in output: msg = u'Your eslint configuration output the following error:\n' \ '```\n' \ '{}\n' \ '```' error = '\n'.join(output.split('\n')[0:2]) return self.problems.add(IssueComment(msg.format(error))) filename_converter = functools.partial( self._relativize_filename, files) process_checkstyle(self.problems, output, filename_converter)
def test_process_checkstyle(): problems = Problems() xml = """ <checkstyle> <file name="things.py"> <error line="1" message="Not good" /> <error line="2" message="Also not good" /> </file> <file name="other_things.py"> <error line="3" message="Not good" /> </file> </checkstyle> """ tools.process_checkstyle(problems, xml, lambda x: x) eq_(3, len(problems)) things = problems.all('things.py') eq_(2, len(things)) eq_(1, things[0].line) eq_('Not good', things[0].body)
def process_files(self, files): """ Run code checks with swiftlit. """ command = [ 'swiftlint', 'lint', '--quiet', '--reporter', 'checkstyle', '--use-script-input-files' ] # swiftlint uses a set of environment variables # to lint multiple files at once. env = {} for index, name in enumerate(files): env['SCRIPT_INPUT_FILE_%s' % (index, )] = name env['SCRIPT_INPUT_FILE_COUNT'] = str(len(files)) output = docker.run('swiftlint', command, self.base_path, env=env) if not output.strip().startswith('<?xml'): output = self._process_warnings(output) process_checkstyle(self.problems, output, docker.strip_base)
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)
def _process_output(self, output, files): missing_ruleset = 'Could not find implementations' if missing_ruleset in output: msg = u'Your tslint configuration output the following error:\n' \ '```\n' \ '{}\n' \ '```' # When tslint fails the error message is trailed by # multiple newlines with some bonus space. Use that to segment # out the error error = re.split(r'\n\s*\n', output)[0] return self.problems.add(IssueComment(msg.format(error.strip()))) if (output.startswith('No valid rules') or not output.startswith('<?xml')): msg = u'Your tslint config file is missing or invalid. ' \ u'Please ensure that `{}` exists and is valid JSON.' config = self.options.get('config', 'tslint.json') msg = msg.format(config) return self.problems.add(IssueComment(msg)) process_checkstyle(self.problems, output, docker.strip_base)
def test_process_checkstyle__comma_lines(self): problems = Problems() xml = """ <checkstyle> <file name="other_things.py"> <error line="3,4,5" message="Not good" /> </file> </checkstyle> """ tools.process_checkstyle(problems, xml, lambda x: x) self.assertEqual(3, len(problems)) things = problems.all('other_things.py') self.assertEqual(3, len(things)) self.assertEqual(3, things[0].line) self.assertEqual('Not good', things[0].body) self.assertEqual(4, things[1].line) self.assertEqual('Not good', things[1].body) self.assertEqual(5, things[2].line) self.assertEqual('Not good', things[2].body)
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 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 = docker.run( 'phpcs', command, source_dir=self.base_path) # 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, docker.strip_base)
def test_process_checkstyle__comma_lines(): problems = Problems() xml = """ <checkstyle> <file name="other_things.py"> <error line="3,4,5" message="Not good" /> </file> </checkstyle> """ tools.process_checkstyle(problems, xml, lambda x: x) eq_(3, len(problems)) things = problems.all('other_things.py') eq_(3, len(things)) eq_(3, things[0].line) eq_('Not good', things[0].body) eq_(4, things[1].line) eq_('Not good', things[1].body) eq_(5, things[2].line) eq_('Not good', things[2].body)
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)
def _process_output(self, output, files): filename_converter = functools.partial(self._relativize_filename, files) process_checkstyle(self.problems, output, filename_converter)
def _process_output(self, output, files): if '<?xml' not in output: return self._config_error(output) process_checkstyle(self.problems, output, docker.strip_base)
def _process_output(self, output, files): filename_converter = functools.partial( self._relativize_filename, files) process_checkstyle(self.problems, output, filename_converter)