Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps): bump org.jlleitschuh.gradle.ktlint from 11.6.1 to 12.1.1 & ktlint 1.5.0 #17581

Merged
merged 7 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
14 changes: 4 additions & 10 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@ end_of_line = lf
[*.bat]
end_of_line = crlf

# These can be removed once we upgrade to ktlint 1.5.0
# These are added in preparation for the move to gradle.ktlint 12.1.1

# Rule 'standard:no-unused-imports' throws exception in file 'CardBrowser.kt' at position (1228:9)
[*CardBrowser.kt]
ktlint_standard_no-unused-imports = disabled

# Rule 'standard:parameter-list-wrapping' throws exception in file 'DeckConfig.kt' at position (0:0)
[*DeckConfig.kt]
ktlint_standard_parameter-list-wrapping = disabled
[*.kt]
# We often have block comments representing implementation details after KDocs.
# This feels like an acceptable commenting strategy
ktlint_standard_no-consecutive-comments = disabled
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class DeckPickerTest : InstrumentedTest() {
// Check if currently open Activity is StudyOptionsActivity
assertThat(
activityInstance,
instanceOf(StudyOptionsActivity::class.java)
instanceOf(StudyOptionsActivity::class.java),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,17 @@ class DownloadFileTest : InstrumentedTest() {
// https://github.com/ankidroid/Anki-Android/issues/17573
// https://issuetracker.google.com/issues/382864232

val downloadFile = DownloadFile(
url = "https://ankiweb.net/svc/shared/download-deck/293204297?t=token",
userAgent = "unused",
contentDisposition = "attachment; filename=Goethe_Institute_A1_Wordlist.apkg",
mimeType = "application/octet-stream"
)
val downloadFile =
DownloadFile(
url = "https://ankiweb.net/svc/shared/download-deck/293204297?t=token",
userAgent = "unused",
contentDisposition = "attachment; filename=Goethe_Institute_A1_Wordlist.apkg",
mimeType = "application/octet-stream",
)

assertThat(
downloadFile.toFileName(extension = "apkg"),
equalTo("Goethe_Institute_A1_Wordlist.apkg")
equalTo("Goethe_Institute_A1_Wordlist.apkg"),
)
}
}
22 changes: 12 additions & 10 deletions AnkiDroid/src/androidTest/java/com/ichi2/anki/FieldEditLineTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ import java.util.concurrent.atomic.AtomicReference
class FieldEditLineTest : NoteEditorTest() {
@Test
fun testSetters() {
val line = fieldEditLine().apply {
setContent("Hello", true)
name = "Name"
setOrd(5)
}
val line =
fieldEditLine().apply {
setContent("Hello", true)
name = "Name"
setOrd(5)
}
val text = line.editText
assertThat(text.ord, equalTo(5))
assertThat(text.text.toString(), equalTo("Hello"))
Expand All @@ -39,11 +40,12 @@ class FieldEditLineTest : NoteEditorTest() {

@Test
fun testSaveRestore() {
val toSave = fieldEditLine().apply {
setContent("Hello", true)
name = "Name"
setOrd(5)
}
val toSave =
fieldEditLine().apply {
setContent("Hello", true)
name = "Name"
setOrd(5)
}
val b = toSave.onSaveInstanceState()

val restored = fieldEditLine()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ class NoteEditorIntentTest : InstrumentedTest() {
var runtimePermissionRule: TestRule? = GrantStoragePermission.instance

@get:Rule
var activityRuleIntent: ActivityScenarioRule<SingleFragmentActivity>? = ActivityScenarioRule(
noteEditorTextIntent
)
var activityRuleIntent: ActivityScenarioRule<SingleFragmentActivity>? =
ActivityScenarioRule(
noteEditorTextIntent,
)

@Test
@Flaky(OS.ALL, "Issue 15707 - java.lang.ArrayIndexOutOfBoundsException: length=0; index=0")
Expand All @@ -63,10 +64,11 @@ class NoteEditorIntentTest : InstrumentedTest() {

@Test
fun intentLaunchedWithNonImageIntent() {
val intent = Intent().apply {
action = Intent.ACTION_SEND
type = TEXT_PLAIN
}
val intent =
Intent().apply {
action = Intent.ACTION_SEND
type = TEXT_PLAIN
}
assertFalse(intentLaunchedWithImage(intent))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class NoteEditorTabOrderTest : NoteEditorTest() {

java.lang.AssertionError:

Expected: is "a""""
Expected: is "a"""",
)
@Throws(Throwable::class)
fun testTabOrder() {
Expand All @@ -63,7 +63,10 @@ class NoteEditorTabOrderTest : NoteEditorTest() {
}
}

private fun sendKeyDownUp(editor: NoteEditor, keyCode: Int) {
private fun sendKeyDownUp(
editor: NoteEditor,
keyCode: Int,
) {
val focusedView = editor.requireActivity().currentFocus ?: return
val inputConnection = BaseInputConnection(focusedView, true)
inputConnection.sendKeyEvent(KeyEvent(KeyEvent.ACTION_DOWN, keyCode))
Expand Down
11 changes: 6 additions & 5 deletions AnkiDroid/src/androidTest/java/com/ichi2/anki/NoteEditorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ abstract class NoteEditorTest protected constructor() {
var runtimePermissionRule: TestRule? = GrantStoragePermission.instance

@get:Rule
var activityRule: ActivityScenarioRule<SingleFragmentActivity>? = ActivityScenarioRule(
noteEditorIntent
)
var activityRule: ActivityScenarioRule<SingleFragmentActivity>? =
ActivityScenarioRule(
noteEditorIntent,
)

private val noteEditorIntent: Intent
get() {
Expand All @@ -51,8 +52,8 @@ abstract class NoteEditorTest protected constructor() {
"Test fails on Travis API $invalid",
Build.VERSION.SDK_INT,
not(
equalTo(invalid)
)
equalTo(invalid),
),
)
}
}
Expand Down
51 changes: 28 additions & 23 deletions AnkiDroid/src/androidTest/java/com/ichi2/anki/PagesTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,44 +66,49 @@ class PagesTest : InstrumentedTest() {
@JvmStatic // required for initParameters
fun initParameters(): Collection<Array<out Any>> {
/** See [PageFragment] */
val intents = listOf<Pair<PagesTest.(Context) -> Intent, String>>(
Pair(PagesTest::getStatistics, "Statistics"),
Pair(PagesTest::getCardInfo, "CardInfo"),
Pair(PagesTest::getCongratsPage, "CongratsPage"),
Pair(PagesTest::getDeckOptions, "DeckOptions"),
// the following need a file path
Pair(PagesTest::needsPath, "AnkiPackageImporterFragment"),
Pair(PagesTest::needsPath, "CsvImporter"),
Pair(PagesTest::needsPath, "ImageOcclusion")
)
val intents =
listOf<Pair<PagesTest.(Context) -> Intent, String>>(
Pair(PagesTest::getStatistics, "Statistics"),
Pair(PagesTest::getCardInfo, "CardInfo"),
Pair(PagesTest::getCongratsPage, "CongratsPage"),
Pair(PagesTest::getDeckOptions, "DeckOptions"),
// the following need a file path
Pair(PagesTest::needsPath, "AnkiPackageImporterFragment"),
Pair(PagesTest::needsPath, "CsvImporter"),
Pair(PagesTest::needsPath, "ImageOcclusion"),
)

return intents.map { arrayOf(it.first, it.second) }
}
}
}

fun PagesTest.getStatistics(context: Context): Intent {
return Statistics.getIntent(context)
}
fun PagesTest.getStatistics(context: Context): Intent = Statistics.getIntent(context)

fun PagesTest.getCardInfo(context: Context): Intent {
return addNoteUsingBasicModel().firstCard(col).let { card ->
fun PagesTest.getCardInfo(context: Context): Intent =
addNoteUsingBasicModel().firstCard(col).let { card ->
this.card = card
CardInfoDestination(card.id).toIntent(context)
}
}

fun PagesTest.getCongratsPage(context: Context): Intent {
return addNoteUsingBasicModel().firstCard(col).let { card ->
fun PagesTest.getCongratsPage(context: Context): Intent =
addNoteUsingBasicModel().firstCard(col).let { card ->
this.card = card
CardInfoDestination(card.id).toIntent(context)
}
}
fun PagesTest.getDeckOptions(context: Context): Intent {
return DeckOptions.getIntent(context, col.decks.allNamesAndIds().first().id)
}

fun PagesTest.needsPath(@Suppress("UNUSED_PARAMETER") context: Context): Intent {
fun PagesTest.getDeckOptions(context: Context): Intent =
DeckOptions.getIntent(
context,
col.decks
.allNamesAndIds()
.first()
.id,
)

fun PagesTest.needsPath(
@Suppress("UNUSED_PARAMETER") context: Context,
): Intent {
assumeThat("not implemented: path needed", false, equalTo(true))
TODO()
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import java.util.concurrent.TimeUnit

@RunWith(AndroidJUnit4::class)
class ReviewerFragmentTest : InstrumentedTest() {

// Launch IntroductionActivity instead of DeckPicker activity because in CI
// builds, it seems to create IntroductionActivity after the DeckPicker,
// causing the DeckPicker activity to be destroyed. As a consequence, this
Expand Down Expand Up @@ -76,9 +75,13 @@ class ReviewerFragmentTest : InstrumentedTest() {
card.moveToReviewQueue()
col.backend.updateCards(
listOf(
card.toBackendCard().toBuilder().setCustomData("""{"c":1}""").build()
card
.toBackendCard()
.toBuilder()
.setCustomData("""{"c":1}""")
.build(),
),
true
true,
)

closeGetStartedScreenIfExists()
Expand Down Expand Up @@ -135,7 +138,7 @@ class ReviewerFragmentTest : InstrumentedTest() {
100,
// Increase to a max of 30 seconds because CI builds can be very
// slow
TimeUnit.SECONDS.toMillis(30)
TimeUnit.SECONDS.toMillis(30),
)
}

Expand All @@ -148,4 +151,6 @@ class ReviewerFragmentTest : InstrumentedTest() {

private var Collection.cardStateCustomizer: String?
get() = config.get("cardStateCustomizer")
set(value) { config.set("cardStateCustomizer", value) }
set(value) {
config.set("cardStateCustomizer", value)
}
21 changes: 13 additions & 8 deletions AnkiDroid/src/androidTest/java/com/ichi2/anki/ReviewerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import java.lang.AssertionError

@RunWith(AndroidJUnit4::class)
class ReviewerTest : InstrumentedTest() {

// Launch IntroductionActivity instead of DeckPicker activity because in CI
// builds, it seems to create IntroductionActivity after the DeckPicker,
// causing the DeckPicker activity to be destroyed. As a consequence, this
Expand Down Expand Up @@ -95,9 +94,13 @@ class ReviewerTest : InstrumentedTest() {
card.moveToReviewQueue()
col.backend.updateCards(
listOf(
card.toBackendCard().toBuilder().setCustomData("""{"c":1}""").build()
card
.toBackendCard()
.toBuilder()
.setCustomData("""{"c":1}""")
.build(),
),
true
true,
)

closeGetStartedScreenIfExists()
Expand Down Expand Up @@ -149,8 +152,8 @@ class ReviewerTest : InstrumentedTest() {
onView(withId(R.id.decks)).perform(
RecyclerViewActions.actionOnItem<RecyclerView.ViewHolder>(
hasDescendant(withText(deckName)),
click()
)
click(),
),
)
}

Expand Down Expand Up @@ -202,13 +205,13 @@ class ReviewerTest : InstrumentedTest() {
// ...on the command line it has resource name "good_button"...
onView(withResourceName("good_button")).checkWithTimeout(
matches(isDisplayed()),
100
100,
)
} catch (e: AssertionError) {
// ...but in Android Studio it has resource name "flashcard_layout_ease3" !?
onView(withResourceName("flashcard_layout_ease3")).checkWithTimeout(
matches(isDisplayed()),
100
100,
)
}
}
Expand All @@ -228,4 +231,6 @@ class ReviewerTest : InstrumentedTest() {

private var Collection.cardStateCustomizer: String?
get() = config.get("cardStateCustomizer")
set(value) { config.set("cardStateCustomizer", value) }
set(value) {
config.set("cardStateCustomizer", value)
}
Loading
Loading