Unverified Commit fe367274 authored by John DiSanti's avatar John DiSanti Committed by GitHub
Browse files

Upgrade Kotlin to 1.9.20 and Ktlint to 1.0.1 (#3320)

This PR upgrades Kotlin to 1.9.20, and Ktlint to 1.0.1.

I had to abandon the pretty-format-kotlin pre-commit hook since it was
ignoring our `.editorconfig`, which made it impossible to suppress some
of the newer lints that would be difficult and undesirable to fix. Now
all Ktlint runs go through gradle, so there isn't any way for
inconsistencies to creep in.

I recommend reviewing this PR commit by commit as the commit that runs
Ktlint against the entire repo has a very large diff. When reviewing the
Ktlint formatting changes, be sure to hide whitespace changes to reduce
how much needs to be examined.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
parent aa1f556a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -17,3 +17,5 @@ ktlint_standard_filename = disabled
ktlint_standard_max-line-length = disabled
ktlint_standard_argument-list-wrapping = disabled
ktlint_standard_parameter-list-wrapping = disabled
ktlint_standard_property-naming = disabled
ktlint_standard_comment-wrapping = disabled
+5 −2
Original line number Diff line number Diff line
@@ -9,8 +9,6 @@ repos:
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
  rev: v2.11.0
  hooks:
  - id: pretty-format-kotlin
    args: [--autofix, --ktlint-version, 0.48.2]
  - id: pretty-format-yaml
    args: [--autofix, --indent, '2']
  - id: pretty-format-rust
@@ -18,6 +16,11 @@ repos:
    files: ^.*\.rs$
- repo: local
  hooks:
  - id: ktlint
    name: Ktlint
    entry: ./.pre-commit-hooks/ktlint.sh
    language: system
    files: ^.*\.kt$
  - id: kotlin-block-quotes
    name: Kotlin Block Quotes
    entry: ./.pre-commit-hooks/kotlin-block-quotes.py
+4 −3
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ def starts_or_ends_block_quote(line, inside_block_quotes):

# Returns the indentation of a line
def line_indent(line):
    indent = re.search("[^\s]", line)
    indent = re.search(r"[^\s]", line)
    if indent != None:
        return indent.start(0)
    else:
@@ -72,7 +72,7 @@ def line_indent(line):

# Changes the indentation of a line
def adjust_indent(line, indent):
    old_indent = re.search("[^\s]", line)
    old_indent = re.search(r"[^\s]", line)
    if old_indent == None:
        return line
    line = line[old_indent.start(0):]
@@ -168,7 +168,8 @@ def fix_file(file_name):
            print("INFO: Fixed indentation in `" + file_name + "`.")
            return True
    else:
        print("INFO: `" + file_name + "` is fine.")
        # This print is useful when debugging this script, but spammy otherwise. Leave it commented.
        # print("INFO: `" + file_name + "` is fine.")
        return False

class SelfTest(unittest.TestCase):
+13 −0
Original line number Diff line number Diff line
#!/bin/bash
#
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
#

set -e

cd "$(git rev-parse --show-toplevel)"
# `-q`: run gradle in quiet mode
# `--console plain`: Turn off the fancy terminal printing in gradle
# `2>/dev/null`: Suppress the build success/failure output at the end since pre-commit will report failures
./gradlew -q --console plain ktlintPreCommit -DktlintPreCommitArgs="$*" 2>/dev/null
+2 −2
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ dependencies {
}

tasks.compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
    kotlinOptions.jvmTarget = "11"
}

// Reusable license copySpec
@@ -67,7 +67,7 @@ if (isTestingEnabled.toBoolean()) {
    }

    tasks.compileTestKotlin {
        kotlinOptions.jvmTarget = "1.8"
        kotlinOptions.jvmTarget = "11"
    }

    tasks.test {
Loading