summaryrefslogtreecommitdiff
path: root/ktlint.py
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-10-06 23:28:36 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-10-06 23:28:36 +0000
commit21fd11ea819765612d6b0af133532e1059b85b25 (patch)
treee3c0ed650383fb7e5ac5731d0e68efaae0e36aee /ktlint.py
parent39fed3ead852a0b22e6b2f100c083f8bb47d5a08 (diff)
parentaa768f01dbb57ceca4df0d14db981e3c97957ee2 (diff)
downloadktlint-android-13.0.0_r57.tar.gz
Snap for 9148167 from aa768f01dbb57ceca4df0d14db981e3c97957ee2 to tm-d3-releaseandroid-13.0.0_r57android13-d3-s1-release
Change-Id: I121e47a57c9eded98a897ab9c7fa4e1dd2f6acfb
Diffstat (limited to 'ktlint.py')
-rwxr-xr-xktlint.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/ktlint.py b/ktlint.py
index 86b15ed..aefff63 100755
--- a/ktlint.py
+++ b/ktlint.py
@@ -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)