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

Ignore FunctionOnlyReturningConstant for allowed annotations #1968

Conversation

sowmyav24
Copy link
Contributor

Fixes #1313

  • Introduced excludeAnnotatedFunctions to provide a list of annotations that can disable FunctionOnlyReturningConstant check
  • Set default value to dagger.Provides


it("does not report excluded annotated function which returns a constant") {
val code = """
import jdk.nashorn.internal.ir.annotations.Ignore
Copy link
Member

Choose a reason for hiding this comment

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

This is the reason why the build fails on some machines when compiling the test snippet. Please remove this import here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, replaced with kotlin.SinceKotlin

""".trimIndent()
val config = TestConfig(mapOf("excludeAnnotatedFunction" to "jdk.nashorn.internal.ir.annotations.Ignore"))
val rule = FunctionOnlyReturningConstant(config)
assertThat(rule.compileAndLint(code)).hasSize(0)
Copy link
Member

Choose a reason for hiding this comment

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

nit

Suggested change
assertThat(rule.compileAndLint(code)).hasSize(0)
assertThat(rule.compileAndLint(code)).isEmpty()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done !


it("does not report excluded annotated function which returns a constant") {
val code = """
import jdk.nashorn.internal.ir.annotations.Ignore
Copy link
Member

Choose a reason for hiding this comment

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

You could use the kotlin.SinceKotlin annotation for testing purposes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, Done.

@schalkms
Copy link
Member

schalkms commented Oct 2, 2019

Thanks! I like this config option.

@schalkms schalkms merged commit a846ec2 into detekt:master Oct 3, 2019
@arturbosch arturbosch added this to the 1.1.0 milestone Oct 4, 2019
smyachenkov pushed a commit to smyachenkov/detekt that referenced this pull request Dec 9, 2019
…1968)

* Ignore FunctionOnlyReturningConstant for allowed annotations

* Refactor tests
smyachenkov pushed a commit to smyachenkov/detekt that referenced this pull request Dec 9, 2019
…1968)

* Ignore FunctionOnlyReturningConstant for allowed annotations

* Refactor tests
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.

Ignore FunctionOnlyReturningConstant for Dagger provides methods
3 participants