From 7c5a41f03deb73a5c9fd974480ddc4559ab80b07 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 10 Oct 2023 22:09:57 +0200 Subject: [PATCH] Konsist: no field should have 'm' prefix, and fix new detected issues. --- .../io/element/android/app/KonsistTest.kt | 14 ++++++++++ .../rageshake/impl/logs/LogFormatter.kt | 6 ++-- .../impl/reporter/DefaultBugReporter.kt | 28 +++++++++---------- .../push/impl/push/DefaultPushHandler.kt | 4 +-- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/app/src/test/kotlin/io/element/android/app/KonsistTest.kt b/app/src/test/kotlin/io/element/android/app/KonsistTest.kt index bf44b0c2ed..25367e8c5a 100644 --- a/app/src/test/kotlin/io/element/android/app/KonsistTest.kt +++ b/app/src/test/kotlin/io/element/android/app/KonsistTest.kt @@ -23,6 +23,7 @@ import com.lemonappdev.konsist.api.ext.list.constructors import com.lemonappdev.konsist.api.ext.list.modifierprovider.withoutModifier import com.lemonappdev.konsist.api.ext.list.modifierprovider.withoutOverrideModifier import com.lemonappdev.konsist.api.ext.list.parameters +import com.lemonappdev.konsist.api.ext.list.properties import com.lemonappdev.konsist.api.ext.list.withAllAnnotationsOf import com.lemonappdev.konsist.api.ext.list.withAllParentsOf import com.lemonappdev.konsist.api.ext.list.withNameEndingWith @@ -30,6 +31,7 @@ import com.lemonappdev.konsist.api.ext.list.withReturnType import com.lemonappdev.konsist.api.ext.list.withTopLevel import com.lemonappdev.konsist.api.ext.list.withoutName import com.lemonappdev.konsist.api.ext.list.withoutNameEndingWith +import com.lemonappdev.konsist.api.verify.assertFalse import com.lemonappdev.konsist.api.verify.assertTrue import io.element.android.libraries.architecture.Presenter import io.element.android.libraries.designsystem.preview.PreviewsDayNight @@ -122,4 +124,16 @@ class KonsistTest { functionDeclaration.name == "create${functionDeclaration.returnType?.name}" } } + + @Test + fun `no field should have 'm' prefix`() { + Konsist + .scopeFromProject() + .classes() + .properties() + .assertFalse { + val secondCharacterIsUppercase = it.name.getOrNull(1)?.isUpperCase() ?: false + it.name.startsWith('m') && secondCharacterIsUppercase + } + } } diff --git a/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/logs/LogFormatter.kt b/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/logs/LogFormatter.kt index e0dc1a5fbb..45c2d0a65b 100644 --- a/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/logs/LogFormatter.kt +++ b/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/logs/LogFormatter.kt @@ -28,9 +28,9 @@ import java.util.logging.LogRecord internal class LogFormatter : Formatter() { override fun format(r: LogRecord): String { - if (!mIsTimeZoneSet) { + if (!isTimeZoneSet) { DATE_FORMAT.timeZone = TimeZone.getTimeZone("UTC") - mIsTimeZoneSet = true + isTimeZoneSet = true } val thrown = r.thrown @@ -59,6 +59,6 @@ internal class LogFormatter : Formatter() { // private val DATE_FORMAT = SimpleDateFormat("MM-dd HH:mm:ss.SSS", Locale.US) private val DATE_FORMAT = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss*SSSZZZZ", Locale.US) - private var mIsTimeZoneSet = false + private var isTimeZoneSet = false } } diff --git a/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/reporter/DefaultBugReporter.kt b/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/reporter/DefaultBugReporter.kt index 46ccc7fc56..a693189d3c 100755 --- a/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/reporter/DefaultBugReporter.kt +++ b/features/rageshake/impl/src/main/kotlin/io/element/android/features/rageshake/impl/reporter/DefaultBugReporter.kt @@ -101,10 +101,10 @@ class DefaultBugReporter @Inject constructor( } // the pending bug report call - private var mBugReportCall: Call? = null + private var bugReportCall: Call? = null // boolean to cancel the bug report - private val mIsCancelled = false + private val isCancelled = false /* val adapter = MatrixJsonParser.getMoshi() @@ -151,7 +151,7 @@ class DefaultBugReporter @Inject constructor( listener: BugReporterListener? ) { // enumerate files to delete - val mBugReportFiles: MutableList = ArrayList() + val bugReportFiles: MutableList = ArrayList() try { @@ -172,7 +172,7 @@ class DefaultBugReporter @Inject constructor( val files = getLogFiles() files.mapNotNullTo(gzippedFiles) { f -> when { - mIsCancelled -> null + isCancelled -> null f.extension == "gz" -> f else -> compressFile(f) } @@ -180,7 +180,7 @@ class DefaultBugReporter @Inject constructor( files.deleteAllExceptMostRecent() } - if (!mIsCancelled && (withCrashLogs || withDevicesLogs)) { + if (!isCancelled && (withCrashLogs || withDevicesLogs)) { val gzippedLogcat = saveLogCat(false) if (null != gzippedLogcat) { @@ -215,7 +215,7 @@ class DefaultBugReporter @Inject constructor( val userId = sessionData?.userId ?: "undefined" var olmVersion = "undefined" - if (!mIsCancelled) { + if (!isCancelled) { val text = when (reportType) { ReportType.BUG_REPORT -> bugDescription ReportType.SUGGESTION -> "[Suggestion] $bugDescription" @@ -268,7 +268,7 @@ class DefaultBugReporter @Inject constructor( } } - mBugReportFiles.addAll(gzippedFiles) + bugReportFiles.addAll(gzippedFiles) if (gzippedFiles.isNotEmpty() && !uploadedSomeLogs) { serverError = "Couldn't upload any logs, please retry." @@ -336,8 +336,8 @@ class DefaultBugReporter @Inject constructor( 0 } - if (mIsCancelled && null != mBugReportCall) { - mBugReportCall!!.cancel() + if (isCancelled && null != bugReportCall) { + bugReportCall!!.cancel() } Timber.v("## onWrite() : $percentage%") @@ -360,8 +360,8 @@ class DefaultBugReporter @Inject constructor( // trigger the request try { - mBugReportCall = okHttpClient.get().newCall(request) - response = mBugReportCall!!.execute() + bugReportCall = okHttpClient.get().newCall(request) + response = bugReportCall!!.execute() responseCode = response.code } catch (e: CancellationException) { throw e @@ -423,11 +423,11 @@ class DefaultBugReporter @Inject constructor( } withContext(coroutineDispatchers.main) { - mBugReportCall = null + bugReportCall = null if (null != listener) { try { - if (mIsCancelled) { + if (isCancelled) { listener.onUploadCancelled() } else if (null == serverError) { listener.onUploadSucceed(reportURL) @@ -443,7 +443,7 @@ class DefaultBugReporter @Inject constructor( } } finally { // delete the generated files when the bug report process has finished - for (file in mBugReportFiles) { + for (file in bugReportFiles) { file.safeDelete() } } diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/push/DefaultPushHandler.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/push/DefaultPushHandler.kt index 6c9138fb15..cf5b13ce9b 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/push/DefaultPushHandler.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/push/DefaultPushHandler.kt @@ -56,7 +56,7 @@ class DefaultPushHandler @Inject constructor( private val coroutineScope = CoroutineScope(SupervisorJob()) // UI handler - private val mUIHandler by lazy { + private val uiHandler by lazy { Handler(Looper.getMainLooper()) } @@ -81,7 +81,7 @@ class DefaultPushHandler @Inject constructor( return } - mUIHandler.post { + uiHandler.post { coroutineScope.launch(Dispatchers.IO) { handleInternal(pushData) } } }