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

style(lint) manual fixes for gradle.ktlint 12.1.1 / ktLint 1.5.0 #17577

Merged
merged 1 commit 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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,15 @@
end_of_line = lf

[*.bat]
end_of_line = crlf
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
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,10 @@ abstract class NoteEditorTest protected constructor() {

private val invalidSdksImpl: List<Int>
get() {
// TODO: Look into these assumptions and see if they can be diagnosed - both work on my emulators.
// If we fix them, we might be able to use instrumentation.sendKeyDownUpSync
/*
java.lang.AssertionError: Activity never becomes requested state "[DESTROYED]" (last lifecycle transition = "PAUSED")
at androidx.test.core.app.ActivityScenario.waitForActivityToBecomeAnyOf(ActivityScenario.java:301)
*/
*/
val invalid = Build.VERSION_CODES.N_MR1
val integers = ArrayList(listOf(invalid))
integers.addAll(invalidSdks!!)
Expand Down
12 changes: 10 additions & 2 deletions AnkiDroid/src/androidTest/java/com/ichi2/anki/tests/ACRATest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,11 @@ class ACRATest : InstrumentedTest() {
assertThat("Second handler is AnalyticsLoggingExceptionHandler", secondExceptionHandler is UsageAnalytics.AnalyticsLoggingExceptionHandler)
UsageAnalytics.unInstallDefaultExceptionHandler()
var thirdExceptionHandler = Thread.getDefaultUncaughtExceptionHandler()
assertThat("Third handler is neither Analytics nor ThrowableFilter", thirdExceptionHandler !is UsageAnalytics.AnalyticsLoggingExceptionHandler && thirdExceptionHandler !is ThrowableFilterService.FilteringExceptionHandler)
assertThat(
"Third handler is neither Analytics nor ThrowableFilter",
thirdExceptionHandler !is UsageAnalytics.AnalyticsLoggingExceptionHandler &&
thirdExceptionHandler !is ThrowableFilterService.FilteringExceptionHandler
)

// chain them again
UsageAnalytics.installDefaultExceptionHandler()
Expand All @@ -260,7 +264,11 @@ class ACRATest : InstrumentedTest() {
assertThat("Second handler is AnalyticsLoggingExceptionHandler", secondExceptionHandler is UsageAnalytics.AnalyticsLoggingExceptionHandler)
UsageAnalytics.unInstallDefaultExceptionHandler()
thirdExceptionHandler = Thread.getDefaultUncaughtExceptionHandler()
assertThat("Third handler is neither Analytics nor ThrowableFilter", thirdExceptionHandler !is UsageAnalytics.AnalyticsLoggingExceptionHandler && thirdExceptionHandler !is ThrowableFilterService.FilteringExceptionHandler)
assertThat(
"Third handler is neither Analytics nor ThrowableFilter",
thirdExceptionHandler !is UsageAnalytics.AnalyticsLoggingExceptionHandler &&
thirdExceptionHandler !is ThrowableFilterService.FilteringExceptionHandler
)
}

private fun setAcraReportingMode(feedbackReportAlways: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -789,15 +789,17 @@ class ContentProviderTest : InstrumentedTest() {
fun testUnsupportedOperations() {
val cr = contentResolver
val dummyValues = ContentValues()
val updateUris = arrayOf( // Can't update most tables in bulk -- only via ID
FlashCardsContract.Note.CONTENT_URI,
FlashCardsContract.Model.CONTENT_URI,
FlashCardsContract.Deck.CONTENT_ALL_URI,
FlashCardsContract.Note.CONTENT_URI.buildUpon()
.appendPath("1234")
.appendPath("cards")
.build()
)
// Can't update most tables in bulk -- only via ID
val updateUris =
arrayOf(
FlashCardsContract.Note.CONTENT_URI,
FlashCardsContract.Model.CONTENT_URI,
FlashCardsContract.Deck.CONTENT_ALL_URI,
FlashCardsContract.Note.CONTENT_URI.buildUpon()
.appendPath("1234")
.appendPath("cards")
.build()
)
for (uri in updateUris) {
try {
cr.update(uri, dummyValues, null, null)
Expand All @@ -808,22 +810,24 @@ class ContentProviderTest : InstrumentedTest() {
// ... or this.
}
}
val deleteUris = arrayOf(
FlashCardsContract.Note.CONTENT_URI, // Only note/<id> is supported
FlashCardsContract.Note.CONTENT_URI.buildUpon()
.appendPath("1234")
.appendPath("cards")
.build(),
FlashCardsContract.Note.CONTENT_URI.buildUpon()
.appendPath("1234")
.appendPath("cards")
.appendPath("2345")
.build(),
FlashCardsContract.Model.CONTENT_URI,
FlashCardsContract.Model.CONTENT_URI.buildUpon()
.appendPath("1234")
.build()
)
// Only note/<id> is supported
val deleteUris =
arrayOf(
FlashCardsContract.Note.CONTENT_URI,
FlashCardsContract.Note.CONTENT_URI.buildUpon()
.appendPath("1234")
.appendPath("cards")
.build(),
FlashCardsContract.Note.CONTENT_URI.buildUpon()
.appendPath("1234")
.appendPath("cards")
.appendPath("2345")
.build(),
FlashCardsContract.Model.CONTENT_URI,
FlashCardsContract.Model.CONTENT_URI.buildUpon()
.appendPath("1234")
.build()
)
for (uri in deleteUris) {
try {
cr.delete(uri, null, null)
Expand All @@ -832,23 +836,25 @@ class ContentProviderTest : InstrumentedTest() {
// This was expected
}
}
val insertUris = arrayOf( // Can't do an insert with specific ID on the following tables
FlashCardsContract.Note.CONTENT_URI.buildUpon()
.appendPath("1234")
.build(),
FlashCardsContract.Note.CONTENT_URI.buildUpon()
.appendPath("1234")
.appendPath("cards")
.build(),
FlashCardsContract.Note.CONTENT_URI.buildUpon()
.appendPath("1234")
.appendPath("cards")
.appendPath("2345")
.build(),
FlashCardsContract.Model.CONTENT_URI.buildUpon()
.appendPath("1234")
.build()
)
// Can't do an insert with specific ID on the following tables
val insertUris =
arrayOf(
FlashCardsContract.Note.CONTENT_URI.buildUpon()
.appendPath("1234")
.build(),
FlashCardsContract.Note.CONTENT_URI.buildUpon()
.appendPath("1234")
.appendPath("cards")
.build(),
FlashCardsContract.Note.CONTENT_URI.buildUpon()
.appendPath("1234")
.appendPath("cards")
.appendPath("2345")
.build(),
FlashCardsContract.Model.CONTENT_URI.buildUpon()
.appendPath("1234")
.build()
)
for (uri in insertUris) {
try {
cr.insert(uri, dummyValues)
Expand Down Expand Up @@ -1273,10 +1279,14 @@ class ContentProviderTest : InstrumentedTest() {

contentResolver.query(
specificCardUri,
arrayOf(FlashCardsContract.Card.QUESTION, FlashCardsContract.Card.ANSWER), // projection
null, // selection is ignored for this URI
null, // selectionArgs is ignored for this URI
null // sortOrder is ignored for this URI
// projection
arrayOf(FlashCardsContract.Card.QUESTION, FlashCardsContract.Card.ANSWER),
// selection is ignored for this URI
null,
// selectionArgs is ignored for this URI
null,
// sortOrder is ignored for this URI
null
)?.let { cursor ->
if (!cursor.moveToFirst()) {
fail("no rows in cursor")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/****************************************************************************************
/* **************************************************************************************
* Copyright (c) 2011 Kostas Spyropoulos <[email protected]> *
* Copyright (c) 2014 Bruno Romero de Azevedo <[email protected]> *
* Copyright (c) 2014–15 Roland Sieker <[email protected]> *
Expand All @@ -17,6 +17,7 @@
* You should have received a copy of the GNU General Public License along with *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/

// TODO: implement own menu? http://www.codeproject.com/Articles/173121/Android-Menus-My-Way
package com.ichi2.anki

Expand Down Expand Up @@ -277,8 +278,9 @@ abstract class AbstractFlashcardViewer :
*/
protected val gestureProcessor = GestureProcessor(this)

/** Handle joysticks/pedals */
// needs to be lateinit due to a reliance on Context

/** Handle joysticks/pedals */
protected lateinit var motionEventHandler: MotionEventHandler

val server = AnkiServer(this).also { it.start() }
Expand Down
8 changes: 4 additions & 4 deletions AnkiDroid/src/main/java/com/ichi2/anki/AnkiDroidApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,9 @@ open class AnkiDroidApp : Application(), Configuration.Provider, ChangeManager.S
val parsed = Uri.parse(uri)
return Intent(Intent.ACTION_VIEW, parsed)
} // TODO actually this can be done by translating "link_help" string for each language when the App is
// properly translated

/**
* Get the url for the feedback page
* Get the url for the properly translated feedback page
* @return
*/
val feedbackUrl: String
Expand All @@ -436,9 +436,9 @@ open class AnkiDroidApp : Application(), Configuration.Provider, ChangeManager.S
"ar" -> appResources.getString(R.string.link_help_ar)
else -> appResources.getString(R.string.link_help)
} // TODO actually this can be done by translating "link_manual" string for each language when the App is
// properly translated

/**
* Get the url for the manual
* Get the url for the properly translated manual
* @return
*/
val manualUrl: String
Expand Down
22 changes: 17 additions & 5 deletions AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,10 @@ open class CardBrowser :
}
val data = result.data
if (data != null &&
(data.getBooleanExtra(NoteEditor.RELOAD_REQUIRED_EXTRA_KEY, false) || data.getBooleanExtra(NoteEditor.NOTE_CHANGED_EXTRA_KEY, false))
(
data.getBooleanExtra(NoteEditor.RELOAD_REQUIRED_EXTRA_KEY, false) ||
data.getBooleanExtra(NoteEditor.NOTE_CHANGED_EXTRA_KEY, false)
)
) {
Timber.d("Reloading Card Browser due to activity result")
// if reloadRequired or noteChanged flag was sent from note editor then reload card list
Expand Down Expand Up @@ -249,7 +252,10 @@ open class CardBrowser :
// Previewing can now perform an "edit", so it can pass on a reloadRequired
val data = result.data
if (data != null &&
(data.getBooleanExtra(NoteEditor.RELOAD_REQUIRED_EXTRA_KEY, false) || data.getBooleanExtra(NoteEditor.NOTE_CHANGED_EXTRA_KEY, false))
(
data.getBooleanExtra(NoteEditor.RELOAD_REQUIRED_EXTRA_KEY, false) ||
data.getBooleanExtra(NoteEditor.NOTE_CHANGED_EXTRA_KEY, false)
)
) {
forceRefreshSearch()
if (reviewerCardId == currentCardId) {
Expand Down Expand Up @@ -1886,8 +1892,11 @@ open class CardBrowser :
// can delete some elements from the cache for example, since nothing is displayed.

// It would be interesting to know how often it occurs, but it is not a bug.
// CrashReportService.sendExceptionReport("CardBrowser Scroll Issue 8821", "In a search result of $size cards, with totalItemCount = $totalItemCount, somehow we got $visibleItemCount elements to display.")
Timber.w("CardBrowser Scroll Issue 15441/8821: In a search result of $size cards, with totalItemCount = $totalItemCount, somehow we got $visibleItemCount elements to display.")
Timber.w(
"CardBrowser Scroll Issue 15441/8821: In a search result of $size " +
"cards, with totalItemCount = $totalItemCount, " +
"somehow we got $visibleItemCount elements to display."
)
}
// In all of those cases, there is nothing to do:
if (size <= 0 || firstVisibleItem >= size || lastVisibleItem >= size || visibleItemCount <= 0) {
Expand Down Expand Up @@ -2489,7 +2498,10 @@ open class CardBrowser :
due.toLong()
} else if (card.queue == Consts.QUEUE_TYPE_NEW || card.type == Consts.CARD_TYPE_NEW) {
return due.toString()
} else if (card.queue == Consts.QUEUE_TYPE_REV || card.queue == Consts.QUEUE_TYPE_DAY_LEARN_RELEARN || card.type == Consts.CARD_TYPE_REV && card.queue < 0) {
} else if (card.queue == Consts.QUEUE_TYPE_REV ||
card.queue == Consts.QUEUE_TYPE_DAY_LEARN_RELEARN ||
card.type == Consts.CARD_TYPE_REV && card.queue < 0
) {
val time = TimeManager.time.intTime()
val nbDaySinceCreation = due - col.sched.today
time + nbDaySinceCreation * SECONDS_PER_DAY
Expand Down
2 changes: 1 addition & 1 deletion AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/****************************************************************************************
/* **************************************************************************************
* Copyright (c) 2009 Andrew Dubya <[email protected]> *
* Copyright (c) 2009 Nicolas Raoul <[email protected]> *
* Copyright (c) 2009 Edu Zamora <[email protected]> *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,11 @@ class CardContentProvider : ContentProvider() {
val keyAndValue = arg.split("=").toTypedArray() // split arguments into key ("limit") and value ("?")
try {
// check if value is a placeholder ("?"), if so replace with the next value of selectionArgs
val value = if ("?" == keyAndValue[1].trim { it <= ' ' }) selectionArgs!![selectionArgIndex++] else keyAndValue[1]
val value = if ("?" == keyAndValue[1].trim { it <= ' ' }) {
selectionArgs!![selectionArgIndex++]
} else {
keyAndValue[1]
}
if ("limit" == keyAndValue[0].trim { it <= ' ' }) {
limit = value.toInt()
} else if ("deckID" == keyAndValue[0].trim { it <= ' ' }) {
Expand Down Expand Up @@ -980,8 +984,10 @@ class CardContentProvider : ContentProvider() {
val tempFile: File
try {
tempFile = File.createTempFile(
preferredName + "_", // the beginning of the filename.
".$fileMimeType", // this is the extension, if null, '.tmp' is used, need to get the extension from MIME type?
// the beginning of the filename.
preferredName + "_",
// this is the extension, if null, '.tmp' is used, need to get the extension from MIME type?
".$fileMimeType",
File(tempMediaDir)
)
tempFile.deleteOnExit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,13 @@ class GestureMapper {
}

companion object {
@Suppress("ktlint:standard:property-naming")
private var VIEW_CONFIGURATION: ViewConfiguration? = null

@Suppress("ktlint:standard:property-naming")
private var DEFAULT_SWIPE_MIN_DISTANCE = 0

@Suppress("ktlint:standard:property-naming")
private var DEFAULT_SWIPE_THRESHOLD_VELOCITY = 0
private fun fromTap(height: Int, width: Int, posX: Float, posY: Float): Gesture {
val gestureIsRight = posY > height * (1 - posX / width)
Expand Down
5 changes: 5 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/libanki/sched/Scheduler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ open class Scheduler(val col: Collection) {
/**
* @return Number of new card in current deck and its descendants. Capped at [REPORT_LIMIT]
*/
@Suppress("ktlint:standard:max-line-length")
fun totalNewForCurrentDeck(): Int {
return col.db.queryScalar(
"SELECT count() FROM cards WHERE id IN (SELECT id FROM cards WHERE did IN " + deckLimit() + " AND queue = " + Consts.QUEUE_TYPE_NEW + " LIMIT ?)",
Expand All @@ -506,6 +507,7 @@ open class Scheduler(val col: Collection) {

/** @return Number of review cards in current deck.
*/
@Suppress("ktlint:standard:max-line-length")
fun totalRevForCurrentDeck(): Int {
return col.db.queryScalar(
"SELECT count() FROM cards WHERE id IN (SELECT id FROM cards WHERE did IN " + deckLimit() + " AND queue = " + Consts.QUEUE_TYPE_REV + " AND due <= ? LIMIT ?)",
Expand Down Expand Up @@ -535,6 +537,7 @@ open class Scheduler(val col: Collection) {
}

/** true if there are any rev cards due. */
@Suppress("ktlint:standard:max-line-length")
open fun revDue(): Boolean {
return col.db
.queryScalar(
Expand All @@ -545,6 +548,7 @@ open class Scheduler(val col: Collection) {
}

/** true if there are any new cards due. */
@Suppress("ktlint:standard:max-line-length")
open fun newDue(): Boolean {
return col.db.queryScalar("SELECT 1 FROM cards WHERE did IN " + deckLimit() + " AND queue = " + Consts.QUEUE_TYPE_NEW + " LIMIT 1") != 0
}
Expand All @@ -568,6 +572,7 @@ open class Scheduler(val col: Collection) {
* @param counts An array of [new, lrn, rev] counts from the scheduler's counts() method.
* @param reload Force rebuild of estimator rates using the revlog.
*/
@Suppress("ktlint:standard:max-line-length")
fun eta(counts: Counts, reload: Boolean = true): Int {
var newRate: Double
var newTime: Double
Expand Down
3 changes: 1 addition & 2 deletions AnkiDroid/src/main/java/com/ichi2/ui/FixedTextView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ open class FixedTextView : AppCompatTextView {
at android.widget.TextView.performLongClick(TextView.java:13544)
at android.view.View.performLongClick(View.java:7928)
at android.view.View$CheckForLongPress.run(View.java:29321)
*/
/*

java.lang.NullPointerException: Attempt to invoke virtual method 'int android.widget.Editor$SelectionModifierCursorController.getMinTouchOffset()' on a null object reference
at android.widget.Editor.touchPositionIsInSelection(Unknown:36)
at android.widget.Editor.performLongClick(Unknown:72)
Expand Down
Loading
Loading