diff options
author | Jeff Davidson <jpd@google.com> | 2016-12-15 17:34:40 -0800 |
---|---|---|
committer | Jeff Davidson <jpd@google.com> | 2016-12-16 14:44:15 -0800 |
commit | 1b169302fe4e8dffd5c69285e78425164ec59a16 (patch) | |
tree | cc6e71d4807c45d7cca00fde1948093441f14371 | |
parent | 0f9d9f860918f9063ca98803ae1e55410acbb818 (diff) | |
download | repohooks-1b169302fe4e8dffd5c69285e78425164ec59a16.tar.gz |
Pass --skip-sorting-imports to google-java-format.
In the newest version of the formatter, imports are sorted by default.
This would normally be fine, except that AOSP has a defined order that
doesn't confirm to this style, which would lead to the formatter
requiring a lot of changes and possibly introducing conflicts without
a larger scale cleanup. So turn off this behavior.
Projects that would prefer to sort their imports may specify the
--sort-options arg in their PREUPLOAD.cfg files to revert to the
default google-java-format behavior.
Bug: 31552314
Test: Verified in local test repository
Change-Id: I9e2df57ef472e7f2d1d4e795ba63559c1aacac67
-rw-r--r-- | rh/hooks.py | 5 | ||||
-rwxr-xr-x | tools/google-java-format.py | 7 |
2 files changed, 8 insertions, 4 deletions
diff --git a/rh/hooks.py b/rh/hooks.py index d92c953..2c0dc1d 100644 --- a/rh/hooks.py +++ b/rh/hooks.py @@ -293,15 +293,12 @@ def check_clang_format(project, commit, _desc, diff, options=None): def check_google_java_format(project, commit, _desc, _diff, options=None): """Run google-java-format on the commit.""" - if options.args(): - raise ValueError('google-java-format check takes no options') - tool = get_helper_path('google-java-format.py') google_java_format = options.tool_path('google-java-format') google_java_format_diff = options.tool_path('google-java-format-diff') cmd = [tool, '--google-java-format', google_java_format, '--google-java-format-diff', google_java_format_diff, - '--commit', commit] + '--commit', commit] + options.args() return _check_cmd('google-java-format', project, commit, cmd) diff --git a/tools/google-java-format.py b/tools/google-java-format.py index f76175a..6796cfc 100755 --- a/tools/google-java-format.py +++ b/tools/google-java-format.py @@ -44,6 +44,11 @@ def get_parser(): help='Fix any formatting errors automatically.') parser.add_argument('--commit', type=str, default='HEAD', help='Specify the commit to validate.') + # While the formatter defaults to sorting imports, in the Android codebase, + # the standard import order doesn't match the formatter's, so flip the + # default to not sort imports, while letting callers override as desired. + parser.add_argument('--sort-imports', action='store_true', + help='If true, imports will be sorted.') return parser @@ -76,6 +81,8 @@ def main(argv): cmd = [opts.google_java_format_diff, '-p1', '--aosp'] if opts.fix: cmd.extend(['-i']) + if not opts.sort_imports: + cmd.extend(['--skip-sorting-imports']) stdout = rh.utils.run_command(cmd, input=diff, |