manifold-systems / manifold-ij

IntelliJ plugin for Manifold
Other
17 stars 5 forks source link

[Bug] Sonarlint complains about unused assignment/local variables when using string interpolation #25

Open CC007 opened 4 months ago

CC007 commented 4 months ago

In this code snippet:

default String getTemplateFileName(HttpServletRequest request, Model model) {
    URI baseUri = getBaseUri();
    String templateFileName = this.getClass().getSimpleName() + ".ftl";
    String canonicalFileName = getResource(templateFileName)
            .map(baseUri::relativize)
            .map(URI::getPath)
            .orElse(COMPONENT_TEMPLATE_PREFIX + "content/error/Status500.ftl");
    log.info("Template name: $canonicalFileName");
    return "/$canonicalFileName";
}

The canonicalFileName is used in 2 places, however it is ONLY used in string interpolation. SonarLint doesn't understand how manifold added string interpolation, so it is giving a false positive that canonicalFileName is an unused local variable. Because of this, it also erroneously detects that the assignment to that variable is unused.

I don't know if I should file this bug here or on the SonarLint side. I think that the solution might be a combination of both.

rsmckinney commented 4 months ago

As an IntelliJ plugin the invalid errors from Sonarlint may be suppressed from the manifold plugin. If Sonarlint is a JDK tool, not much can be done on my part if it isn't using the javac AST for analysis, which is fully formed with interpolation from manifold. I'll have a deeper look at sonarlist at some point.

CC007 commented 4 months ago

As an IntelliJ plugin the invalid errors from Sonarlint may be suppressed from the manifold plugin.

Well, good thing that SonarLint is a plugin then: https://plugins.jetbrains.com/plugin/7973-sonarlint