BC AL Analyzer
Facts about your Business Central AL code, and commands that make it easier to read without
changing what it does. Every change is checked by building the project with Microsoft's AL Language
extension, and can be undone in one step.
Preview. The extension is young. Try it on code under version control, and please report what
it gets wrong in the issues.
Features
Count Record variables
BC AL Analyzer: Count Record Variables and the status bar show how many variables of type Record
the active AL file declares: globals, locals, parameters, named return values, the implicit
Rec/xRec, report dataitems and XMLport table elements. RecordRef, RecordId and FieldRef
are not counted, nor is anything inside comments or strings.
Exact rules
Improve Readability
Three commands, in the command palette and in the context menu of AL files:
| Command |
Changes |
| Improve Readability of Procedure |
the procedure or trigger at the cursor |
| Improve Readability of Object |
every procedure and trigger of the object |
| Improve Readability of Project |
every AL file of the project (app.json) |
First, AL Language's own quick fixes qualify with statements and the implicit with of Rec
(AL0604 to AL0607). Then the code is simplified, for example:
// Before
if Customer.FindSet() then begin
repeat
if Customer.Blocked = true then begin
Customer.Validate(Blocked, false);
end;
until Customer.Next() = 0;
end;
// After
if not Customer.FindSet() then
exit;
repeat
if Customer.Blocked then
Customer.Validate(Blocked, false);
until Customer.Next() = 0;
The rules: early exit instead of nesting, no else after exit or Error, no begin..end around
a single statement, no comparison with true/false, not (A = B) as A <> B, and, as options,
continue in loops and case for long else if chains. Code the extension does not fully
understand, or where a comment would move, is left alone.
Rules · with statements
Safe by design
- The project is built before the change. If it does not build, you are told that the change
cannot be verified.
- The change is made and the project is built again.
- If there are new errors, you get Undo and Show Problems. Undo restores every changed
file, also for the whole project.
Requirements
- Visual Studio Code 1.110 or later.
- Microsoft's AL Language
extension. VS Code installs it with this one.
- An AL project (
app.json) for the build check.
Settings
| Setting |
Default |
What it does |
bcAlAnalyzer.statusBar.enabled |
true |
Show the number of Record variables in the status bar. |
bcAlAnalyzer.readability.preview |
false |
Show the changes side by side and ask before applying them. |
bcAlAnalyzer.readability.qualifyWith |
true |
Run AL Language's quick fixes for with first. |
bcAlAnalyzer.readability.useContinue |
true |
Use continue in loops (needs runtime 15.0 or later). |
bcAlAnalyzer.readability.ifChainToCase |
false |
Turn chains of three or more else if into case. |
Known limits
- The build proves that the code compiles, not that it behaves the same. The rules are written and
tested to keep the behaviour, but review the change like any other.
- AL Language's quick fixes are run through a command that Microsoft does not document. If a future
AL Language changes it,
with statements are simply left alone.
Contributing
Bug reports and ideas are welcome in the
issues. To build and test the extension
yourself, see CONTRIBUTING.md.
License
MIT