(This isn’t so much a feature request as a suggestion for extending an existing rule; hopefully I’ve selected the correct category.)
In brief: java:S4288 recommends constructor injection in place of autowiring fields in Spring controllers, services and repositories. For example, the following snippet (correctly) triggers the rule,
@Controller
public class DemoController {
@Autowired // java:S4288 matches here
private FooRepository fooRepository;
}
Unfortunately, the rule doesn’t match when using (the very common) @RestController:
@RestController
public class DemoController {
@Autowired // no match
private FooRepository fooRepository;
}
Suggestion: the second snippet should also be considered non-compliant. The rule description should probably also be updated to mention @RestController
.
(Snippets tested with SonarLint for Eclipse, v5.9.0.31414.)