Skip to content

Commit

Permalink
remove JerseyMissingHttpMethodAnnotation temporarily
Browse files Browse the repository at this point in the history
i did _not_ think this through.

there's a bunch of

    @path("/subResource")
    fun resource() = getSubResource()

which cannot be handled and add a _lot_ of false positives.
  • Loading branch information
thewisenerd committed May 16, 2021
1 parent 2fe076c commit 3f3ac9e
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 51 deletions.
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ Inspections provided:
- **BlockingCallContextReclaimable**: infer blocking calls within `Dispatchers.IO` context which can be migrated to
non-blocking alternatives
- **JerseyMethodParameterDefaultValue**: infer if a probable jersey method contains a parameter with a default value
- **JerseyMissingHttpMethodAnnotation**: infer if a probable jersey method does not contain any HttpMethod annotations
like `@GET` or `@POST`

## detekt run

Expand Down Expand Up @@ -89,7 +87,7 @@ already provide non-blocking method alternatives. such methods may be annotated

same as `reclaimableMethodAnnotations`, but allowing you to provide FQ names to the methods

## JerseyMethodParameterDefaultValue, JerseyMissingHttpMethodAnnotation
## JerseyMethodParameterDefaultValue

```yml
sidekt:
Expand All @@ -107,8 +105,3 @@ and if not, throw a "Parameter specified as non-null is null" error on invocatio

- [KT-27947](https://youtrack.jetbrains.com/issue/KT-27947)
- [KT-28684](https://youtrack.jetbrains.com/issue/KT-28684)

**JerseyMissingHttpMethodAnnotation**

if a resource method has a `@Path` annotation, but not an accompanying `@GET` or `@POST` annotation,
the resources get tagged `UNKNOWN`, do not match or invoke the resource method; and throw a 404 instead.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package io.github.thewisenerd.linters.sidekt
import io.github.thewisenerd.linters.sidekt.rules.BlockingCallContext
import io.github.thewisenerd.linters.sidekt.rules.BlockingCallContextReclaimable
import io.github.thewisenerd.linters.sidekt.rules.JerseyMethodParameterDefaultValue
import io.github.thewisenerd.linters.sidekt.rules.JerseyMissingHttpMethodAnnotation
import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.api.RuleSet
import io.gitlab.arturbosch.detekt.api.RuleSetProvider
Expand All @@ -16,8 +15,7 @@ class SideKtRuleSetProvider : RuleSetProvider {
listOf(
BlockingCallContext(config),
BlockingCallContextReclaimable(config),
JerseyMethodParameterDefaultValue(config),
JerseyMissingHttpMethodAnnotation(config)
JerseyMethodParameterDefaultValue(config)
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ private object JerseyIssueHolder {
"jersey resource method has default parameter value",
Debt.FIVE_MINS
)

val jerseyMissingHttpMethodAnnotation = Issue(
JerseyMissingHttpMethodAnnotation::class.java.simpleName,
Severity.Defect,
"jersey resource method does not have HttpMethod annotation",
Debt.FIVE_MINS
)
}

/**
Expand Down Expand Up @@ -46,26 +39,13 @@ class JerseyMethodParameterDefaultValue(config: Config) : Rule(config) {
val dbg = Debugger.make(JerseyMethodParameterDefaultValue::class.java.simpleName, debugStream)

// TODO: ideally use fqName
val hasHttpMethodAnnotation = function.hasAnnotation(*standardHttpMethodList, "HttpMethod")
val hasPathAnnotation = function.hasAnnotation("Path")

if (!hasPathAnnotation) {
dbg.i(" hasPathAnnotation=false")
return
}

if (!hasHttpMethodAnnotation) {
dbg.i(" hasHttpMethodAnnotation=false")

report(
CodeSmell(
issue = JerseyIssueHolder.jerseyMissingHttpMethodAnnotation,
entity = Entity.from(function),
message = "probable jersey resource method (${function.name}) does not have a HttpMethod annotation"
)
)
}

function.valueParameters.forEach { parameter ->
dbg.i(" parameter=${parameter.name}")
if (parameter.hasDefaultValue()) {
Expand All @@ -81,7 +61,3 @@ class JerseyMethodParameterDefaultValue(config: Config) : Rule(config) {
}
}
}

class JerseyMissingHttpMethodAnnotation(config: Config) : Rule(config) {
override val issue: Issue = JerseyIssueHolder.jerseyMissingHttpMethodAnnotation
}
12 changes: 2 additions & 10 deletions src/test/kotlin/io/github/thewisenerd/linters/sidekt/JerseyTest.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.thewisenerd.linters.sidekt

import io.github.thewisenerd.linters.sidekt.rules.JerseyMethodParameterDefaultValue
import io.github.thewisenerd.linters.sidekt.rules.JerseyMissingHttpMethodAnnotation
import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.api.Finding
import io.gitlab.arturbosch.detekt.api.SourceLocation
Expand All @@ -11,13 +10,9 @@ import org.junit.Test
class JerseyTest {
companion object {
private val jerseyMethodParameterDefaultValueClassName = JerseyMethodParameterDefaultValue::class.java.simpleName
private val jerseyMissingHttpMethodAnnotationClassName = JerseyMissingHttpMethodAnnotation::class.java.simpleName

private fun ensureJerseyMethodParameterDefaultValueFindings(findings: List<Finding>, requiredFindings: List<SourceLocation>) =
TestUtils.ensureFindings(jerseyMethodParameterDefaultValueClassName, findings, requiredFindings)

private fun ensureJerseyMissingHttpMethodAnnotationFindings(findings: List<Finding>, requiredFindings: List<SourceLocation>) =
TestUtils.ensureFindings(jerseyMissingHttpMethodAnnotationClassName, findings, requiredFindings)
}

private val testConfig = object : Config {
Expand All @@ -39,11 +34,8 @@ class JerseyTest {
val code = TestUtils.readFile("simple05.kt")
val findings = subject.compileAndLintWithContext(TestUtils.env, code)
ensureJerseyMethodParameterDefaultValueFindings(findings, listOf(
SourceLocation(19, 1),
SourceLocation(25, 1)
))
ensureJerseyMissingHttpMethodAnnotationFindings(findings, listOf(
SourceLocation(14, 1)
SourceLocation(13, 1),
SourceLocation(19, 1)
))
}

Expand Down
6 changes: 0 additions & 6 deletions src/test/resources/simple05.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ annotation class POST
@Retention(AnnotationRetention.RUNTIME)
annotation class Path(val descriptor: String)


@Path("/users/{username}")
fun foo1(a: String) {

}

@POST
@Path("/users/{username}")
fun foo2(a: String? = null) {
Expand Down

0 comments on commit 3f3ac9e

Please sign in to comment.