Пример #1
0
    def CheckDirectory(self, start_dir):
        """Checks all relevant source files in the specified directory and
    its subdirectories for compliance with DEPS rules throughout the
    tree (starting at |self.base_directory|).  |start_dir| must be a
    subdirectory of |self.base_directory|.

    On completion, self.results_formatter has the results of
    processing, and calling Report() will print a report of results.
    """
        java = java_checker.JavaChecker(self.base_directory, self.verbose)
        cpp = cpp_checker.CppChecker(self.verbose, self._resolve_dotdot,
                                     self.base_directory)
        proto = proto_checker.ProtoChecker(self.verbose, self._resolve_dotdot,
                                           self.base_directory)
        checkers = dict((extension, checker) for checker in [java, cpp, proto]
                        for extension in checker.EXTENSIONS)

        for rules, file_paths in self.GetAllRulesAndFiles(start_dir):
            for full_name in file_paths:
                if self._skip_tests and _IsTestFile(
                        os.path.basename(full_name)):
                    continue
                file_extension = os.path.splitext(full_name)[1]
                if not file_extension in checkers:
                    continue
                checker = checkers[file_extension]
                file_status = checker.CheckFile(rules, full_name)
                if file_status.HasViolations():
                    self.results_formatter.AddError(file_status)
Пример #2
0
  def CheckAddedProtoImports(self, added_imports):
    """This is used from PRESUBMIT.py to check new #import statements added in
    the change being presubmit checked.

    Args:
      added_imports : ((file_path, (import_line, import_line, ...), ...)

    Return:
      A list of tuples, (bad_file_path, rule_type, rule_description)
      where rule_type is one of Rule.DISALLOW or Rule.TEMP_ALLOW and
      rule_description is human-readable. Empty if no problems.
    """
    return self.CheckIncludesAndImports(
        added_imports, proto_checker.ProtoChecker(
            verbose=self.verbose, root_dir=self.base_directory))