[core] Make LanguageRegistry not static#4049
Conversation
Generated by 🚫 Danger |
adangel
left a comment
There was a problem hiding this comment.
Thanks, looks good!
I'm going to merge this now... Note: This will create conflicts with #4059
@oowekyala Do you have any idea about the changed violations in the regression report? It's only the rule LawOfDemeter...
| private static String supportedVersions() { | ||
| return "Languages and version suported:" + PMD.EOL | ||
| + LanguageRegistry.getLanguages().stream().map(Language::getTerseName).collect(Collectors.joining(", ")) | ||
| + LanguageRegistry.PMD.commaSeparatedList(Language::getId) |
There was a problem hiding this comment.
Hm... this method commaSeparatedList sounds more like a utility method that's too detailed. Do we need this flexibility with the parameter?
What we need here IMHO is a method, that just returns a printable list of available languages...
|
|
||
| private @NonNull String supportedLanguages() { | ||
| return LanguageRegistry.getLanguages().stream().map(Language::getTerseName).map(StringUtil::inSingleQuotes).collect(Collectors.joining(", ")); | ||
| return languageRegistry.commaSeparatedList(l -> StringUtil.inSingleQuotes(l.getId())); |
There was a problem hiding this comment.
Maybe it's better if the languageRegistry has a method like "getSupportedLanguagesAsString" (or sth. like a "toString" method) which always returns the list the same way - for consistency. Here we add single quotes, in the CLI help, we don't.
LawOfDemeter has been on my radar for a while... I think the problem is it relies accidentally on the order of rulechain visits, which is not necessarily stable across runs... |
Describe the PR
LanguageRegistry.PMDis available. With [core] Merge CPD and PMD language #3919 there will probably be another registryCPDLanguagueRegistry::getDefaultLanguageis removed (refs [core] Stop falling back on Java when language is unknown #3779)Language::getIdis added. I would like to replacegetTerseNamewith that, to make it clear that it's an Id and not a user-facing name.Related issues
Ready?
./mvnw clean verifypasses (checked automatically by github actions)