anzwdev / al-code-outline

AL Code Outline for Visual Studio Code
MIT License
51 stars 13 forks source link

fixCodeCopUnusedVariablesOnSave (fix AA0137 warnings) #287

Closed fvet closed 2 years ago

fvet commented 3 years ago

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.

anzwdev commented 3 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.

fvet commented 3 years ago

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 )

DavidFeldhoff commented 3 years ago

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) image image

anzwdev commented 2 years ago

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:

anzwdev commented 2 years ago

I've just released another version of the extension with these 2 new commands that can add missing parentheses without using CodeCop: