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

Resolve detekt findings #54

Merged
merged 19 commits into from
Feb 27, 2021
Merged

Resolve detekt findings #54

merged 19 commits into from
Feb 27, 2021

Conversation

mpgirro
Copy link
Owner

@mpgirro mpgirro commented Feb 24, 2021

This PR closes #52 by resolving the issues found by detekt. I did not add any custom rules so far, but we might want to do that in the future(?). We've had mostly MaxLineLength and ReturnCount issues.

Some resulting constructs are definitely worth debating, and I'm not super happy with quite a few of them. I did not @Suppress too much and only when refactoring would have been very inconvenient.

@mpgirro mpgirro added this to the 1.0.0 milestone Feb 24, 2021
@mpgirro mpgirro requested a review from rock3r February 24, 2021 12:03
@coveralls
Copy link

coveralls commented Feb 24, 2021

Pull Request Test Coverage Report for Build #30

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 400 of 413 (96.85%) changed or added relevant lines in 68 files are covered.
  • 17 unchanged lines in 11 files lost coverage.
  • Overall coverage decreased (-0.3%) to 97.747%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/main/kotlin/dev/stalla/builder/validating/episode/ValidatingEpisodeBuilder.kt 9 10 90.0%
src/main/kotlin/dev/stalla/builder/validating/podcast/ValidatingPodcastItunesBuilder.kt 7 8 87.5%
src/main/kotlin/dev/stalla/builder/validating/podcast/ValidatingPodcastPodcastindexLockedBuilder.kt 5 6 83.33%
src/main/kotlin/dev/stalla/dom/DomBuilderFactory.kt 7 8 87.5%
src/main/kotlin/dev/stalla/parser/NamespaceParser.kt 2 4 50.0%
src/main/kotlin/dev/stalla/dom/DomWritingExtensions.kt 2 9 22.22%
Files with Coverage Reduction New Missed Lines %
src/main/kotlin/dev/stalla/dom/DomParsingExtensions.kt 1 95.45%
src/main/kotlin/dev/stalla/model/itunes/ItunesCategory.kt 1 99.21%
src/main/kotlin/dev/stalla/parser/namespace/AtomParser.kt 1 96.3%
src/main/kotlin/dev/stalla/parser/namespace/ContentParser.kt 1 85.71%
src/main/kotlin/dev/stalla/parser/namespace/GoogleplayParser.kt 1 95.65%
src/main/kotlin/dev/stalla/parser/namespace/ItunesParser.kt 1 97.37%
src/main/kotlin/dev/stalla/parser/namespace/PodcastindexParser.kt 1 98.25%
src/main/kotlin/dev/stalla/parser/namespace/PodloveSimpleChapterParser.kt 1 90.91%
src/main/kotlin/dev/stalla/model/StyledDuration.kt 2 98.26%
src/main/kotlin/dev/stalla/parser/namespace/FyydParser.kt 2 71.43%
Totals Coverage Status
Change from base Build #27: -0.3%
Covered Lines: 1996
Relevant Lines: 2042

💛 - Coveralls

jcenter()
jcenter {
content {
includeGroup("org.jetbrains.kotlinx")
Copy link
Owner Author

@mpgirro mpgirro Feb 24, 2021

Choose a reason for hiding this comment

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

Required for HTML reports. We might also use kotlinx for introducing truly immutable lists in the data classes again, for safety in Java.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is that lib released? Immutable collections I mean.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Hm, I've just read up on it here, without checking the release status. Seems it's still in pre-release.

Comment on lines +15 to +16
public fun addAllAuthorBuilder(authorBuilders: List<PersonBuilder>): AtomBuilder =
apply { authorBuilders.forEach(::addAuthorBuilder) }
Copy link
Owner Author

Choose a reason for hiding this comment

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

These are in accordance with the formatting of expression-bodies (even though especially scope functions are nice on the same line as the =)

@@ -1,3 +1,5 @@
@file:Suppress("TooManyFunctions")
Copy link
Owner Author

Choose a reason for hiding this comment

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

I've suppressed the TooManyFunctions in builders since we need at least as many methods in them as there are properties in their data class models.

Copy link
Collaborator

@rock3r rock3r Feb 25, 2021

Choose a reason for hiding this comment

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

I think we can simply suppress TooManyFunctions and TooManyParameters entirely, they don't really make too much sense when dealing with large models and files with top-level functions

Copy link
Owner Author

Choose a reason for hiding this comment

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

Do you have a favourite config file at hand that we can use? Might be quicker than setting one up from scratch.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'll try to find something

Comment on lines 31 to 39
override fun applyFrom(prototype: EpisodeGoogleplay?): EpisodeGoogleplayBuilder = whenNotNull(prototype) { googleplay ->
author(googleplay.author)
description(googleplay.description)
explicit(googleplay.explicit?.type)
block(googleplay.block)
imageBuilder(HrefOnlyImage.builder().applyFrom(googleplay.image))
override fun applyFrom(prototype: EpisodeGoogleplay?): EpisodeGoogleplayBuilder {
return whenNotNull(prototype) { googleplay ->
author(googleplay.author)
description(googleplay.description)
explicit(googleplay.explicit?.type)
block(googleplay.block)
imageBuilder(HrefOnlyImage.builder().applyFrom(googleplay.image))
}
Copy link
Owner Author

Choose a reason for hiding this comment

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

Alternative here could be:

override fun applyFrom(prototype: EpisodeGoogleplay?): EpisodeGoogleplayBuilder =
  whenNotNull(prototype) { googleplay ->
    author(googleplay.author)
    description(googleplay.description)
    explicit(googleplay.explicit?.type)
    block(googleplay.block)
    imageBuilder(HrefOnlyImage.builder().applyFrom(googleplay.image))
  }

but that's not really a single line expression body anymore.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's not a single line but it it a single expression. Personal taste would prefer the expression body syntax, but easy either way

Copy link
Owner Author

Choose a reason for hiding this comment

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

I also prefer the single expression tbh. Just wanted to stick to the convention as closely as possible. But if you're also preferring it, I'll change it then.

Comment on lines -16 to +17
override fun addAuthorBuilder(authorBuilder: PersonBuilder): AtomBuilder = apply {
authorBuilders.add(authorBuilder)
}
override fun addAuthorBuilder(authorBuilder: PersonBuilder): AtomBuilder =
apply { authorBuilders.add(authorBuilder) }
Copy link
Owner Author

Choose a reason for hiding this comment

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

For consistency, I've refactored these as well to new line expression bodies, even though the lines have not been too long here. Preferred the previous style more though.

Comment on lines 174 to 177
@Suppress("ReturnCount")
internal fun Node.toItunesCategory(namespace: FeedNamespace? = null): ItunesCategory? {
val categoryValue = getAttributeValueByName("text")?.trim() ?: return null
val category = ItunesCategory.of(categoryValue) ?: return null
Copy link
Owner Author

@mpgirro mpgirro Feb 24, 2021

Choose a reason for hiding this comment

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

The alternatives I came up with were harder to read and still had too many returns 😅

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suppression is ok here too yep

Comment on lines +23 to 26
@Suppress("MagicNumber")
private val dayOfWeek = mapOf(
1L to "Mon",
2L to "Tue",
Copy link
Owner Author

Choose a reason for hiding this comment

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

Felt stupid to introduce constants here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Absolutely :)

@@ -1,3 +1,5 @@
@file:Suppress("TooManyFunctions")
Copy link
Owner Author

@mpgirro mpgirro Feb 24, 2021

Choose a reason for hiding this comment

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

Also suppressed TooManyFunctions in the extensions, since we have as many extensions as we like.

Comment on lines 42 to 43
"contributor" -> ifCanBeParsed { toPersonBuilder(personBuilderProvider.createPersonBuilder(), namespace) }
?.let(atomBuilder::addContributorBuilder)
Copy link
Owner Author

Choose a reason for hiding this comment

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

Parsers suffered from both MaxLineLength and ReturnCount. Solved with ?.let and by only passing the function pointer.

@@ -87,7 +83,10 @@ internal object PodcastindexParser : NamespaceParser() {
.type(type)
}

private fun Node.toSoundbiteBuilder(soundbiteBuilder: EpisodePodcastindexSoundbiteBuilder): EpisodePodcastindexSoundbiteBuilder? {
@Suppress("ReturnCount")
Copy link
Owner Author

Choose a reason for hiding this comment

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

Again, not better idea for this method.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's ok, it was already the smallest/simplest implementation in my mind 👯

Copy link
Collaborator

@rock3r rock3r left a comment

Choose a reason for hiding this comment

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

I'd turn off those rules mentioned in the comments, so we can spare ourselves some suppressions. Looks good for the rest!

@mpgirro
Copy link
Owner Author

mpgirro commented Feb 26, 2021

I've disabled the mentioned rules. Since the ReturnCount is obsolete now, I've also reverted the parsers to their previous state, for better readability.

@rock3r
Copy link
Collaborator

rock3r commented Feb 26, 2021

Ace, I'll try to get you a detekt config file asap, may need to patch it up from other projects I have :)

@rock3r
Copy link
Collaborator

rock3r commented Feb 27, 2021

@mpgirro please see #57 where I add my own config and fix a bunch more issues. I am also testing SARIF support (more info in the PR)

Seb's detekt ruleset, and relevant fixes
@rock3r
Copy link
Collaborator

rock3r commented Feb 27, 2021

I think we can ship now 💯

@rock3r rock3r merged commit 8743810 into master Feb 27, 2021
@rock3r rock3r deleted the 52_detekt branch February 27, 2021 14:39
@mpgirro
Copy link
Owner Author

mpgirro commented Feb 27, 2021

Bit of stuff is still in my pipeline. Found another issue with specs actually 😅

@rock3r
Copy link
Collaborator

rock3r commented Feb 27, 2021

Huh, curious to see what. But can always be a separate PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Detekt to the project
3 participants