Enforce AL quality with code analysis
Configuration and dependency management keep a workspace connecting and building correctly. Code analysis keeps the code inside those projects consistent with a shared quality bar as more developers contribute to it.
Select analyzers and enable code analysis
The AL Language extension includes four code analyzers, each covering a different concern:
- CodeCop enforces the official AL coding guidelines, such as spacing and naming conventions.
- PerTenantExtensionCop enforces rules required for extensions installed directly to a single tenant.
- AppSourceCop enforces rules required for extensions submitted to Microsoft Marketplace.
- UICop enforces rules for extensions that customize the web client user interface.
Turn on analysis with the al.enableCodeAnalysis setting, and list the
analyzers you want to run with al.codeAnalyzers:
{
"al.enableCodeAnalysis": true,
"al.codeAnalyzers": [
"${CodeCop}",
"${PerTenantExtensionCop}"
]
}
Set these values in settings.json at the user, workspace, or individual
project level. A workspace-level setting applies to every project in a
multi-root workspace unless a specific project overrides it, so choose
the scope that matches whether every project in the workspace needs the
same analyzers. Once enabled, the analyzers run in the background as you
edit, and again on the whole project when you build with
Ctrl+Shift+B. Diagnostics appear inline in the editor and in the
Problems view. Learn more in
The code analysis tool.
Configure a ruleset to control diagnostic severity
A ruleset file lets you change how code analysis reports specific
diagnostics without changing the analyzer selection. Name the file with
the pattern <name>.ruleset.json so Visual Studio Code provides
IntelliSense while you edit it, and point to it with the
al.ruleSetPath setting.
{
"name": "Workspace ruleset",
"description": "Rules that apply to every project in this workspace.",
"rules": [
{
"id": "AA0005",
"action": "Error",
"justification": "Explicit BEGIN..END blocks are required for readability in this codebase."
}
]
}
Each rule sets an action of Error, Warning, Info, or Hidden for
a specific diagnostic ID. A project-specific ruleset can also include a
shared ruleset with includedRuleSets, so a team-wide file defines
common rules and individual projects only override what's different for
that project. Reserve Hidden for diagnostics your team has deliberately
decided not to act on, and document the reason in the justification
field. Hiding a diagnostic only changes what the build reports; it
doesn't change the underlying code, so use it sparingly and only when the
governance decision is intentional. Learn more in
Ruleset for the code analysis tool.
Interpret diagnostics and integrate analysis into the workflow
A diagnostic identifies the rule ID, the affected file and line, and the analyzer that raised it. Before you suppress or change the severity of a diagnostic, confirm which analyzer produced it and what that analyzer is designed to protect. A CodeCop diagnostic about formatting has a different governance impact than an AppSourceCop diagnostic about a required field property, even though both appear in the same Problems view.
Treat a clean result from one analyzer as partial evidence, not complete evidence, of quality. A project can pass CodeCop with no issues while still failing AppSourceCop rules required for Marketplace submission, or while a manual test uncovers a defect no analyzer checks for. Combine code analysis with the manual verification steps your team already uses, such as a build validation step in a continuous integration pipeline, so analyzer results and test results are reviewed together before a change is accepted.
On a large project, background analysis can slow down editing. Rather than turning analysis off, review the available performance settings for the code analysis tool, such as scoping analysis to changed files during active editing while still running the full analyzer set during a Ctrl+Shift+B build. This keeps the editor responsive without reducing the coverage your team relies on for the build.
For a workspace built through an automated pipeline, run the same
analyzers and ruleset in the pipeline's build step that developers run
locally. Passing analysis in the editor but skipping it in the pipeline,
or the reverse, leads to inconsistent enforcement, where some quality
issues only surface after a change already merged. Keeping the local and
pipeline configuration identical, including the same al.codeAnalyzers
list and the same ruleset file, gives the team one consistent quality bar
regardless of where the build runs.