casid / jte

Secure and speedy templates for Java and Kotlin.
https://jte.gg
Apache License 2.0
737 stars 54 forks source link

kte: Fix parameter declaration for generated templates #319

Closed marcospereira closed 6 months ago

marcospereira commented 6 months ago

What?

Given the following template:

@param name: String
@param age: Int? = null

The generated code for Kotlin's renderMap would have:

@JvmStatic fun renderMap(jteOutput:gg.jte.html.HtmlTemplateOutput, jteHtmlInterceptor:gg.jte.html.HtmlInterceptor?, params:Map<String, Any?>) {
    val name = params["name"] as String
    val age = params["age"] as Int?? ?: null
    render(jteOutput, jteHtmlInterceptor, name, age);
}

There are two issues here:

  1. The double ? in Int?? generates a warning (Redundant '?')
  2. The section ?: null also generates a warning (Right operand of elvis operator (?:) is useless if it is null).

This PR fixes both warnings.

codecov[bot] commented 6 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (7ad2e12) 91.20% compared to head (dc8ef75) 91.23%. Report is 1 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #319 +/- ## ============================================ + Coverage 91.20% 91.23% +0.02% - Complexity 1211 1216 +5 ============================================ Files 76 76 Lines 3151 3159 +8 Branches 492 492 ============================================ + Hits 2874 2882 +8 Misses 164 164 Partials 113 113 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

casid commented 6 months ago

Thank you @marcospereira!