Skip to content

Commit 9d4d538

Browse files
author
m.zharinova
committed
добавлены правила для детекта
1 parent 0fb8929 commit 9d4d538

File tree

8 files changed

+268
-36
lines changed

8 files changed

+268
-36
lines changed

buildSrc/src/main/kotlin/sb-ot-demo.kotlin-conventions.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ detekt {
4141
toolVersion = versionCatalog.findVersion("detekt").get().requiredVersion
4242
config.setFrom(file("${rootDir}/config/detekt/detekt.yml"))
4343
buildUponDefaultConfig = true
44+
autoCorrect = true
4445
}
4546

4647
tasks {

config/detekt/detekt.yml

Lines changed: 214 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,219 @@ performance:
22
SpreadOperator:
33
active: false
44

5+
formatting:
6+
active: true
7+
android: false
8+
AnnotationOnSeparateLine:
9+
active: false
10+
ChainWrapping:
11+
active: true
12+
CommentSpacing:
13+
active: true
14+
Filename:
15+
active: true
16+
FinalNewline:
17+
active: true
18+
ImportOrdering:
19+
active: false
20+
Indentation:
21+
active: true
22+
indentSize: 4
23+
# continuationIndentSize: 4
24+
MaximumLineLength:
25+
active: true
26+
maxLineLength: 240
27+
ModifierOrdering:
28+
active: true
29+
MultiLineIfElse:
30+
active: true
31+
NoBlankLineBeforeRbrace:
32+
active: true
33+
NoConsecutiveBlankLines:
34+
active: true
35+
NoEmptyClassBody:
36+
active: true
37+
NoLineBreakAfterElse:
38+
active: true
39+
NoLineBreakBeforeAssignment:
40+
active: true
41+
NoMultipleSpaces:
42+
active: true
43+
NoSemicolons:
44+
active: true
45+
NoTrailingSpaces:
46+
active: true
47+
NoUnitReturn:
48+
active: true
49+
NoUnusedImports:
50+
active: true
51+
NoWildcardImports:
52+
active: true
53+
PackageName:
54+
active: true
55+
ParameterListWrapping:
56+
active: true
57+
# indentSize: 4
58+
SpacingAroundColon:
59+
active: true
60+
SpacingAroundComma:
61+
active: true
62+
SpacingAroundCurly:
63+
active: true
64+
SpacingAroundDot:
65+
active: true
66+
SpacingAroundKeyword:
67+
active: true
68+
SpacingAroundOperators:
69+
active: true
70+
SpacingAroundParens:
71+
active: true
72+
SpacingAroundRangeOperator:
73+
active: true
74+
StringTemplate:
75+
active: true
76+
577
style:
78+
active: true
79+
CollapsibleIfStatements:
80+
active: false
81+
DataClassContainsFunctions:
82+
active: false
83+
conversionFunctionPrefix: ['to']
84+
DataClassShouldBeImmutable:
85+
active: false
86+
EqualsNullCall:
87+
active: true
88+
EqualsOnSignatureLine:
89+
active: false
90+
ExplicitItLambdaParameter:
91+
active: false
92+
ExpressionBodySyntax:
93+
active: false
94+
includeLineWrapping: false
95+
ForbiddenComment:
96+
active: false
97+
comments: [ 'TODO:','FIXME:','STOPSHIP:' ]
98+
allowedPatterns: ""
99+
ForbiddenImport:
100+
active: false
101+
imports: [ ]
102+
forbiddenPatterns: ""
103+
ForbiddenVoid:
104+
active: false
105+
ignoreOverridden: false
106+
ignoreUsageInGenerics: false
107+
FunctionOnlyReturningConstant:
108+
active: true
109+
ignoreOverridableFunction: true
110+
excludedFunctions: [ 'describeContents' ]
111+
LoopWithTooManyJumpStatements:
112+
active: true
113+
maxJumpCount: 1
114+
MagicNumber:
115+
active: true
116+
excludes: [ "**/test/**","**/*.Test.kt","**/*.Spec.kt","**/*.Spek.kt","**/*Properties.kt","**/*Configuration.kt" ]
117+
ignoreNumbers: [ '-1','0','1','2' ]
118+
ignoreHashCodeFunction: true
119+
ignorePropertyDeclaration: false
120+
ignoreLocalVariableDeclaration: false
121+
ignoreConstantDeclaration: true
122+
ignoreCompanionObjectPropertyDeclaration: true
123+
ignoreAnnotation: false
124+
ignoreNamedArgument: true
125+
ignoreEnums: false
126+
ignoreRanges: false
6127
MaxLineLength:
7-
maxLineLength: 200
128+
active: true
129+
maxLineLength: 240
130+
excludePackageStatements: true
131+
excludeImportStatements: true
132+
excludeCommentStatements: false
133+
MayBeConst:
134+
active: true
135+
ModifierOrder:
136+
active: true
137+
NestedClassesVisibility:
138+
active: false
139+
NewLineAtEndOfFile:
140+
active: true
141+
NoTabs:
142+
active: true
143+
OptionalAbstractKeyword:
144+
active: true
145+
OptionalUnit:
146+
active: false
147+
PreferToOverPairSyntax:
148+
active: true
149+
ProtectedMemberInFinalClass:
150+
active: true
151+
RedundantExplicitType:
152+
active: false
153+
RedundantVisibilityModifierRule:
154+
active: true
155+
ReturnCount:
156+
active: true
157+
max: 2
158+
excludedFunctions: [ "equals" ]
159+
excludeLabeled: false
160+
excludeReturnFromLambda: true
161+
excludeGuardClauses: false
162+
SafeCast:
163+
active: true
164+
SerialVersionUIDInSerializableClass:
165+
active: false
166+
SpacingBetweenPackageAndImports:
167+
active: false
168+
ThrowsCount:
169+
active: true
170+
max: 2
171+
TrailingWhitespace:
172+
active: false
173+
UnderscoresInNumericLiterals:
174+
active: false
175+
acceptableLength: 5
176+
UnnecessaryAbstractClass:
177+
active: false
178+
UnnecessaryApply:
179+
active: false
180+
UnnecessaryInheritance:
181+
active: true
182+
UnnecessaryLet:
183+
active: false
184+
UnnecessaryParentheses:
185+
active: false
186+
UntilInsteadOfRangeTo:
187+
active: false
188+
UnusedImports:
189+
active: true
190+
UnusedPrivateClass:
191+
active: true
192+
UnusedPrivateMember:
193+
active: true
194+
allowedNames: "(_|ignored|expected|serialVersionUID)"
195+
UseArrayLiteralsInAnnotations:
196+
active: false
197+
UseCheckOrError:
198+
active: false
199+
UseDataClass:
200+
active: false
201+
ignoreAnnotated: [ ]
202+
allowVars: false
203+
UseIfInsteadOfWhen:
204+
active: false
205+
UseRequire:
206+
active: false
207+
UselessCallOnNotNull:
208+
active: true
209+
UtilityClassWithPublicConstructor:
210+
active: true
211+
VarCouldBeVal:
212+
active: false
213+
WildcardImport:
214+
active: true
215+
216+
libraries:
217+
LibraryEntitiesShouldNotBePublic:
218+
active: false
219+
ForbiddenPublicDataClass:
220+
active: false

spring-boot-3-demo-app-kotlin/src/main/kotlin/io/github/mfvanek/spring/boot3/kotlin/test/service/PublicApiService.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ class PublicApiService(
5959
.doBeforeRetry { retrySignal: Retry.RetrySignal ->
6060
withLoggingContext("instance_timezone" to zoneName) {
6161
logger.info {
62-
"Retrying request to '/$zoneName', attempt ${retrySignal.totalRetries() + 1}/$retries due to error: ${retrySignal.failure()}"
62+
"Retrying request to '/$zoneName', attempt ${retrySignal.totalRetries() + 1}/$retries " +
63+
"due to error: ${retrySignal.failure()}"
6364
}
6465
}
6566
}

spring-boot-3-demo-app-kotlin/src/test/kotlin/io/github/mfvanek/spring/boot3/kotlin/test/ActuatorEndpointTest.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@ class ActuatorEndpointTest : TestBase() {
3737

3838
@ParameterizedTest
3939
@CsvSource(
40-
value = ["prometheus|jvm_threads_live_threads|text/plain", "health|{\"status\":\"UP\",\"groups\":[\"liveness\",\"readiness\"]}|application/json",
41-
"health/liveness|{\"status\":\"UP\"}|application/json", "health/readiness|{\"status\":\"UP\"}|application/json", "info|\"version\":|application/json"],
40+
value = [
41+
"prometheus|jvm_threads_live_threads|text/plain",
42+
"health|{\"status\":\"UP\",\"groups\":[\"liveness\",\"readiness\"]}|application/json",
43+
"health/liveness|{\"status\":\"UP\"}|application/json",
44+
"health/readiness|{\"status\":\"UP\"}|application/json", "info|\"version\":|application/json"
45+
],
4246
delimiter = '|'
4347
)
4448
fun actuatorEndpointShouldReturnOk(

spring-boot-3-demo-app-kotlin/src/test/kotlin/io/github/mfvanek/spring/boot3/kotlin/test/ApplicationTests.kt

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ import io.micrometer.tracing.Span
77
import io.micrometer.tracing.Tracer
88
import io.micrometer.tracing.otel.bridge.OtelTracer
99
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter
10-
import org.assertj.core.api.Assertions.*
10+
import java.util.Locale
11+
import org.assertj.core.api.Assertions.assertThat
12+
import org.assertj.core.api.Assertions.assertThatNoException
13+
import org.assertj.core.api.Assertions.assertThatThrownBy
1114
import org.assertj.core.api.ThrowingConsumer
1215
import org.junit.jupiter.api.DisplayName
1316
import org.junit.jupiter.api.Test
1417
import org.springframework.beans.factory.annotation.Autowired
1518
import org.springframework.context.ApplicationContext
1619
import org.springframework.dao.DataAccessResourceFailureException
17-
import java.util.*
1820

1921
class ApplicationTests : TestBase() {
2022
@Autowired
@@ -30,18 +32,22 @@ class ApplicationTests : TestBase() {
3032
assertThat(applicationContext.getBean(Tracer::class.java))
3133
.isNotNull()
3234
.isInstanceOf(OtelTracer::class.java)
33-
.satisfies(ThrowingConsumer { t: Tracer ->
34-
assertThat(t.currentSpan())
35-
.isNotEqualTo(Span.NOOP)
36-
})
35+
.satisfies(
36+
ThrowingConsumer { t: Tracer ->
37+
assertThat(t.currentSpan())
38+
.isNotEqualTo(Span.NOOP)
39+
}
40+
)
3741
assertThat(applicationContext.getBean("otelJaegerGrpcSpanExporter"))
3842
.isNotNull()
3943
.isInstanceOf(OtlpGrpcSpanExporter::class.java)
4044
.hasToString(
4145
String.format(
42-
Locale.ROOT, """
43-
OtlpGrpcSpanExporter{exporterName=otlp, type=span, endpoint=http://localhost:%d, endpointPath=/opentelemetry.proto.collector.trace.v1.TraceService/Export, timeoutNanos=5000000000, connectTimeoutNanos=10000000000, compressorEncoding=null, headers=Headers{User-Agent=OBFUSCATED}, retryPolicy=RetryPolicy{maxAttempts=5, initialBackoff=PT1S, maxBackoff=PT5S, backoffMultiplier=1.5}, memoryMode=IMMUTABLE_DATA}
44-
""".trimIndent(), JaegerInitializer.getFirstMappedPort()
46+
Locale.ROOT,
47+
"""
48+
OtlpGrpcSpanExporter{exporterName=otlp, type=span, endpoint=http://localhost:%d, endpointPath=/opentelemetry.proto.collector.trace.v1.TraceService/Export, timeoutNanos=5000000000, connectTimeoutNanos=10000000000, compressorEncoding=null, headers=Headers{User-Agent=OBFUSCATED}, retryPolicy=RetryPolicy{maxAttempts=5, initialBackoff=PT1S, maxBackoff=PT5S, backoffMultiplier=1.5}, memoryMode=IMMUTABLE_DATA}
49+
""".trimIndent(),
50+
JaegerInitializer.getFirstMappedPort()
4551
)
4652
)
4753
}

spring-boot-3-demo-app-kotlin/src/test/kotlin/io/github/mfvanek/spring/boot3/kotlin/test/controllers/TimeControllerTest.kt

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ import io.github.mfvanek.spring.boot3.kotlin.test.filters.TraceIdInResponseServl
44
import io.github.mfvanek.spring.boot3.kotlin.test.service.dto.toParsedDateTime
55
import io.github.mfvanek.spring.boot3.kotlin.test.support.KafkaInitializer
66
import io.github.mfvanek.spring.boot3.kotlin.test.support.TestBase
7+
import java.nio.charset.StandardCharsets
8+
import java.time.Duration
9+
import java.time.LocalDateTime
10+
import java.time.temporal.ChronoUnit
11+
import java.util.Locale
12+
import java.util.UUID
13+
import java.util.concurrent.BlockingQueue
14+
import java.util.concurrent.LinkedBlockingQueue
15+
import java.util.concurrent.TimeUnit
716
import org.apache.kafka.clients.CommonClientConfigs
817
import org.apache.kafka.clients.consumer.ConsumerConfig
918
import org.apache.kafka.clients.consumer.ConsumerRecord
@@ -29,15 +38,6 @@ import org.springframework.kafka.listener.MessageListener
2938
import org.springframework.kafka.test.utils.ContainerTestUtils
3039
import org.springframework.kafka.test.utils.KafkaTestUtils
3140
import org.testcontainers.shaded.org.awaitility.Awaitility
32-
import java.nio.charset.StandardCharsets
33-
import java.time.Duration
34-
import java.time.LocalDateTime
35-
import java.time.temporal.ChronoUnit
36-
import java.util.Locale
37-
import java.util.UUID
38-
import java.util.concurrent.BlockingQueue
39-
import java.util.concurrent.LinkedBlockingQueue
40-
import java.util.concurrent.TimeUnit
4141

4242
@ExtendWith(OutputCaptureExtension::class)
4343
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@@ -119,7 +119,8 @@ class TimeControllerTest : TestBase() {
119119
.containsPattern(
120120
String.format(
121121
Locale.ROOT,
122-
".*\"message\":\"Request to '/%s' failed after 2 attempts.\",\"logger\":\"io\\.github\\.mfvanek\\.spring\\.boot3\\.kotlin\\.test\\.service\\.PublicApiService\"," +
122+
".*\"message\":\"Request to '/%s' failed after 2 attempts.\"," +
123+
"\"logger\":\"io\\.github\\.mfvanek\\.spring\\.boot3\\.kotlin\\.test\\.service\\.PublicApiService\"," +
123124
"\"thread\":\"[^\"]+\",\"level\":\"ERROR\"," +
124125
"\"traceId\":\"38c19768104ab8ae64fabbeed65bbbdf\",\"spanId\":\"[a-f0-9]+\",\"applicationName\":\"spring-boot-3-demo-app\"\\}%n",
125126
zoneName
@@ -128,13 +129,13 @@ class TimeControllerTest : TestBase() {
128129
.containsPattern(
129130
String.format(
130131
Locale.ROOT,
131-
".*\"message\":\"Request to '/%s' failed after 2 attempts.\",\"logger\":\"io\\.github\\.mfvanek\\.spring\\.boot3\\.kotlin\\.test\\.service\\.PublicApiService\"," +
132+
".*\"message\":\"Request to '/%s' failed after 2 attempts.\"," +
133+
"\"logger\":\"io\\.github\\.mfvanek\\.spring\\.boot3\\.kotlin\\.test\\.service\\.PublicApiService\"," +
132134
"\"thread\":\"[^\"]+\",\"level\":\"ERROR\"," +
133135
"\"traceId\":\"38c19768104ab8ae64fabbeed65bbbdf\",\"spanId\":\"[a-f0-9]+\",\"applicationName\":\"spring-boot-3-demo-app\"\\}%n",
134136
zoneName
135137
).toPattern()
136138
)
137-
138139
}
139140

140141
@Order(3)
@@ -161,12 +162,12 @@ class TimeControllerTest : TestBase() {
161162
}
162163

163164
private fun assertThatTraceIdPresentInKafkaHeaders(received: ConsumerRecord<UUID, String>, expectedTraceId: String) {
164-
assertThat(received.value()).startsWith("Current time = ");
165+
assertThat(received.value()).startsWith("Current time = ")
165166
val headers = received.headers().toArray()
166167
val headerNames = headers.map { it.key() }
167168
assertThat(headerNames)
168169
.hasSize(2)
169-
.containsExactlyInAnyOrder("traceparent", "b3");
170+
.containsExactlyInAnyOrder("traceparent", "b3")
170171
val headerValues = headers
171172
.map { String(it.value(), StandardCharsets.UTF_8) }
172173
assertThat(headerValues)
@@ -185,7 +186,7 @@ class TimeControllerTest : TestBase() {
185186

186187
private fun setUpKafkaConsumer(kafkaProperties: KafkaProperties, consumerRecords: BlockingQueue<ConsumerRecord<UUID, String>>): KafkaMessageListenerContainer<UUID, String> {
187188
val containerProperties = ContainerProperties(kafkaProperties.template.defaultTopic)
188-
val consumerProperties = KafkaTestUtils.consumerProps(KafkaInitializer.getBootstrapSevers(), "test-group", "false");
189+
val consumerProperties = KafkaTestUtils.consumerProps(KafkaInitializer.getBootstrapSevers(), "test-group", "false")
189190
consumerProperties[CommonClientConfigs.SECURITY_PROTOCOL_CONFIG] = "SASL_PLAINTEXT"
190191
consumerProperties[SaslConfigs.SASL_MECHANISM] = "PLAIN"
191192
consumerProperties[SaslConfigs.SASL_JAAS_CONFIG] = KafkaInitializer.plainJaas()

0 commit comments

Comments
 (0)