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
Allow plugins to contribute to the default configuration #4315
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3ed9e88
Add missing tests
BraisGabin 8fef21b
Remove deprecated code
BraisGabin 64273a4
Get Spec in DefaultConfigProvider
BraisGabin 7179b6d
Remove DefaultConfig
BraisGabin 00a2e2e
Concat configurations
BraisGabin c6b0b1b
Apply suggestions from code review
BraisGabin 86e6526
Apply suggestions from code review
BraisGabin File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
detekt-cli/src/main/kotlin/io/gitlab/arturbosch/detekt/cli/Configurations.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/config/DefaultConfig.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 40 additions & 4 deletions
44
...kt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/tooling/DefaultConfigProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,55 @@ | ||
package io.gitlab.arturbosch.detekt.core.tooling | ||
|
||
import io.github.detekt.tooling.api.DefaultConfigurationProvider | ||
import io.github.detekt.tooling.api.spec.ProcessingSpec | ||
import io.github.detekt.utils.getSafeResourceAsStream | ||
import io.github.detekt.utils.openSafeStream | ||
import io.gitlab.arturbosch.detekt.api.Config | ||
import io.gitlab.arturbosch.detekt.core.config.DefaultConfig | ||
import io.gitlab.arturbosch.detekt.core.config.YamlConfig | ||
import io.gitlab.arturbosch.detekt.core.settings.ExtensionFacade | ||
import java.io.ByteArrayInputStream | ||
import java.io.ByteArrayOutputStream | ||
import java.io.InputStream | ||
import java.nio.file.Files | ||
import java.nio.file.Path | ||
import java.nio.file.StandardCopyOption | ||
|
||
class DefaultConfigProvider : DefaultConfigurationProvider { | ||
private lateinit var spec: ProcessingSpec | ||
|
||
override fun get(): Config = DefaultConfig.newInstance() | ||
override fun init(spec: ProcessingSpec) { | ||
this.spec = spec | ||
} | ||
|
||
override fun get(): Config = spec.getDefaultConfiguration() | ||
|
||
override fun copy(targetLocation: Path) { | ||
val configUrl = javaClass.getResource("/${DefaultConfig.RESOURCE_NAME}")!! | ||
Files.copy(configUrl.openSafeStream(), targetLocation, StandardCopyOption.REPLACE_EXISTING) | ||
Files.copy(configInputStream(spec), targetLocation, StandardCopyOption.REPLACE_EXISTING) | ||
} | ||
} | ||
|
||
private fun configInputStream(spec: ProcessingSpec): InputStream { | ||
val outputStream = ByteArrayOutputStream() | ||
|
||
requireNotNull(spec.javaClass.getSafeResourceAsStream("/default-detekt-config.yml")) | ||
.use { it.copyTo(outputStream) } | ||
|
||
ExtensionFacade(spec.extensionsSpec).pluginLoader | ||
.getResourcesAsStream("config/config.yml") | ||
.forEach { inputStream -> | ||
outputStream.bufferedWriter().append('\n').flush() | ||
inputStream.use { it.copyTo(outputStream) } | ||
} | ||
|
||
return ByteArrayInputStream(outputStream.toByteArray()) | ||
} | ||
|
||
private fun ClassLoader.getResourcesAsStream(name: String): Sequence<InputStream> { | ||
return getResources(name) | ||
.asSequence() | ||
.map { it.openSafeStream() } | ||
} | ||
|
||
fun ProcessingSpec.getDefaultConfiguration(): Config { | ||
return YamlConfig.load(configInputStream(this).reader()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think this path
config/config.yml
should be configurable? If not, we probably need to add documentation inThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this could be configurable.
We need to document this. But should we document it right now? Or should we wait to release it first? And probably we can create a tool to generate this files from our annotations. The same that we have already for detekt but working for anyone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If not configurable, should this be exposed in detekt-api so that other plugin authors could refer to this constant. (the prefixing
config/
does look a bit awkward)