diff options
author | Jordan Demeulenaere <jdemeulenaere@google.com> | 2022-10-06 14:49:32 +0200 |
---|---|---|
committer | Jordan Demeulenaere <jdemeulenaere@google.com> | 2022-10-06 14:49:32 +0200 |
commit | aa768f01dbb57ceca4df0d14db981e3c97957ee2 (patch) | |
tree | e3c0ed650383fb7e5ac5731d0e68efaae0e36aee | |
parent | 4149cdeb0128facacfb2d09ddcfa0661259c177f (diff) | |
download | ktlint-android13-qpr3-c-s11-release.tar.gz |
Allow preupload hooks to ignore more formatting ktlint rulesandroid-13.0.0_r82android-13.0.0_r81android-13.0.0_r80android-13.0.0_r74android-13.0.0_r73android-13.0.0_r72android-13.0.0_r66android-13.0.0_r65android-13.0.0_r64android-13.0.0_r60android-13.0.0_r59android-13.0.0_r58android13-qpr3-c-s8-releaseandroid13-qpr3-c-s7-releaseandroid13-qpr3-c-s6-releaseandroid13-qpr3-c-s5-releaseandroid13-qpr3-c-s4-releaseandroid13-qpr3-c-s3-releaseandroid13-qpr3-c-s2-releaseandroid13-qpr3-c-s12-releaseandroid13-qpr3-c-s11-releaseandroid13-qpr3-c-s10-releaseandroid13-qpr3-c-s1-release
This CL adds a --no-verify-format rule to ktlint.py so that preuploads
can ignore more formatting rules. This will be used by projects who
already use ktfmt for formatting new files, so that useful ktlint errors
(like unused variables) are not hidden by a ton of ktlint formatting
issues which we are now mostly ignoring.
Bug: 235461679
Test: Manual
Change-Id: I324bcaf4e9e2b087201810343471a55f2434339f
-rw-r--r-- | .editorconfig | 6 | ||||
-rwxr-xr-x | ktlint.py | 16 |
2 files changed, 14 insertions, 8 deletions
diff --git a/.editorconfig b/.editorconfig index e97aa07..1e3f51c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -4,9 +4,3 @@ max_line_length = 100 trim_trailing_whitespace = true insert_final_newline = true ij_kotlin_imports_layout=* - -# Comma-separated list of rules to disable -# ktlint disagrees on indentation with ktfmt in some cases -# TODO(b/185904220): paren spacing disabled because of a ktfmt bug -# TODO(b/189506168): curly spacing disabled because of a ktfmt bug -disabled_rules=indent,paren-spacing,curly-spacing,wrapping @@ -42,14 +42,25 @@ def main(args=None): parser.add_argument('--file', '-f', nargs='*') parser.add_argument('--format', '-F', dest='format', action='store_true') parser.add_argument('--noformat', dest='format', action='store_false') - parser.set_defaults(format=False) + parser.add_argument('--no-verify-format', dest='verify_format', action='store_false') + parser.set_defaults(format=False, verify_format=True) args = parser.parse_args() kt_files = [f for f in args.file if f.endswith('.kt') or f.endswith('.kts')] if not kt_files: sys.exit(0) + disabled_rules = ['indent', 'paren-spacing', 'curly-spacing', 'wrapping'] + + # Disable more format-related rules if we shouldn't verify the format. This is usually + # the case if files we are checking are already checked by ktfmt. + if not args.verify_format: + disabled_rules += ['final-newline', 'no-consecutive-blank-lines', 'import-ordering'] + ktlint_args = kt_files[:] ktlint_args += ['--editorconfig', EDITOR_CONFIG] + ktlint_args += ['--disabled_rules=' + ','.join(disabled_rules)] + + # Automatically format files if requested. if args.format: ktlint_args += ['-F'] @@ -64,7 +75,8 @@ def main(args=None): if stdout: print('prebuilts/ktlint found errors in files you changed:') print(stdout.decode('utf-8')) - print(FORMAT_MESSAGE.format(MAIN_DIRECTORY, ' '.join(kt_files))) + if (args.verify_format): + print(FORMAT_MESSAGE.format(MAIN_DIRECTORY, ' '.join(kt_files))) sys.exit(1) else: sys.exit(0) |