AL Coding Guidelines Extension
This VS Code extension enforces coding guidelines for Business Central AL language development. It checks files upon saving and reports issues.
Prerequisites
- Node.js: You must have Node.js installed to build this extension. Download it from https://nodejs.org/.
- VS Code: Visual Studio Code editor.
Setup Instructions
- Install Node.js: If you haven't already, download and install Node.js.
- Open Terminal: Open a terminal in this directory (
al-guidelines-extension).
- Install Dependencies: Run the following command:
npm install
- Compile the Extension:
npm run compile
- Run/Debug:
- Open this folder in VS Code.
- Press
F5 to start debugging.
- A new "Extension Development Host" window will open.
- Open an
.al file in that window to test the guidelines.
Features
- Formatting & Whitespace:
- Operators: Enforces spaces around binary operators (e.g.,
a + b).
- Keywords: Checks for space after
NOT.
- Control Structures: Ensures
if, while, repeat, and case start on a new line.
- File Structure & Naming:
- Files: Warns on empty files or files containing multiple objects.
- Naming: Enforces alphanumeric filenames (snake_case/kebab-case recommended).
- Object Definition: Validates that files start with a proper AL object type.
- Naming Conventions:
- Variables: Enforces
Temp prefix for temporary record variables.
- Control Flow:
- Deprecation: Warns about nested
WITH statements (deprecated).
- Performance:
- Data Access: Recommends
FindSet() over Find('-') or Find('+').
- UI & Accessibility:
- Page Properties: Enforces
ApplicationArea and ToolTip properties on field and action blocks in Page and PageExtension objects.
- UsageCategory: Enforces
UsageCategory property on Page objects.
- Page ApplicationArea: Enforces
ApplicationArea property on Page objects (in addition to fields/actions).
- Security & Internationalization:
- Data Security: Enforces
DataClassification property on fields in Table and TableExtension objects.
- Localization: Warns against using
CaptionML (suggests XLIFF).
- Hardcoding: Warns on hardcoded strings in
Error, Message, Confirm, and StrSubstNo, suggesting the use of Labels.
- Error Handling:
- Best Practices: Warns against using
AssertError in production code.
- Project Structure:
- Permissions: Scans the workspace to ensure at least one
permissionset or permissionsetextension object exists.
Customization
You can add more rules in src/extension.ts inside the validateALFile function.
| |