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

Add License rule #2429

Merged
merged 7 commits into from
Mar 15, 2020
Merged

Add License rule #2429

merged 7 commits into from
Mar 15, 2020

Conversation

arturbosch
Copy link
Member

@arturbosch arturbosch commented Mar 10, 2020

Additional changes on top of #2077 :

I reused the current FileProcessListener extension to store the license header inside the KtFile's which is basically caching :).
Instead of introducing a Config.Location property on the config, I went with introducing a new method for the Extension interface.

interface Extension {
    ....
    fun init(config: Config) {
        // implement for setup code
    }
    @OptIn(UnstableApi::class)
    fun init(context: SetupContext) {
        // implement for setup code
    }
}

I've marked the new SetupContext as Unstable with the new @RequiresOptIn api. This way we can add some more useful methods and properties later on without needing a major version.
When we decide that SetupContext is stable, we can remove the fun init(config: Config) function from the Extension interface as SetupContext provides the Config.

/**
 * Context providing useful processing settings to initialize extensions.
 */
@UnstableApi
interface SetupContext {
    /**
     * All config locations which where used to create [config].
     */
    val configUris: Collection<URI>

    /**
     * Configuration which is used to setup detekt.
     */
    val config: Config
}

ProcessingSettings was the ideal candidate to implement SetupContext as it has all the useful information from the cli.

@codecov-io
Copy link

Codecov Report

Merging #2429 into master will increase coverage by 0.03%.
The diff coverage is 86.56%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2429      +/-   ##
============================================
+ Coverage     82.83%   82.87%   +0.03%     
- Complexity     2166     2182      +16     
============================================
  Files           356      358       +2     
  Lines          6136     6194      +58     
  Branches       1119     1130      +11     
============================================
+ Hits           5083     5133      +50     
- Misses          478      480       +2     
- Partials        575      581       +6
Impacted Files Coverage Δ Complexity Δ
.../detekt/rules/documentation/EndOfSentenceFormat.kt 95.23% <ø> (ø) 10 <0> (ø) ⬇️
...otlin/io/gitlab/arturbosch/detekt/api/Extension.kt 100% <ø> (ø) 0 <0> (ø) ⬇️
...itlab/arturbosch/detekt/core/ProcessingSettings.kt 91.04% <100%> (+0.41%) 19 <2> (+1) ⬆️
.../io/gitlab/arturbosch/detekt/cli/runners/Runner.kt 92.3% <100%> (ø) 12 <0> (ø) ⬇️
...sch/detekt/rules/providers/CommentSmellProvider.kt 100% <100%> (ø) 2 <0> (ø) ⬇️
...kt/rules/documentation/AbsentOrWrongFileLicense.kt 100% <100%> (ø) 9 <9> (?)
...b/arturbosch/detekt/cli/config/ConfigValidators.kt 76.92% <100%> (+4.19%) 0 <0> (ø) ⬇️
...lab/arturbosch/detekt/core/FileProcessorLocator.kt 100% <100%> (ø) 5 <0> (ø) ⬇️
...in/io/gitlab/arturbosch/detekt/cli/OutputFacade.kt 94.44% <100%> (+0.32%) 6 <0> (ø) ⬇️
...ules/documentation/LicenceHeaderLoaderExtension.kt 75% <75%> (ø) 6 <6> (?)
... and 4 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 62d7dd7...acda94e. Read the comment docs.

@dector
Copy link
Contributor

dector commented Mar 11, 2020

Thanks, @arturbosch for reopening this! Should I add more tests?

@arturbosch
Copy link
Member Author

arturbosch commented Mar 11, 2020

@dector that sounds awesome to me!
Maybe also some real world testing on your project if this rule does what you expect it to. Thx!

@dector
Copy link
Contributor

dector commented Mar 12, 2020

@arturbosch Battle-tested this rule on Mozilla Fenix app with the default template file. Works like a charm and it's so freaking fast! 😍

@arturbosch
Copy link
Member Author

Thanks for testing! If you realize a testcase is missing, feel free to open a new PR.

@arturbosch arturbosch merged commit 74e86cc into master Mar 15, 2020
@arturbosch arturbosch deleted the license-rule branch March 15, 2020 08:05
@dector
Copy link
Contributor

dector commented Mar 15, 2020

🎉 thanks @arturbosch

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.

3 participants