From baf39237b0693717fd55ba1fc53a249caead5c76 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Wed, 5 Dec 2018 13:14:45 -0800 Subject: [PATCH] Run the java formatter more than once. The java formatter is rules based and the output from the first pass is not guarantee to pass linting yet. For example, if unused imports are removed, it may not clean up double line break whitespace. --- synthtool/languages/java.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/synthtool/languages/java.py b/synthtool/languages/java.py index 6bd012342..c40e6bcdf 100644 --- a/synthtool/languages/java.py +++ b/synthtool/languages/java.py @@ -24,7 +24,9 @@ DEFAULT_FORMAT_VERSION = "1.6" -def format_code(path: str, version: str = DEFAULT_FORMAT_VERSION) -> None: +def format_code( + path: str, version: str = DEFAULT_FORMAT_VERSION, times: int = 2 +) -> None: """ Runs the google-java-format jar against all .java files found within the provided path. @@ -39,7 +41,8 @@ def format_code(path: str, version: str = DEFAULT_FORMAT_VERSION) -> None: # Run the formatter as a jar file log.info("Running java formatter on {} files".format(len(files))) - shell.run(["java", "-jar", str(jar), "--replace"] + files) + for _ in range(times): + shell.run(["java", "-jar", str(jar), "--replace"] + files) def _download_formatter(version: str, dest: Path) -> None: