CodeCop, UICop, AppSourceCop and PerTenantExtensionCop sound like the bad cops who slow developers down. They are the opposite: the colleagues who read every line, never get tired and catch the mistakes that would otherwise reach your customers. What each one does, how to switch them on, and how to tune them so they help rather than nag.
Every police drama has the routine. The bad cop slams the table and shouts; the good cop offers a cup of tea and a way out. Business Central developers have their own squad of cops, and on first meeting they can feel like the bad kind: hundreds of yellow and red squiggles, all disapproving of code that compiles perfectly well.
Here is the twist. There is no bad cop in this story. Every one of the AL code cops is on your side. They read every line you write, they never get tired on a Friday afternoon, and they catch the mistakes that would otherwise turn up as a slow page, a failed update or a rejected AppSource submission. This post introduces the squad, what each one patrols, and how to put them to work.
The AL Language extension for Visual Studio Code ships with four code analysers, known as cops. They are part of the compiler, so they cost nothing and need nothing installing.
| Cop | Its beat | Switch it on for |
|---|---|---|
| CodeCop | Enforces Microsoft's official AL coding guidelines: naming, structure, readability and the patterns that cause performance problems. | Every project, always. |
| UICop | Checks code that customises the web client, such as page and page extension rules. | Every project with pages, which is nearly all of them. |
| PerTenantExtensionCop | Enforces the rules for extensions installed for a single customer (per-tenant extensions). | Customer-specific extensions. |
| AppSourceCop | Enforces the rules an app must meet to be published on Microsoft's marketplace, including breaking-change rules between versions and mandatory name affixes. | AppSource apps, and well worth running on per-tenant extensions too. |
The value is easiest to see in the code. Four everyday examples:
FindSet tells the server you are about to read many records. Using it to check for just one wastes effort, and CodeCop flags it (rule AA0181: FindSet and Find should only be used with Next).
// Flagged: FindSet without a loop
if PalletType.FindSet() then
HasPallets := true;
// Better: just ask whether anything exists
HasPallets := not PalletType.IsEmpty();
Unused variables (AA0137) are harmless on their own, but they are a sign that code was changed and not tidied up, and they make the next developer wonder what they were for.
AppSourceCop rule AS0011 flags any field, object or element you add to someone else's object without your affix. As we explained in why prefixes matter, one missing prefix can stop a Business Central update and force a data migration. This cop alone justifies switching AppSourceCop on.
Rename a field, delete a field or change a public procedure in a published app, and AppSourceCop compares the new version with the previous one and tells you before you ship it (for example AS0005: fields must not change name). Without it, you find out when the upgrade fails at the customer.
In your project's .vscode/settings.json:
{
"al.enableCodeAnalysis": true,
"al.codeAnalyzers": [
"${CodeCop}",
"${UICop}",
"${PerTenantExtensionCop}",
"${AppSourceCop}"
],
"al.ruleSetPath": "./bbx.ruleset.json"
}
Analysis runs in the background as you type. To check the whole project at once, build it (Ctrl+Shift+B) and read the Problems panel. If you use AppSourceCop, add an AppSourceCop.json file with your affix so AS0011 knows what to look for:
{
"mandatoryAffixes": [ "BBX" ]
}
The most common complaint about the cops is noise: hundreds of warnings on day one, many of them about style rather than substance. The answer is not to switch them off. It is a ruleset, a JSON file that decides how seriously each rule is taken, with a written reason for every exception.
{
"name": "Business Boxed ruleset",
"description": "House rules for all BBX extensions",
"rules": [
{
"id": "AS0011",
"action": "Error",
"justification": "A missing affix can block a Business Central update."
},
{
"id": "AA0181",
"action": "Error",
"justification": "FindSet without Next is a performance bug."
},
{
"id": "AA0072",
"action": "None",
"justification": "We do not suffix variable names with their type."
}
]
}
Each rule can be set to Error, Warning, Info, Hidden or None. Keep a company ruleset that every project includes (using includedRuleSets), and let a project override it only with a justification. The justification is the important part: a year later, nobody remembers why a rule was turned off unless it is written down.
For a single, deliberate exception in the code itself, use a pragma with a comment rather than turning the rule off for everyone:
#pragma warning disable AA0137 // kept for the upgrade codeunit in v2.0
var
LegacyPalletCode: Code[20];
#pragma warning restore AA0137
Cops in Visual Studio Code only help the developer who looks at the Problems panel. The real protection comes from running the same analysers, with the same ruleset, in your build pipeline, and failing the build on any error. Then a missing affix or a breaking change cannot reach a customer, whoever wrote it and however busy they were. AL-Go for GitHub and BcContainerHelper both run the analysers as part of the build.
The Business Central community has added its own officers to the force. They plug into the same al.codeAnalyzers setting and work with the same rulesets.
Commit() or hard-coded object IDs. The original repository is no longer updated; its development now continues as ALCops.Treat these as specialist units: start with the Microsoft four, then add a community cop once your codebase is clean, so its warnings stand out.
"There are too many warnings." On an old codebase, yes. Set the ruleset so only the rules that matter most are errors, fix those, and tighten it a little each release. Do not let the volume become a reason to ignore all of them.
"It slows Visual Studio Code down." On very large projects background analysis can be heavy. Microsoft documents settings to limit it to the open file, and the full check still runs on build and in the pipeline.
"AppSourceCop is for AppSource, not us." Its affix and breaking-change rules protect a per-tenant extension just as much. Switch it on, and use the ruleset to set aside the marketplace-only rules that do not apply to you.
"Our code compiles, so it is fine." Compiling means Business Central can run it. It does not mean it is fast, safe to upgrade or readable by the next developer. That is the cops' beat.
They are good, but they are not detectives. They will not tell you whether the code does what the business asked for, whether the design is sensible, or whether it works with real data. That still needs a colleague's code review and automated tests (see part 10 of our AL development series). The cops clear away the routine problems so the human review can concentrate on the important ones.
Switch on CodeCop, UICop and PerTenantExtensionCop or AppSourceCop in every project, add a ruleset with a justification for every exception, and run the same checks in your build pipeline so errors cannot be shipped. Then consider a community cop. There is no bad cop in the squad: just colleagues who read every line so your customers never have to find the mistakes.
Inherited an extension and want to know what the cops would say about it? Our AL code check runs the full squad and explains what matters, or book a 30-minute call.