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

MTG-6 Update ktlint to 0.47.1 #1091

Merged
merged 4 commits into from
Oct 21, 2022
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
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2016-Present Datadog, Inc.

[buildSrc/src/test/kotlin/com/example/model/*.kt]
ktlint_disabled_rules = trailing-comma-on-call-site, trailing-comma-on-declaration-site
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static-analysis:
variables:
GRADLE_OPTS: "-Xmx2560m -Dorg.gradle.daemon=false -Dorg.gradle.logging.stacktrace=all"
trigger:
include: "https://gitlab-templates.ddbuild.io/mobile/release/static-analysis.yml"
include: "https://gitlab-templates.ddbuild.io/mobile/v10617593-67a1de90/static-analysis.yml"
strategy: depend

analysis:nightly-tests-coverage:
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ same feature from a Java source code.
Our coding style is ensured by [KtLint](https://ktlint.github.io/), with the
default settings. A KtLint check is ran on every PR to ensure that all new code
follow this rule.
Current KtLint version: 0.45.1
Current KtLint version: 0.47.1

Classes should group their methods in folding regions named after the declaring
class. Private methods should be grouped in an `Internal` named folding region.
Expand Down
21 changes: 10 additions & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,16 @@ nightlyTestsCoverageConfig(threshold = 0.92f)
kover {
isDisabled = false
disabledProjects = setOf(
"instrumented",
"sample",
"tools",
"integration",
"nightly-tests",
"kotlin",
"detekt",
"javabackport",
"noopfactory",
"unit"
"instrumented",
"sample",
"tools",
"integration",
"nightly-tests",
"kotlin",
"detekt",
"javabackport",
"noopfactory",
"unit"
)
instrumentAndroidPackage = false
}

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ object AndroidConfig {

const val TARGET_SDK = 31
const val MIN_SDK = 19

// this is temporary, until we bump min sdk. Compose requires min sdk 21.
const val MIN_SDK_FOR_COMPOSE = 21
const val BUILD_TOOLS_VERSION = "31.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import org.gradle.kotlin.dsl.findByType
inline fun <reified T : Any> Project.extensionConfig(
crossinline configure: T.() -> Unit
) {

project.afterEvaluate {
val ext: T? = extensions.findByType(T::class)
ext?.configure()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import org.gradle.api.Project

fun Project.dependencyUpdateConfig() {

taskConfig<DependencyUpdatesTask> {
revision = "release"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import org.gradle.api.Project
import org.gradle.kotlin.dsl.withType

fun Project.detektConfig(excludes: List<String> = emptyList()) {

extensionConfig<DetektExtension> {
source = files("$projectDir/src/main/kotlin")
config = files("${project.rootDir}/detekt.yml")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.gradle.api.Project
import org.jetbrains.dokka.gradle.DokkaTask

fun Project.javadocConfig() {

tasks.withType(DokkaTask::class.java).configureEach {
val toOutputDirectory = file("${buildDir.canonicalPath}/reports/javadoc")
outputDirectory.set(toOutputDirectory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.io.File

fun Project.kotlinConfig(evaluateWarningsAsErrors: Boolean = true) {

taskConfig<KotlinCompile> {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ fun Project.publishingConfig(projectDescription: String) {
}

publishingExtension.apply {

publications.create(MavenConfig.PUBLICATION, MavenPublication::class.java) {
from(components.getByName("release"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.gradle.api.Project
import org.gradle.api.tasks.Exec

fun Project.nightlyTestsCoverageConfig(threshold: Float) {

tasks.register("checkNightlyTestsCoverage", Exec::class.java) {
this.group = "datadog"
val generateApiTasks = allprojects.mapNotNull { it.tasks.findByName("generateApiSurface") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ open class CheckThirdPartyLicensesTask : DefaultTask() {

@TaskAction
fun applyTask() {

val projectDependencies = provider.getThirdPartyDependencies(
project,
extension.transitiveDependencies,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package com.datadog.gradle.plugin.checklicenses

@Suppress("ktlint:enum-entry-name-case")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suppressing the check here as I dont think it is worth modifying all enum variables defined here...

enum class SPDXLicense(val csvName: String) {
_0BSD("0BSD"),
AAL("AAL"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ class JsonSchemaReader(
typeName: String,
fromFile: File
): TypeDefinition {

if (definition == null) return TypeDefinition.Null()

return when (definition.type) {
Expand Down Expand Up @@ -342,7 +341,6 @@ class JsonSchemaReader(
definition: JsonDefinition,
fromFile: File
): TypeDefinition {

val properties = mutableListOf<TypeProperty>()
definition.properties?.forEach { (name, property) ->
val required = (definition.required != null) && (name in definition.required)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ sealed class TypeDefinition {
fun renameRecursive(duplicates: Set<String>, parentName: String): TypeDefinition {
val newName = if (name in duplicates) {
"$parentName$name"
} else name
} else {
name
}

val newProperties = properties.map {
if (it.type is Class) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ class ClassDeserializerGenerator(
hasKnownProperties: Boolean,
rootTypeName: String
) {

addStatement(
"val %L = mutableMapOf<%T, %T>()",
Identifier.PARAM_ADDITIONAL_PROPS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ class ClassGenerator(
private fun FunSpec.Builder.appendPropertySerialization(
property: TypeProperty
) {

val propertyName = property.name.variableName()
val isNullable =
property.optional && property.type !is TypeDefinition.Constant && property.type !is TypeDefinition.Null
Expand Down Expand Up @@ -390,7 +389,6 @@ class ClassGenerator(
}

private fun generateReservedPropertiesArray(definition: TypeDefinition.Class): PropertySpec {

val propertyNames = definition.properties.joinToString(", ") { "\"${it.name}\"" }

val propertyBuilder = PropertySpec.builder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class FileGenerator(
val topLevelTypeBuilder = generateTypeSpec(definition, rootTypeName)

while (knownTypes.any(isUnwrittenClass)) {

val nestedClasses = knownTypes.filter(isUnwrittenClass).toSet()
nestedClasses.forEach {
topLevelTypeBuilder.addType(generateTypeSpec(it.type, rootTypeName).build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import java.io.File
class TransitiveDependenciesPlugin : Plugin<Project> {

override fun apply(target: Project) {

target.tasks.register(TASK_NAME, TransitiveDependenciesTask::class.java) {
outputFile = File(target.projectDir, FILE_NAME)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class ModelValidationTest(
validator.validate(JSONObject(json.toString()))
} catch (e: Exception) {
throw RuntimeException(
"Failed to validate $schemaResourcePath (#$it):\n$entity\n$json\n", e
"Failed to validate $schemaResourcePath (#$it):\n$entity\n$json\n",
e
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ val Employee = TypeDefinition.Class(
TypeDefinition.Primitive(JsonPrimitiveType.STRING),
false
),
TypeProperty("address", Address, false),
TypeProperty("address", Address, false)
)
),
optional = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ internal constructor(val key: String) : EventListener() {
}
val (sslS, sslD) = if (sslStart == 0L) {
0L to 0L
} else (sslStart - callStart) to (sslEnd - sslStart)
} else {
(sslStart - callStart) to (sslEnd - sslStart)
}
val (fbS, fbD) = if (headersStart == 0L) {
0L to 0L
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ internal class DatadogDataConstraints : DataConstraints {
if (it == '.') {
dotCount++
if (dotCount > MAX_DEPTH_LEVEL) '_' else it
} else it
} else {
it
}
}
return String(mapped.toCharArray())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ internal class DataUploadRunnable(
override fun run() {
val batch = if (isNetworkAvailable() && isSystemReady()) {
reader.lockAndReadNext()
} else null
} else {
null
}

if (batch != null) {
consumeBatch(batch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ internal class BroadcastReceiverNetworkInfoProvider(
private var networkInfo: NetworkInfo =
NetworkInfo()
set(value) {
field = value
dataWriter.write(field)
}
field = value
dataWriter.write(field)
}

// region BroadcastReceiver

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,68 +44,110 @@ private fun <T> File.safeCall(
}

internal fun File.canWriteSafe(): Boolean {
return safeCall(default = false) { @Suppress("UnsafeThirdPartyFunctionCall") canWrite() }
return safeCall(default = false) {
@Suppress("UnsafeThirdPartyFunctionCall")
canWrite()
}
}

internal fun File.canReadSafe(): Boolean {
return safeCall(default = false) { @Suppress("UnsafeThirdPartyFunctionCall") canRead() }
return safeCall(default = false) {
@Suppress("UnsafeThirdPartyFunctionCall")
canRead()
}
}

internal fun File.deleteSafe(): Boolean {
return safeCall(default = false) { @Suppress("UnsafeThirdPartyFunctionCall") delete() }
return safeCall(default = false) {
@Suppress("UnsafeThirdPartyFunctionCall")
delete()
}
}

internal fun File.existsSafe(): Boolean {
return safeCall(default = false) { @Suppress("UnsafeThirdPartyFunctionCall") exists() }
return safeCall(default = false) {
@Suppress("UnsafeThirdPartyFunctionCall")
exists()
}
}

internal fun File.isFileSafe(): Boolean {
return safeCall(default = false) { @Suppress("UnsafeThirdPartyFunctionCall") isFile() }
return safeCall(default = false) {
@Suppress("UnsafeThirdPartyFunctionCall")
isFile()
}
}

internal fun File.isDirectorySafe(): Boolean {
return safeCall(default = false) { @Suppress("UnsafeThirdPartyFunctionCall") isDirectory() }
return safeCall(default = false) {
@Suppress("UnsafeThirdPartyFunctionCall")
isDirectory()
}
}

internal fun File.listFilesSafe(): Array<File>? {
return safeCall(default = null) { @Suppress("UnsafeThirdPartyFunctionCall") listFiles() }
return safeCall(default = null) {
@Suppress("UnsafeThirdPartyFunctionCall")
listFiles()
}
}

internal fun File.listFilesSafe(filter: FileFilter): Array<File>? {
return safeCall(default = null) { @Suppress("UnsafeThirdPartyFunctionCall") listFiles(filter) }
return safeCall(default = null) {
@Suppress("UnsafeThirdPartyFunctionCall")
listFiles(filter)
}
}

internal fun File.lengthSafe(): Long {
return safeCall(default = 0L) { @Suppress("UnsafeThirdPartyFunctionCall") length() }
return safeCall(default = 0L) {
@Suppress("UnsafeThirdPartyFunctionCall")
length()
}
}

internal fun File.mkdirsSafe(): Boolean {
return safeCall(default = false) { @Suppress("UnsafeThirdPartyFunctionCall") mkdirs() }
return safeCall(default = false) {
@Suppress("UnsafeThirdPartyFunctionCall")
mkdirs()
}
}

internal fun File.renameToSafe(dest: File): Boolean {
return safeCall(default = false) { @Suppress("UnsafeThirdPartyFunctionCall") renameTo(dest) }
return safeCall(default = false) {
@Suppress("UnsafeThirdPartyFunctionCall")
renameTo(dest)
}
}

internal fun File.readTextSafe(charset: Charset = Charsets.UTF_8): String? {
return if (existsSafe() && canReadSafe()) {
safeCall(default = null) { @Suppress("UnsafeThirdPartyFunctionCall") readText(charset) }
safeCall(default = null) {
@Suppress("UnsafeThirdPartyFunctionCall")
readText(charset)
}
} else {
null
}
}

internal fun File.readBytesSafe(): ByteArray? {
return if (existsSafe() && canReadSafe()) {
safeCall(default = null) { @Suppress("UnsafeThirdPartyFunctionCall") readBytes() }
safeCall(default = null) {
@Suppress("UnsafeThirdPartyFunctionCall")
readBytes()
}
} else {
null
}
}

internal fun File.readLinesSafe(charset: Charset = Charsets.UTF_8): List<String>? {
return if (existsSafe() && canReadSafe()) {
safeCall(default = null) { @Suppress("UnsafeThirdPartyFunctionCall") readLines(charset) }
safeCall(default = null) {
@Suppress("UnsafeThirdPartyFunctionCall")
readLines(charset)
}
} else {
null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal val NULL_MAP_VALUE = Object()
internal fun <K, V> Iterable<Pair<K, V>>.toMutableMap(): MutableMap<K, V> {
return toMap(mutableMapOf())
}

/**
* @return the [MutableMap] if its not `null`, or the empty [MutableMap] otherwise.
*/
Expand Down
Loading