al-code-outline icon indicating copy to clipboard operation
al-code-outline copied to clipboard

Code Cleanup issue

Open fvet opened this issue 1 year ago • 1 comments

When I ran the code cleanup on below sample code, the file was wrongfully (?) replacing the global variable with Rec.PK, resulting in invalid code.

image

I could easily solve above case by renaming the global variable, but I'm not sure if this was the only file impacted.

Is this something that can be improved in the cleanup actions? Or maybe this could be a valid scenario for @arthurvdv to include in https://github.com/StefanMaron/BusinessCentral.LinterCop as possible new rule?

fvet avatar Mar 05 '24 21:03 fvet

It is caused by RemoveWithStatements command. It removes both implicit and explicit cases, but to be able to do it, it needs to compile project with "NoImplicitWith" "feature" disabled. Only this way compiler can detect variables that are Rec fields, but unfortunately this setting changes priorities and Rec fields are hiding variables of the same name.

With disabled "NoImplicitWith" feature compiler pretends that every function and trigger in a table/page starts with invisible "with Rec do begin....". I am thinking about splitting this functionality into 2 separate sets of commands - remove implicit with and remove explicit with. Explicit version will use current settings from app.json and will work correctly, but for "implicit" version it will always run with "NoImplicitWith" feature disabled.

anzwdev avatar Mar 05 '24 23:03 anzwdev