Ruleset for the Code Analysis Tool

In an AL project, you can use a custom ruleset file to specify how code analysis will report the issues it encounters. Different settings can affect how rules are applied and each ruleset file name must follow the pattern <name>.ruleset.json to benefit from IntelliSense in Visual Studio Code.

Note

Use the truleset and trule snippets provided by the AL Language extension to create your ruleset.

The following table describes the schema of a ruleset object:

Setting Mandatory Type Value
name Yes String The name of the ruleset.
description No String The description of the ruleset. You can use this to document the purpose of the ruleset.
generalAction No Error | Warning | Info | Hidden The action to apply to all the diagnostics that have rules defined in this file or in other files that have a Default action specified and to all the diagnostics generated by the current set of analyzers that do not have a rule defined. If an included file has a stricter generalAction, that one will be used.
includedRuleSets No Array of IncludedRuleSet List of external ruleset files to include in the current ruleset. The order in which the files are processed is undefined.
rules No Array of Rule Collection of rules to apply to diagnostics generated by analyzers.

An IncludedRuleSet is a complex JSON object that defines the inclusion of an external ruleset file in the current ruleset, and has the following properties:

Setting Mandatory Type Value
path Yes String The path to the included file. For includes specified in the file to which the al.ruleSetPath is set, the path can be absolute or relative to the project folder. For files included from the root ruleset file, the path is relative to the file.
action Yes Error | Warning | Info | Hidden | None | Default The action to apply for all the diagnostics that have an action specified in the included ruleset that is different from None and Hidden.

A Rule is a complex JSON object that specifies how you can process a specific diagnostic. A Rule object has the following properties:

Setting Mandatory Type Value
id Yes String The string that uniquely identifies a diagnostic.
action Yes Error | Warning | Info | Hidden | None The action to apply if the diagnostic is emitted. There cannot be two rules with the same id and different actions in the same rule file.

Examples

The following example shows a ruleset that sets the severity of rule AA0001 : There must be exactly one space character on each side of a binary operator such as := + - AND OR =. provided by the CodeCop analyzer to Error.

{
    "name": "Company ruleset",
    "description": "These rules must be respected by all the AL code written within the company.",
    "rules": [
        {
            "id": "AA0001",
            "action": "Error",
            "justification": "This diagnostic helps to improve readability. It must be respected in all cases."
        }
    ]
}

The following example shows a project specific ruleset that extends a company wide ruleset contained in the file company.ruleset.json and sets the severity of the rule AA0005 : Only use BEGIN..END to enclose compound statements. provided by the CodeCop analyzer to Info.

{
    "name": "Personal Project ruleset",
    "description": "A list of project specific rules",
    "includedRuleSets": [
        {
            "action": "Default",
            "path": "./company.ruleset.json"
        }
    ],
    "rules": [
        {
            "id": "AA0005",
            "action": "Info",
            "justification": "For this specific project, this diagnostic should be informational."
        }
    ]
}

See Also

Using the Code Analysis Tools
Using the Code Analysis Tools with the ruleset
AL Development Environment