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

Suppress RedundantVisibilityModifierRule if explicit API mode enabled #3125

Closed
osipxd opened this issue Oct 3, 2020 · 3 comments · Fixed by #3175 or #3358
Closed

Suppress RedundantVisibilityModifierRule if explicit API mode enabled #3125

osipxd opened this issue Oct 3, 2020 · 3 comments · Fixed by #3175 or #3358

Comments

@osipxd
Copy link
Contributor

osipxd commented Oct 3, 2020

Expected Behavior of the rule

If explicit API mode is enabled:

kotlin {
    explicitApi()
}

Detekt should suppress RedundantVisibilityModifierRule for public modifier.

Context

Explicit API mode was added in Kotlin 1.4
It prevents libraries' authors from making APIs public unintentionally. In this mode, you should explicitly specify the visibility modifier even if it is public.

schalkms added a commit that referenced this issue Oct 26, 2020
Explicit API mode was added in Kotlin 1.4
It prevents libraries' authors from making APIs public unintentionally.
In this mode, the visibility modifier should be defined explicitly even if it is public.
See: https://kotlinlang.org/docs/reference/whatsnew14.html#explicit-api-mode-for-library-authors

Closes #3125
schalkms added a commit that referenced this issue Oct 27, 2020
…#3175)

* Suppress RedundantVisibilityModifierRule if explicit API mode enabled

Explicit API mode was added in Kotlin 1.4
It prevents libraries' authors from making APIs public unintentionally.
In this mode, the visibility modifier should be defined explicitly even if it is public.
See: https://kotlinlang.org/docs/reference/whatsnew14.html#explicit-api-mode-for-library-authors

Closes #3125

* Add explicit API mode to rule documentation
@arturbosch arturbosch added this to the 1.15.0 milestone Nov 2, 2020
arturbosch pushed a commit that referenced this issue Nov 15, 2020
…#3175)

* Suppress RedundantVisibilityModifierRule if explicit API mode enabled

Explicit API mode was added in Kotlin 1.4
It prevents libraries' authors from making APIs public unintentionally.
In this mode, the visibility modifier should be defined explicitly even if it is public.
See: https://kotlinlang.org/docs/reference/whatsnew14.html#explicit-api-mode-for-library-authors

Closes #3125

* Add explicit API mode to rule documentation
arturbosch pushed a commit that referenced this issue Dec 21, 2020
…#3175)

* Suppress RedundantVisibilityModifierRule if explicit API mode enabled

Explicit API mode was added in Kotlin 1.4
It prevents libraries' authors from making APIs public unintentionally.
In this mode, the visibility modifier should be defined explicitly even if it is public.
See: https://kotlinlang.org/docs/reference/whatsnew14.html#explicit-api-mode-for-library-authors

Closes #3125

* Add explicit API mode to rule documentation
@osipxd
Copy link
Contributor Author

osipxd commented Dec 29, 2020

Not fixed in 1.15.0
I've created the minimal project to reproduce this bug.
https://github.com/osipxd/detekt-explicit-api-mode-test

@osipxd
Copy link
Contributor Author

osipxd commented Dec 29, 2020

Looks like the value in AnalysisFlags, used to get explicitMode is default value, so it is always DISABLED and AnalysisFlag is immutable.
https://github.com/JetBrains/kotlin/blob/8be23df668be32bad8c23f49f0b9f8feb7cb6cd9/compiler/util/src/org/jetbrains/kotlin/config/AnalysisFlag.kt#L32-L34

@schalkms
Copy link
Member

schalkms commented Jan 7, 2021

Thanks for checking this feature thoroughly.
I scrolled through the version history of the Kotlin compiler. Luckily, I found another possible solution by using another internal function.
Please check out the referenced PR. Thank you!

schalkms added a commit that referenced this issue Jan 10, 2021
…#3358)

* Suppress RedundantVisibilityModifierRule if explicit API mode enabled

This solution uses the languageVersionSettings of the compiler to fetch the API mode setting.

Explicit API mode was added in Kotlin 1.4
It prevents libraries' authors from making APIs public unintentionally.
In this mode, the visibility modifier should be defined explicitly even if it is public.
See: https://kotlinlang.org/docs/reference/whatsnew14.html#explicit-api-mode-for-library-authors

Closes #3125

* Declare variables in Spec as memoized
arturbosch pushed a commit that referenced this issue Jan 16, 2021
…#3175)

* Suppress RedundantVisibilityModifierRule if explicit API mode enabled

Explicit API mode was added in Kotlin 1.4
It prevents libraries' authors from making APIs public unintentionally.
In this mode, the visibility modifier should be defined explicitly even if it is public.
See: https://kotlinlang.org/docs/reference/whatsnew14.html#explicit-api-mode-for-library-authors

Closes #3125

* Add explicit API mode to rule documentation
arturbosch pushed a commit that referenced this issue Jan 16, 2021
…#3358)

* Suppress RedundantVisibilityModifierRule if explicit API mode enabled

This solution uses the languageVersionSettings of the compiler to fetch the API mode setting.

Explicit API mode was added in Kotlin 1.4
It prevents libraries' authors from making APIs public unintentionally.
In this mode, the visibility modifier should be defined explicitly even if it is public.
See: https://kotlinlang.org/docs/reference/whatsnew14.html#explicit-api-mode-for-library-authors

Closes #3125

* Declare variables in Spec as memoized
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants