Skip to content

Commit 5e3adc6

Browse files
authored
Merge pull request #639 from square/rick/enable_ktlint_rules
enable disabled ktlint rules
2 parents 153130a + 4855b91 commit 5e3adc6

File tree

166 files changed

+2089
-2022
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+2089
-2022
lines changed

.editorconfig

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#
1010
# Some keys were manually changed:
1111
# * insert_final_newline (is false, changed to true, expected by KtLint)
12-
# * kotlin_imports_layout (see comment below, needed for KtLint)
12+
# * ktlint_ignore_back_ticked_identifier (enabled, see comment below)
1313
# * root (see comment below)
1414

1515
# Tells tools to stop searching upwards.
@@ -30,10 +30,9 @@ ij_formatter_tags_enabled = false
3030
ij_smart_tabs = false
3131
ij_wrap_on_typing = false
3232

33-
# This config is needed for KtLint. It configures the import rule order to use IntelliJ IDEA's
34-
# default style, see also:
35-
# https://github.com/pinterest/ktlint#custom-ktlint-specific-editorconfig-properties
36-
kotlin_imports_layout = *,java.**,javax.**,kotlin.**,^
33+
# Back-ticked method names are allowed to exceed the line length. That's especially helpful for
34+
# test methods with descriptive names.
35+
ktlint_ignore_back_ticked_identifier = true
3736

3837
[*.java]
3938
ij_java_align_consecutive_assignments = false

build.gradle.kts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,28 +66,6 @@ subprojects {
6666
// Default "plain" reporter is actually harder to read.
6767
reporter(ReporterType.JSON)
6868
}
69-
70-
disabledRules.set(
71-
setOf(
72-
// IntelliJ refuses to sort imports correctly.
73-
// This is a known issue: https://github.com/pinterest/ktlint/issues/527
74-
"import-ordering",
75-
76-
// We had to disable the indent and parameter-list-wrapping rules, because they lead to
77-
// false positives even in the most recent KtLint version. We created tickets:
78-
//
79-
// https://github.com/pinterest/ktlint/issues/963
80-
// https://github.com/pinterest/ktlint/issues/964
81-
// https://github.com/pinterest/ktlint/issues/965
82-
//
83-
// We can't revert the KtLint version, because they only work with Kotlin 1.3 and would
84-
// block Kotlin 1.4. We rather have a newer Kotlin version than a proper indent. The
85-
// indent rule needs to be disabled globally due to another bug:
86-
// https://github.com/pinterest/ktlint/issues/967
87-
"indent",
88-
"parameter-list-wrapping"
89-
)
90-
)
9169
}
9270
}
9371

internal-testing-utils/src/main/java/com/squareup/workflow1/internal/util/UncaughtExceptionGuard.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class UncaughtExceptionGuard {
4040

4141
// If the block completed successfully, but an uncaught exception was reported, report it now.
4242
uncaughtException.get()
43-
?.let { throw it }
43+
?.let { throw it }
4444

4545
return result
4646
}

internal-testing-utils/src/test/java/com/squareup/workflow1/internal/util/UncaughtExceptionGuardTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class UncaughtExceptionGuardTest {
4747
try {
4848
rethrowingUncaughtExceptions {
4949
Thread.getDefaultUncaughtExceptionHandler()
50-
.uncaughtException(Thread.currentThread(), RuntimeException("fail"))
50+
.uncaughtException(Thread.currentThread(), RuntimeException("fail"))
5151
}
5252
fail("Expected exception.")
5353
} catch (e: RuntimeException) {
@@ -67,7 +67,7 @@ class UncaughtExceptionGuardTest {
6767
// Wait for all the other threads are also ready…
6868
startLatch.await()
6969
Thread.getDefaultUncaughtExceptionHandler()
70-
.uncaughtException(Thread.currentThread(), RuntimeException("fail $i"))
70+
.uncaughtException(Thread.currentThread(), RuntimeException("fail $i"))
7171
finishedLatch.countDown()
7272
}.start()
7373
}

samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposebinding/HelloBindingActivity.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,22 @@ class HelloBindingActivity : AppCompatActivity() {
3535

3636
val model: HelloBindingModel by viewModels()
3737
setContentView(
38-
WorkflowLayout(this).apply {
39-
start(
40-
renderings = model.renderings,
41-
environment = viewEnvironment
42-
)
43-
}
38+
WorkflowLayout(this).apply {
39+
start(
40+
renderings = model.renderings,
41+
environment = viewEnvironment
42+
)
43+
}
4444
)
4545
}
4646

4747
class HelloBindingModel(savedState: SavedStateHandle) : ViewModel() {
4848
@OptIn(WorkflowUiExperimentalApi::class)
4949
val renderings: StateFlow<Any> by lazy {
5050
renderWorkflowIn(
51-
workflow = HelloWorkflow,
52-
scope = viewModelScope,
53-
savedStateHandle = savedState
51+
workflow = HelloWorkflow,
52+
scope = viewModelScope,
53+
savedStateHandle = savedState
5454
)
5555
}
5656
}

samples/compose-samples/src/main/java/com/squareup/sample/compose/hellocomposeworkflow/ComposeWorkflowImpl.kt

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import androidx.compose.runtime.Composable
44
import androidx.compose.runtime.MutableState
55
import androidx.compose.runtime.mutableStateOf
66
import androidx.compose.runtime.structuralEqualityPolicy
7+
import com.squareup.sample.compose.hellocomposeworkflow.ComposeWorkflowImpl.State
78
import com.squareup.workflow1.Sink
89
import com.squareup.workflow1.Snapshot
910
import com.squareup.workflow1.StatefulWorkflow
1011
import com.squareup.workflow1.action
1112
import com.squareup.workflow1.contraMap
1213
import com.squareup.workflow1.ui.ViewEnvironment
1314
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi
14-
import com.squareup.sample.compose.hellocomposeworkflow.ComposeWorkflowImpl.State
1515
import com.squareup.workflow1.ui.compose.ComposeRendering
1616

1717
@WorkflowUiExperimentalApi
@@ -35,15 +35,18 @@ internal class ComposeWorkflowImpl<PropsT, OutputT : Any>(
3535
val propsHolder = mutableStateOf(props, policy = structuralEqualityPolicy())
3636
val sinkHolder = SinkHolder<OutputT>()
3737

38-
return State(propsHolder, sinkHolder, object : ComposeRendering {
39-
@Composable override fun Content(viewEnvironment: ViewEnvironment) {
40-
// The sink will get set on the first render pass, which must happen before this is first
41-
// composed, so it should never be null.
42-
val sink = sinkHolder.sink!!
43-
// Important: Use the props from the MutableState, _not_ the one passed into render.
44-
workflow.RenderingContent(propsHolder.value, sink, viewEnvironment)
38+
return State(
39+
propsHolder, sinkHolder,
40+
object : ComposeRendering {
41+
@Composable override fun Content(viewEnvironment: ViewEnvironment) {
42+
// The sink will get set on the first render pass, which must happen before this is first
43+
// composed, so it should never be null.
44+
val sink = sinkHolder.sink!!
45+
// Important: Use the props from the MutableState, _not_ the one passed into render.
46+
workflow.RenderingContent(propsHolder.value, sink, viewEnvironment)
47+
}
4548
}
46-
})
49+
)
4750
}
4851

4952
override fun onPropsChanged(

samples/compose-samples/src/main/java/com/squareup/sample/compose/inlinerendering/InlineRenderingWorkflow.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ object InlineRenderingWorkflow : StatefulWorkflow<Unit, Int, Nothing, AndroidVie
6565
AnimatedContent(
6666
targetState = counterValue,
6767
transitionSpec = {
68-
(slideInVertically() + fadeIn() with
69-
slideOutVertically() + fadeOut())
68+
(
69+
slideInVertically() + fadeIn() with
70+
slideOutVertically() + fadeOut()
71+
)
7072
.using(SizeTransform(clip = false))
7173
}
7274
) { content(it) }

samples/compose-samples/src/main/java/com/squareup/sample/compose/launcher/SampleLauncherApp.kt

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ import com.squareup.sample.compose.R
4545
@Composable fun SampleLauncherApp() {
4646
MaterialTheme(colors = darkColors()) {
4747
Scaffold(
48-
topBar = {
49-
TopAppBar(title = {
50-
Text(stringResource(R.string.app_name))
51-
})
52-
}
48+
topBar = {
49+
TopAppBar(title = {
50+
Text(stringResource(R.string.app_name))
51+
})
52+
}
5353
) {
5454
LazyColumn {
5555
items(samples) {
@@ -75,12 +75,12 @@ import com.squareup.sample.compose.R
7575
val globalBounds = remember { Ref<Rect>() }
7676

7777
ListItem(
78-
text = { Text(sample.name) },
79-
secondaryText = { Text(sample.description) },
80-
singleLineSecondaryText = false,
81-
// Animate the activities as scaling up from where the preview is drawn.
82-
icon = { SamplePreview(sample) { globalBounds.value = it.boundsInRoot() } },
83-
modifier = Modifier.clickable { launchSample(sample, rootView, globalBounds.value) }
78+
text = { Text(sample.name) },
79+
secondaryText = { Text(sample.description) },
80+
singleLineSecondaryText = false,
81+
// Animate the activities as scaling up from where the preview is drawn.
82+
icon = { SamplePreview(sample) { globalBounds.value = it.boundsInRoot() } },
83+
modifier = Modifier.clickable { launchSample(sample, rootView, globalBounds.value) }
8484
)
8585
}
8686

@@ -100,24 +100,24 @@ import com.squareup.sample.compose.R
100100
// the measurements here otherwise the rest of the UI will think the previews are full-size even
101101
// though they're graphically scaled down.
102102
Box(
103-
modifier = Modifier
104-
.height(previewHeight)
105-
.aspectRatio(screenRatio)
106-
.onGloballyPositioned(onPreviewCoordinates)
103+
modifier = Modifier
104+
.height(previewHeight)
105+
.aspectRatio(screenRatio)
106+
.onGloballyPositioned(onPreviewCoordinates)
107107
) {
108108
// Preview the samples with a light theme, since that's what most of them use.
109109
MaterialTheme(lightColors()) {
110110
Surface {
111111
Box(
112-
modifier = Modifier
113-
// This preview isn't meant to be interactive.
114-
.disableTouchInput()
115-
// Measure/layout the child at full screen size, and then just scale the pixels
116-
// down. This way all the text and other density-dependent things get scaled
117-
// correctly too.
118-
.requiredHeight(configuration.screenHeightDp.dp)
119-
.requiredWidth(configuration.screenWidthDp.dp)
120-
.graphicsLayer(scaleX = scale, scaleY = scale)
112+
modifier = Modifier
113+
// This preview isn't meant to be interactive.
114+
.disableTouchInput()
115+
// Measure/layout the child at full screen size, and then just scale the pixels
116+
// down. This way all the text and other density-dependent things get scaled
117+
// correctly too.
118+
.requiredHeight(configuration.screenHeightDp.dp)
119+
.requiredWidth(configuration.screenWidthDp.dp)
120+
.graphicsLayer(scaleX = scale, scaleY = scale)
121121
) {
122122
sample.preview()
123123
}
@@ -135,11 +135,11 @@ private fun launchSample(
135135
val intent = Intent(context, sample.activityClass.java)
136136
val options: Bundle? = sourceBounds?.let {
137137
makeScaleUpAnimation(
138-
rootView,
139-
it.left.toInt(),
140-
it.top.toInt(),
141-
it.width.toInt(),
142-
it.height.toInt()
138+
rootView,
139+
it.left.toInt(),
140+
it.top.toInt(),
141+
it.width.toInt(),
142+
it.height.toInt()
143143
).toBundle()
144144
}
145145
startActivity(context, intent, options)

samples/compose-samples/src/main/java/com/squareup/sample/compose/launcher/Samples.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ package com.squareup.sample.compose.launcher
44

55
import androidx.activity.ComponentActivity
66
import androidx.compose.runtime.Composable
7-
import com.squareup.sample.compose.hellocomposeworkflow.HelloComposeWorkflowActivity
8-
import com.squareup.sample.compose.hellocomposeworkflow.HelloComposeWorkflowPreview
97
import com.squareup.sample.compose.hellocompose.App
108
import com.squareup.sample.compose.hellocompose.HelloComposeActivity
119
import com.squareup.sample.compose.hellocomposebinding.DrawHelloRenderingPreview
1210
import com.squareup.sample.compose.hellocomposebinding.HelloBindingActivity
11+
import com.squareup.sample.compose.hellocomposeworkflow.HelloComposeWorkflowActivity
12+
import com.squareup.sample.compose.hellocomposeworkflow.HelloComposeWorkflowPreview
1313
import com.squareup.sample.compose.inlinerendering.InlineRenderingActivity
1414
import com.squareup.sample.compose.inlinerendering.InlineRenderingWorkflowPreview
1515
import com.squareup.sample.compose.nestedrenderings.NestedRenderingsActivity

samples/compose-samples/src/main/java/com/squareup/sample/compose/nestedrenderings/RecursiveViewFactory.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ val RecursiveViewFactory = composeViewFactory<Rendering> { rendering, viewEnviro
8080
children = listOf("bar"),
8181
onAddChildClicked = {}, onResetClicked = {}
8282
)
83-
), onAddChildClicked = {}, onResetClicked = {}
83+
),
84+
onAddChildClicked = {}, onResetClicked = {}
8485
),
8586
placeholderModifier = Modifier.fillMaxSize()
8687
)

0 commit comments

Comments
 (0)