Skip to content

Commit

Permalink
Run the java formatter more than once. (#163)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chingor13 authored Dec 5, 2018
1 parent fd937d1 commit 7a643b9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions synthtool/languages/java.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand Down

0 comments on commit 7a643b9

Please sign in to comment.