Closed fvet closed 2 years ago
Hi
Thank you for reporting this idea. I want to investigate first if I can make it work without waiting for CodeCop to report warnings. I am also not sure if running it on save is a good idea. Some developers like to save files in the middle of typing, if they do it when they create procedure header with local variables, but before they start populating procedure body, they will lose part of the code.
That makes perfect sense. AL files might indeed get saved a lot based on various settings and the linting and formatting should ideally only occur before actually committing the changes. In our workspaces (4800+ files), we even don't have the CodeAnalysis enabled by default (so no CodeCop to report an 'unused variable' warning), since it's terribly slow. Also the format on save and fixCodeCopMissingParenthesesOnSaveare sometimes runs for ages, so we tend to cancel these actions, mainly for larger files.
So for now, finally when the pull request is made, the developer is presented with all remaining warnings from the various CodeAnalyzers. The missing parentheses warnings are dropped a lot since the introduction of fixCodeCopMissingParenthesesOnSaveare. Now, 9 out of 10 warnings are about Unused Variables.
So main goal is to try having those fixed before the PR is made. If saving the file is not the right trigger, maybe the 'pre-commit' trigger might be the better alternative? (https://www.developerhandbook.com/react/how-to-setup-vs-code-productivity/)
PS: Maybe @DavidFeldhoff already has a non-Codecop alternative? (#226 )
For now, my solution is that you can execute a command which removes all unused variables (it compiles the solution to generate the code cops and removes the variables then)
Hi
I've released a new version of the extension with two new commands that don't need code analyzers to remove unused variables from the file opened in the editor or all files in the project:
Remove Unused Variables from the Active Editor
Remove Unused Variables from the Active Project
These commands need to compile whole solution to collect information about all symbols in the project, so it can take a few seconds to run them.I've just released another version of the extension with these 2 new commands that can add missing parentheses without using CodeCop:
Add Missing Parentheses to the Active Editor
Add Missing Parentheses to the Active Project
They work the same way as "Remove Unused Variables" commands - they need to compile whole solution to get information about all symbols.
While refactoring, we very often receive the CodeCop AA0137 warning for unused variables. Solution to fix is simple : remove the variable.
It would be nice if this could be included in the codeActionsOnSave, through a new setting fixCodeCopUnusedVariablesOnSave (similar to fixCodeCopMissingParenthesesOnSave).
So when saving an al file, any references to unused variables could be auto solved.