diff options
author | Xin Li <delphij@google.com> | 2024-01-17 22:14:44 -0800 |
---|---|---|
committer | Xin Li <delphij@google.com> | 2024-01-17 22:14:44 -0800 |
commit | 9176c8d6120f88393541b7f459e14b45395455a0 (patch) | |
tree | e69317294b14e4b413f4806b49ee07860abb6f53 | |
parent | f83371c43f8be3c34c8094e30bbb542ad5270e07 (diff) | |
parent | 181a0c7dbf8af2c88e670f77e5a8fc04f7a87658 (diff) | |
download | ktlint-9176c8d6120f88393541b7f459e14b45395455a0.tar.gz |
Merge Android 24Q1 Release (ab/11220357)temp_319669529
Bug: 319669529
Merged-In: I984735f7d4372deaaa77c5a429e775c75dfb166a
Change-Id: I7bbd1d0c8726dbfc642111ea04545c58ea4928cc
-rw-r--r-- | ktlint-android-all.jar | bin | 62738111 -> 66818499 bytes | |||
-rwxr-xr-x | ktlint.py | 52 |
2 files changed, 41 insertions, 11 deletions
diff --git a/ktlint-android-all.jar b/ktlint-android-all.jar Binary files differindex 8de50b3..06c22af 100644 --- a/ktlint-android-all.jar +++ b/ktlint-android-all.jar @@ -29,12 +29,12 @@ import sys MAIN_DIRECTORY = os.path.normpath(os.path.dirname(__file__)) KTLINT_JAR = os.path.join(MAIN_DIRECTORY, 'ktlint-android-all.jar') EDITOR_CONFIG = os.path.join(MAIN_DIRECTORY, '.editorconfig') -FORMAT_MESSAGE = ''' +FORMAT_MESSAGE = """ ********************************************************************** To format run: {}/ktlint.py --format --file {} ********************************************************************** -''' +""" def main(args=None): @@ -42,7 +42,9 @@ 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.add_argument('--no-verify-format', dest='verify_format', action='store_false') + parser.add_argument( + '--no-verify-format', dest='verify_format', action='store_false' + ) parser.add_argument('--editorconfig', default=EDITOR_CONFIG) parser.set_defaults(format=False, verify_format=True) args = parser.parse_args() @@ -50,36 +52,63 @@ def main(args=None): if not kt_files: sys.exit(0) - disabled_rules = ['indent', 'paren-spacing', 'curly-spacing', 'wrapping'] + disabled_rules = [ + 'indent', + 'paren-spacing', + 'curly-spacing', + 'wrapping', + # trailing-comma requires wrapping + 'trailing-comma-on-call-site', + 'trailing-comma-on-declaration-site', + # annotations requires wrapping + 'spacing-between-declarations-with-annotations', + 'annotation', + ] # 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'] + disabled_rules += [ + 'final-newline', + 'no-consecutive-blank-lines', + 'import-ordering', + 'comment-wrapping', + 'argument-list-wrapping', + 'spacing-between-declarations-with-comments', + 'annotation-spacing', + 'multiline-if-else', + ] ktlint_args = kt_files[:] ktlint_args += ['--disabled_rules=' + ','.join(disabled_rules)] # Setup editor config explicitly if defined - else will inherit from tree if args.editorconfig is not None: - ktlint_args += ['--editorconfig', args.editorconfig] + ktlint_args += ['--editorconfig', args.editorconfig] # Automatically format files if requested. if args.format: ktlint_args += ['-F'] - ktlint_args += ['--android'] - ktlint_env = os.environ.copy() ktlint_env['JAVA_CMD'] = 'java' try: - check = subprocess.Popen(['java', '-jar', KTLINT_JAR] + ktlint_args, - stdout=subprocess.PIPE, env=ktlint_env) + check = subprocess.Popen( + [ + 'java', + '--add-opens=java.base/java.lang=ALL-UNNAMED', + '-jar', + KTLINT_JAR, + ] + + ktlint_args, + stdout=subprocess.PIPE, + env=ktlint_env, + ) stdout, _ = check.communicate() if stdout: print('prebuilts/ktlint found errors in files you changed:') print(stdout.decode('utf-8')) - if (args.verify_format): + if args.verify_format: print(FORMAT_MESSAGE.format(MAIN_DIRECTORY, ' '.join(kt_files))) sys.exit(1) else: @@ -89,5 +118,6 @@ def main(args=None): print('Error running ktlint!') sys.exit(1) + if __name__ == '__main__': main() |