class CheckstyleBear(LocalBear, Lint): executable = 'java' google_checks = join(dirname(abspath(__file__)), 'google_checks.xml') jar = join(dirname(abspath(__file__)), 'checkstyle.jar') severity_map = { "INFO": RESULT_SEVERITY.INFO, "WARN": RESULT_SEVERITY.NORMAL } check_prerequisites = classmethod( check_linter_prerequisites_builder( executable, ["java", "-jar", jar, "-v"], "jar file {} is invalid and cannot be used".format(jar))) def run(self, filename, file): """ Checks the code using `checkstyle` using the Google codestyle specification. """ self.output_regex = re.compile( r'\[(?P<severity>WARN|INFO)\]\s*' + re.escape(abspath(filename)) + r':(?P<line>\d+)(:(?P<col>\d+))?:\s*' r'(?P<message>.*?)\s*\[(?P<origin>[a-zA-Z]+?)\]') self.arguments = '-jar ' + self.jar + ' -c ' + self.google_checks self.arguments += " {filename}" return self.lint(filename)
def check_linter_prerequisites_builder_valid_executable_test(): executable = 'java' check_linter_prerequisites = check_linter_prerequisites_builder( executable, ['java', '-version'], '' ) assert check_linter_prerequisites(Dummy) == True
def check_linter_prerequisites_builder_invalid_executable_test(): executable = 'invalid_executable' executable_fail_message = executable + ' is not installed.' check_linter_prerequisites = check_linter_prerequisites_builder( executable, [], "" ) assert check_linter_prerequisites(Dummy) == executable_fail_message
def check_linter_prerequisites_builder_invalid_options_test(): executable = 'java' options_fail_msg = 'invalid option' check_linter_prerequisites = check_linter_prerequisites_builder( executable, ['java', '-v'], options_fail_msg ) assert check_linter_prerequisites(Dummy) == options_fail_msg
class ScalaLintBear(LocalBear, Lint): executable = 'java' current_file_dir = dirname(abspath(__file__)) jar = join(current_file_dir, 'scalastyle.jar') scalastyle_config_file = join(current_file_dir, 'scalastyle_config.xml') output_regex = re.compile( r'(?P<severity>warning)\s(file=)(?P<filename>.+)\s(message=)' r'(?P<message>.+)(line=)(?P<line>\d+)(\s(column=)(?P<column>\d+))*' ) severity_map = { "warning": RESULT_SEVERITY.NORMAL } prerequisites_args_list = [ "java", "-jar", jar, "-c", scalastyle_config_file, ".", "-q", "true" ] prerequisites_fail_msg = "jar file {} is invalid and cannot be used".format( jar) check_linter_prerequisites = check_linter_prerequisites_builder( executable, prerequisites_args_list, prerequisites_fail_msg ) check_prerequisites = classmethod(check_linter_prerequisites) def run(self, filename, file, scalalint_config: str=""): ''' Checks the code with `scalastyle` on each file separately. :param scalalint_config: Path to a custom configuration file. ''' self.arguments = ' -jar ' + self.jar self.arguments += ' {filename}' scala_config_file = self.scalastyle_config_file if scalalint_config: scala_config_file = scalalint_config self.arguments += (' --config ' + escape_path_argument(scala_config_file)) return self.lint(filename)