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

Allow plugins to contribute to the default configuration #4315

Merged
merged 7 commits into from Jan 2, 2022

Conversation

BraisGabin
Copy link
Member

@BraisGabin BraisGabin commented Nov 20, 2021

We should allow that the detekt plugins could contribute with the configuration of it's rules (Slack comment and #3242. There are two places where we should allow this: when the core request the default configuration and when the user request to generare the configuration file.

With this PR if a plugin author adds a configuration file in their resources at the path config/config.yml detekt would concat it at the end of the configuration file.

This PR doesn't give any support to generate nor keep in sync those configurations files but I think that it should be doable in the future.

Related #3242
Closes #1103

@BraisGabin BraisGabin mentioned this pull request Nov 20, 2021
@BraisGabin BraisGabin added this to the 1.20.0 milestone Nov 20, 2021
@BraisGabin BraisGabin changed the base branch from main to improve-test-default-config November 20, 2021 20:13
Base automatically changed from improve-test-default-config to main November 20, 2021 20:57
@BraisGabin BraisGabin changed the base branch from main to simplify-yamlconfig November 20, 2021 21:37
Base automatically changed from simplify-yamlconfig to main November 24, 2021 09:47
@codecov
Copy link

codecov bot commented Dec 1, 2021

Codecov Report

Merging #4315 (86e6526) into main (8a919d9) will decrease coverage by 0.07%.
The diff coverage is 73.91%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #4315      +/-   ##
============================================
- Coverage     84.35%   84.28%   -0.08%     
- Complexity     3277     3283       +6     
============================================
  Files           473      472       -1     
  Lines         10357    10450      +93     
  Branches       1827     1863      +36     
============================================
+ Hits           8737     8808      +71     
- Misses          668      671       +3     
- Partials        952      971      +19     
Impacted Files Coverage Δ
...otlin/io/gitlab/arturbosch/detekt/cli/CliRunner.kt 7.14% <0.00%> (ø)
...b/arturbosch/detekt/core/tooling/AnalysisFacade.kt 62.85% <37.50%> (-3.81%) ⬇️
...otlin/io/gitlab/arturbosch/detekt/core/Analyzer.kt 81.81% <66.66%> (ø)
...ab/arturbosch/detekt/core/config/Configurations.kt 84.37% <66.66%> (ø)
...bosch/detekt/core/tooling/DefaultConfigProvider.kt 80.00% <77.77%> (ø)
...ab/arturbosch/detekt/cli/runners/ConfigExporter.kt 88.88% <100.00%> (+3.17%) ⬆️
.../arturbosch/detekt/core/config/ConfigValidators.kt 84.21% <100.00%> (+0.87%) ⬆️
...kt/core/config/DefaultPropertiesConfigValidator.kt 100.00% <100.00%> (ø)
...gitlab/arturbosch/detekt/core/tooling/Lifecycle.kt 100.00% <100.00%> (ø)
...detekt/tooling/api/DefaultConfigurationProvider.kt 100.00% <100.00%> (ø)
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8a919d9...86e6526. Read the comment docs.

@BraisGabin
Copy link
Member Author

It's difficult to unit test this >_<

@BraisGabin BraisGabin force-pushed the configure-config branch 2 times, most recently from 430327f to 627d2c1 Compare December 2, 2021 00:30
.use { it.copyTo(outputStream) }

ExtensionFacade(spec.extensionsSpec).pluginLoader
.getResourcesAsStream("config/config.yml")
Copy link
Member

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 in

Copy link
Member Author

@BraisGabin BraisGabin Dec 2, 2021

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.

Copy link
Member

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)

public final fun load (Ljava/lang/ClassLoader;)Lio/github/detekt/tooling/api/DefaultConfigurationProvider;
public static synthetic fun load$default (Lio/github/detekt/tooling/api/DefaultConfigurationProvider$Companion;Ljava/lang/ClassLoader;ILjava/lang/Object;)Lio/github/detekt/tooling/api/DefaultConfigurationProvider;
public final fun load (Lio/github/detekt/tooling/api/spec/ProcessingSpec;Ljava/lang/ClassLoader;)Lio/github/detekt/tooling/api/DefaultConfigurationProvider;
public static synthetic fun load$default (Lio/github/detekt/tooling/api/DefaultConfigurationProvider$Companion;Lio/github/detekt/tooling/api/spec/ProcessingSpec;Ljava/lang/ClassLoader;ILjava/lang/Object;)Lio/github/detekt/tooling/api/DefaultConfigurationProvider;
Copy link
Member Author

Choose a reason for hiding this comment

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

I assume that no one is calling this function nor implementing its own DefaultConfigurationProvider. But this change breaks code and binary compatibility. And I don't know how to implement it without this change.

Copy link
Member

Choose a reason for hiding this comment

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

I think this breaking change is okay if it's highlighted in the changelog.

@BraisGabin BraisGabin marked this pull request as ready for review December 2, 2021 09:23
@cortinico cortinico added the notable changes Marker for notable changes in the changelog label Dec 2, 2021
@cortinico
Copy link
Member

That's great stuff! Can I ask you to update the PR name to something more meaningful as it will be harder to search & understand in the changelog

@BraisGabin BraisGabin changed the title Configure config Allow plugins to contribute to the default configuration Dec 2, 2021
@BraisGabin
Copy link
Member Author

That's great stuff! Can I ask you to update the PR name to something more meaningful as it will be harder to search & understand in the changelog

You are completely right.

public final fun load (Ljava/lang/ClassLoader;)Lio/github/detekt/tooling/api/DefaultConfigurationProvider;
public static synthetic fun load$default (Lio/github/detekt/tooling/api/DefaultConfigurationProvider$Companion;Ljava/lang/ClassLoader;ILjava/lang/Object;)Lio/github/detekt/tooling/api/DefaultConfigurationProvider;
public final fun load (Lio/github/detekt/tooling/api/spec/ProcessingSpec;Ljava/lang/ClassLoader;)Lio/github/detekt/tooling/api/DefaultConfigurationProvider;
public static synthetic fun load$default (Lio/github/detekt/tooling/api/DefaultConfigurationProvider$Companion;Lio/github/detekt/tooling/api/spec/ProcessingSpec;Ljava/lang/ClassLoader;ILjava/lang/Object;)Lio/github/detekt/tooling/api/DefaultConfigurationProvider;
Copy link
Member

Choose a reason for hiding this comment

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

I think this breaking change is okay if it's highlighted in the changelog.

Co-authored-by: M Schalk <30376729+schalkms@users.noreply.github.com>
Copy link
Member

@chao2zhang chao2zhang left a comment

Choose a reason for hiding this comment

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

Looks good to me overall. Thank you for building this feature!

Co-authored-by: Chao Zhang <zhangchao6865@gmail.com>
@BraisGabin BraisGabin merged commit a7184d1 into main Jan 2, 2022
@BraisGabin BraisGabin deleted the configure-config branch January 2, 2022 17:55
@cortinico
Copy link
Member

Great stuff! @BraisGabin can you add a paragraph in the UNRELEASED section of the Changelog to explain how this will work for the end user.

@BraisGabin
Copy link
Member Author

@cortinico sorry but I don't know where do you want me to write it.

@cortinico
Copy link
Member

@cortinico sorry but I don't know where do you want me to write it.

I meant here:

(we should create an #### UNRELEASED section and start populating the Changelog for 1.20.0).

@cortinico
Copy link
Member

Do we happen to have a page in the documentation about this feature?

@BraisGabin
Copy link
Member Author

No, we don't have it. I'll try to write somthing about it. A tool to automate it would be nice too (#4457).

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

Successfully merging this pull request may close these issues.

Detekt deactivates non activated rules by default which causes confusion for detekt extension authors
4 participants