Snap for 10447354 from 504c44174623769766a6403b5c00da36ce15d53a to mainline-cellbroadcast-release

Change-Id: I5c62a0af8d62ae2d6eaac48ed8d20692f38a57e5
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..c7cc35a
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,7 @@
+[*.{kt,kts}]
+indent_size = 4
+max_line_length = 100
+trim_trailing_whitespace = true
+insert_final_newline = true
+ij_kotlin_imports_layout=*
+ij_kotlin_packages_to_use_import_on_demand=kotlinx.android.synthetic.**
diff --git a/ktlint-android-all.jar b/ktlint-android-all.jar
index fce8357..8de50b3 100644
--- a/ktlint-android-all.jar
+++ b/ktlint-android-all.jar
Binary files differ
diff --git a/ktlint.py b/ktlint.py
index 16bc0f8..2574319 100755
--- a/ktlint.py
+++ b/ktlint.py
@@ -28,6 +28,7 @@
 
 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 = '''
 **********************************************************************
 To format run:
@@ -41,14 +42,31 @@
   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.add_argument('--editorconfig', default=EDITOR_CONFIG)
+  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 += ['--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]
+
+  # Automatically format files if requested.
   if args.format:
     ktlint_args += ['-F']
-  if not ktlint_args:
-    sys.exit(0)
 
   ktlint_args += ['--android']
 
@@ -61,7 +79,8 @@
     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)