-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable suppressing Nodef for specifik code locations #16
base: master
Are you sure you want to change the base?
Conversation
Issue: #15 |
<continuing discussion of #14 > Hi @demus-nine ! First of all thank you very much for the contribution and the idea. Great job! However as a a new user of this feature (3rd pair of eyes here), I have two observations:
|
If you're using codenarc with NoDef enabled, you would probably be suppressing NoDef at those particular locations anyway, so another annotation would add duplication at all these locations. SuppressWarning was probably named thus for historical reasons, because hitting any codenarc violation most certainly fails the build (in gradle, I don't know how codenarc behaves in other build systems). You could do a hybrid solution with both a dedicated annotation and hardcoding the common suppressions that are used to allow def/dynamic type while removing the configurability. I would probably find it annoying to have to duplicate the suppression everywhere it's needed, but YMMV. |
If you're using Enterprise Groovy with defAllowed=false, and codenarc, I think it would make sense to disable or not include the NoDef rule if you were using codenarc, because you're effectively checking twice. I do have sympathy for garbage code, but if you have a lot of suppression annotations or it this case a defAllowed annotations, that's a code smell and something that should be refactored. In the documentation I do make mention of if you're adding this to a legacy project, you may have to do some whitelisting of classes at least until you can refactor code, otherwise, everything will break. It's definitely easier to start with good practices, but a lot of us don't get the chance and have to clean up after the fact. I'm not a fan of the SuppressWarning annotation, because you're not suppressing a warning you're suppressing an error. Regardless of historical reasons, I would rather the code be clear and make sense. |
While always running groovy as @CompileStatic is advantageous, there are some cases where dynamic resolution is unavoidable or even preferable. The example from our code I gave in #14 cannot easily be achieved otherwise. It's one the niceties of having a runtime resolving language. |
Sorry about the delay but it's been a busy summer... However, I'm still not convinced I should allow SuppressWarning annotation in the codebase. I don't care if it's well known, it's still the wrong annotation, for what it would be doing in this codebase. If the def checking in this plugin is superfluous for you because you are using codenarc, you can turn it off in the config. If you need to whitelist or @CompileDynamic in certain areas, to work around things, that option is available to you too. So bottom line I won't accept this PR with the SuppressWarning annotation. |
No description provided.