Skip to content

Update ktlint to version 1.5.0 #3533

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

Merged
merged 3 commits into from
Apr 24, 2025
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
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[*.{kt,kts}]
ij_kotlin_allow_trailing_comma_on_call_site=true
ij_kotlin_allow_trailing_comma=true

[*]
insert_final_newline = true

# rules we should look into enabling
ktlint_standard_blank-line-before-declaration = disabled
ktlint_standard_chain-method-continuation = disabled
ktlint_standard_class-signature = disabled
ktlint_standard_function-expression-body = disabled
ktlint_standard_function-naming = disabled
ktlint_standard_function-signature = disabled
ktlint_standard_indent = disabled
ktlint_standard_multiline-expression-wrapping = disabled
ktlint_standard_no-empty-first-line-in-class-body = disabled
ktlint_standard_string-template-indent = disabled
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import org.mozilla.reference.browser.BrowserActivity
class BrowserActivityTestRule(
initialTouchMode: Boolean = false,
launchActivity: Boolean = true,

) : ActivityTestRule<BrowserActivity>(BrowserActivity::class.java, initialTouchMode, launchActivity) {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class AndroidAssetDispatcher : Dispatcher() {
assetManager.open(pathWithoutQueryParams!!).use { inputStream ->
return fileToResponse(pathWithoutQueryParams, inputStream)
}
} catch (e: IOException) { // e.g. file not found.
} catch (e: IOException) {
// e.g. file not found.
// We're on a background thread so we need to forward the exception to the main thread.
mainThreadHandler.postAtFrontOfQueue { throw e }
return MockResponse().setResponseCode(HTTP_NOT_FOUND)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CustomTabsTest {
@get:Rule
val activityTestRule = BrowserActivityTestRule()

@get: Rule
@get:Rule
val intentReceiverActivityTestRule = ActivityTestRule(
IntentReceiverActivity::class.java,
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import androidx.preference.Preference
import androidx.preference.PreferenceViewHolder
import org.mozilla.reference.browser.R

class AutofillPreference @JvmOverloads constructor(
class AutofillPreference
@JvmOverloads
constructor(
context: Context,
attrs: AttributeSet? = null,
) : Preference(context, attrs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
fullScreenFeature,
findInPageIntegration,
toolbarIntegration,

sessionFeature,
lastTabFeature,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,24 +102,20 @@ class CustomTabsIntegration(
private fun menuItems(sessionState: SessionState?): List<MenuCandidate> {
return listOf(
menuToolbar(session),

TextMenuCandidate("Share") {
val url = sessionState?.content?.url.orEmpty()
context.share(url)
},

CompoundMenuCandidate(
text = "Request desktop site",
isChecked = sessionState?.content?.desktopMode == true,
end = CompoundMenuCandidate.ButtonType.SWITCH,
) { checked ->
sessionUseCases.requestDesktopSite.invoke(checked, sessionState?.id)
},

TextMenuCandidate("Find in Page") {
FindInPageIntegration.launch?.invoke()
},

TextMenuCandidate("Open in Browser") {
// Release the session from this view so that it can immediately be rendered by a different view
engineView.release()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class ExternalAppBrowserFragment : BaseBrowserFragment(), UserInteractionHandler
) { toolbarVisible ->
toolbar.isVisible = toolbarVisible
webAppToolbarShouldBeVisible = toolbarVisible
if (!toolbarVisible) { engineView.setDynamicToolbarMaxHeight(0) }
if (!toolbarVisible) engineView.setDynamicToolbarMaxHeight(0)
},
owner = this,
view = toolbar,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,17 @@ class ToolbarIntegration(
private fun sessionMenuItems(sessionState: SessionState): List<MenuCandidate> {
return listOfNotNull(
menuToolbar(sessionState),

TextMenuCandidate("Share") {
val url = sessionState.content.url
context.share(url)
},

CompoundMenuCandidate(
text = "Request desktop site",
isChecked = sessionState.content.desktopMode,
end = CompoundMenuCandidate.ButtonType.SWITCH,
) { checked ->
sessionUseCases.requestDesktopSite.invoke(checked)
},

if (webAppUseCases.isPinningSupported()) {
TextMenuCandidate(
text = "Add to homescreen",
Expand All @@ -131,7 +128,6 @@ class ToolbarIntegration(
} else {
null
},

TextMenuCandidate(
text = "Find in Page",
) {
Expand All @@ -153,19 +149,16 @@ class ToolbarIntegration(
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
context.startActivity(intent)
},

TextMenuCandidate(text = "Synced Tabs") {
val intent = Intent(context, SyncedTabsActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
context.startActivity(intent)
},

TextMenuCandidate(text = "Report issue") {
tabsUseCases.addTab(
url = "https://github.com/mozilla-mobile/reference-browser/issues/new",
)
},

TextMenuCandidate(text = "Settings") {
val intent = Intent(context, SettingsActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ class Services(
FirefoxAccountsAuthFeature(
accountManager,
redirectUrl = BackgroundServices.REDIRECT_URL,
) {
_, authUrl ->
) { _, authUrl ->
MainScope().launch {
tabsUseCases.addTab.invoke(authUrl)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ val Context.application: BrowserApplication
val Context.components: Components
get() = application.components

fun Context.getPreferenceKey(@StringRes resourceId: Int): String =
fun Context.getPreferenceKey(
@StringRes resourceId: Int,
): String =
resources.getString(resourceId)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import org.mozilla.reference.browser.ext.components
* implementation to be integrated as a `View` until more parts of the app have been refactored to
* use Jetpack Compose.
*/
class AwesomeBarWrapper @JvmOverloads constructor(
class AwesomeBarWrapper
@JvmOverloads
constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import org.mozilla.reference.browser.R
* This preference is used to define custom colors for both title and summary texts.
* Color code #777777 (placeholder_grey) is used as the fallback color for both title and summary.
*/
class CustomColorPreference @JvmOverloads constructor(
class CustomColorPreference
@JvmOverloads
constructor(
context: Context,
attrs: AttributeSet? = null,
defStyle: Int = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import com.google.android.material.tabs.TabLayout
import mozilla.components.feature.tabs.tabstray.TabsFeature
import org.mozilla.reference.browser.R

class TabsPanel @JvmOverloads constructor(
class TabsPanel
@JvmOverloads
constructor(
context: Context,
attrs: AttributeSet? = null,
) : TabLayout(context, attrs), TabLayout.OnTabSelectedListener {
Expand Down Expand Up @@ -73,10 +75,14 @@ class TabsPanel @JvmOverloads constructor(
tab?.icon?.colorFilter = null
}

private fun Resources.getThemedDrawable(@DrawableRes resId: Int) =
private fun Resources.getThemedDrawable(
@DrawableRes resId: Int,
) =
ResourcesCompat.getDrawable(resources, resId, context.theme)

private fun Drawable.colorTint(@ColorRes color: Int) = apply {
private fun Drawable.colorTint(
@ColorRes color: Int,
) = apply {
mutate()
colorFilter = createBlendModeColorFilterCompat(ContextCompat.getColor(context, color), SRC_IN)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import mozilla.components.feature.tabs.tabstray.TabsFeature
import org.mozilla.reference.browser.R
import org.mozilla.reference.browser.ext.components

class TabsToolbar @JvmOverloads constructor(
class TabsToolbar
@JvmOverloads
constructor(
context: Context,
attrs: AttributeSet? = null,
) : androidx.appcompat.widget.Toolbar(context, attrs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ import mozilla.components.feature.syncedtabs.view.SyncedTabsView.ErrorType.SYNC_
import mozilla.components.feature.syncedtabs.view.SyncedTabsView.ErrorType.SYNC_UNAVAILABLE
import org.mozilla.reference.browser.R

class SyncedTabsLayout @JvmOverloads constructor(
class SyncedTabsLayout
@JvmOverloads
constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
) : FrameLayout(context, attrs, defStyleAttr), SyncedTabsView {

override var listener: SyncedTabsView.Listener? = null

private val adapter = SyncedTabsAdapter() { listener?.onTabClicked(it) }
private val adapter = SyncedTabsAdapter { listener?.onTabClicked(it) }

private val syncedTabsList: RecyclerView
get() = findViewById(R.id.synced_tabs_list)
Expand Down
4 changes: 2 additions & 2 deletions config/detekt-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" ?>
<SmellBaseline>
<ManuallySuppressedIssues></ManuallySuppressedIssues>
<ManuallySuppressedIssues/>
<CurrentIssues>
<ID>UndocumentedPublicClass:AboutFragment.kt$AboutFragment : Fragment</ID>
<ID>UndocumentedPublicClass:AccountSettingsFragment.kt$AccountSettingsFragment : PreferenceFragmentCompat</ID>
Expand Down Expand Up @@ -72,7 +72,7 @@
<ID>UndocumentedPublicFunction:ComposableComponents.kt$@Composable fun sessionUseCases(): SessionUseCases</ID>
<ID>UndocumentedPublicFunction:Config.kt$Config$@JvmStatic fun generateDebugVersionName(): String</ID>
<ID>UndocumentedPublicFunction:Config.kt$Config$@JvmStatic fun releaseVersionName(project: Project): String</ID>
<ID>UndocumentedPublicFunction:Context.kt$fun Context.getPreferenceKey(@StringRes resourceId: Int): String</ID>
<ID>UndocumentedPublicFunction:Context.kt$fun Context.getPreferenceKey( @StringRes resourceId: Int, ): String</ID>
<ID>UndocumentedPublicFunction:CrashIntegration.kt$CrashIntegration$@OptIn(DelicateCoroutinesApi::class) fun sendCrashReport(crash: Crash)</ID>
<ID>UndocumentedPublicFunction:EngineProvider.kt$EngineProvider$@Synchronized fun getOrCreateRuntime(context: Context): GeckoRuntime</ID>
<ID>UndocumentedPublicFunction:EngineProvider.kt$EngineProvider$fun createClient(context: Context): Client</ID>
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ androidx-test-uiautomator = "2.3.0"
dependency-analysis = "2.15.0"
detekt = "1.23.8"
jspecify = "1.0.0"
ktlint = "0.50.0"
ktlint = "1.5.0"

# Third Party Testing
hamcrest = "1.3"
Expand Down Expand Up @@ -99,7 +99,7 @@ androidx-test-uiautomator = { group = "androidx.test.uiautomator", name = "uiaut

# Third Party Linting & Static Code Analysis
jspecify = { group = "org.jspecify", name = "jspecify", version.ref = "jspecify" }
ktlint = { module = "com.pinterest:ktlint", version.ref = "ktlint" }
ktlint = { group = "com.pinterest.ktlint", name = "ktlint-cli", version.ref = "ktlint" }

# Third Party Testing
hamcrest-core = { group = "org.hamcrest", name = "hamcrest-core", version.ref = "hamcrest" }
Expand Down