# Advanced CodeCop Analyzer and Custom Rulesets (Business Central)

_Published: 2024-01-05 · Author: Finn_

## Advanced CodeCop Analyzer and Custom Rulesets

We have already talked about [Rulesets in Business Central](/programming/2023/10/10/BC-Rulesets.html).

This article is about extending it to have multiple ruleset files and using CodeCop Analyzers from the community.

**Attention:** This only works on a Windows PC. It does not work on a Mac.

### Update - LinterCop is deprecated

If you want to upgrade to ALCop then read this article: [There is a new sheriff in town](/programming/2026/07/22/there-is-a-new-sheriff-in-town.html)

## Setup

Find your workspace settings file in the `.vscode` folder. It is named `settings.json` and
make sure you have this:

``````json
{
    "al.enableCodeAnalysis": true,
    "al.codeAnalyzers": [
        "${CodeCop}",
        "${UICop}",
        "${PerTenantExtensionCop}",
        "${analyzerFolder}BusinessCentral.LinterCop.dll",
        "${analyzerFolder}CompanialCopAnalyzer.dll",
    ],
    "al.backgroundCodeAnalysis": "Project",
    "al.ruleSetPath": "./.vscode/Main.ruleset.json",
``````

The `Main.ruleset.json` file is used to point to the other ruleset.json files.
It should not contain any rules.

``````json
{
    "name": "Personal Project ruleset",
    "description": "A list of project specific rules",
    "includedRuleSets": [
        {
            "action": "Default",
            "path": ".rulesets/AfterConversion.ruleset.json"
        },
        {
            "action": "Default",
            "path": ".rulesets/LinterCopIgnore.ruleset.json"
        },
        {
            "action": "Default",
            "path": ".rulesets/CompanialCopIgnore.ruleset.json"
        }
    ]
}
``````

The rulesets are placed in a subfolder `.rulesets` in the `.vscode` folder.

## BusinessCentral.LinterCop

[Stefan Maroń](https://stefanmaron.wordpress.com/) is the author of the [BusinessCentral.LinterCop](https://marketplace.visualstudio.com/items?itemName=StefanMaron.businesscentral-lintercop)

After having installed the LinterCop, I am ignoring some of Stefan's rules.

Add the `LinterCopIgnore.ruleset.json` file to the `.rulesets` folder with the following
content.

``````json
{
    "name": "Ignore.BusinessCentral.LinterCop",
    "description": "Suppressing some BusinessCentral.LinterCop rules.",
    "rules": [
        {
            "id": "LC0047",
            "action": "None",
            "justification": "Locked Label must have a suffix Tok."
        },
        {
            "id": "LC0025",
            "action": "None",
            "justification": "Procedure must be either local, internal or define a documentation comment."
        },
        {
            "id": "LC0010",
            "action": "None",
            "justification": "Cyclomatic Complexity."
        }
    ]
}
``````

Once the file is in place, it becomes much easier to activate or deactivate rules.

### LinterCop Configuration

Place the following file `LinterCop.json` in the root of your project.

You can then configure the settings below. Maybe you want the thresholds to be bigger.

``````json
{
  "cyclomaticComplexityThreshold": 8,
  "maintainabilityIndexThreshold": 20,
  "enableRule0011ForTableFields": false,
  "enableRule0016ForApiObjects": false
}
``````

## Custom Rule Cop

[CompanialCop](https://github.com/Companial/CompanialCop) is an interesting solution to missing rules.

If you are interested in diving deeper into this, I suggest watching this video on YouTube
[Automating Dynamics 365 Business Central Code Quality: A Guide to Using Custom Code Analysis for AL](https://www.youtube.com/watch?v=TP_xy0seRQs)
by [Tine Staric](https://www.linkedin.com/in/tstaric/).

You can download the `CompanialCopAnalyzer.dll` file from the [CompanialCop/releases](https://github.com/Companial/CompanialCop/releases) page and
place it in the AL Extension folder. For example `%userprofile%\.vscode\extensions\ms-dynamics-smb.al-7.4.502459\bin\`.

Add the `CompanialCopIgnore.ruleset.json` file to the `.rulesets` folder with the following
content.

``````json
{
    "name": "Ignore.Companial.CodeCop",
    "description": "Suppressing some Companial.CodeCop rules.",
    "rules": [
        {
            "id": "CM0002",
            "action": "None",
            "justification": "Locked Label must have a suffix Tok."
        },
        {
            "id": "CM0012",
            "action": "None",
            "justification": "Procedure must be either local or internal."
        },
        {
            "id": "CM0017",
            "action": "None",
            "justification": "Object should not have empty sections. Test functions are allowed to have empty sections."
        },
        {
            "id": "CM0018",
            "action": "None",
            "justification": "Objects need to have the Access/Extensible properties defined."
        },
        {
            "id": "CM0023",
            "action": "None",
            "justification": "The identifier must have at least one of the mandatory affixes."
        }
    ]
}
``````

## What rules should you ignore?

You should not choose to follow all their rules.
Which brings up a good question.

**How do I know which rules to follow, and which not to follow?**

The answer is **consistency**.

Is the rule consistent with what Microsoft does?

In general, I recommend staying as close as possible to the Microsoft way of programming.

## Clean AL Code Initiative

- Part 1: [Rulesets in Business Central](/programming/2023/10/10/BC-Rulesets.html)
- Part 2: [Namespaces in AL](/programming/2023/12/28/Namespaces-in-AL.html)
- Part 3: [VS Code Extensions for AL](/programming/2023/12/29/Extensions-for-AL.html)
- Part 4: [Automated Tests in AL](/programming/2024/01/03/Automated-Tests-in-AL.html)
- **Part 5**: [Advanced CodeCop Analyzer and Custom Rulesets](/programming/2024/01/05/BC-Advanced-Rulesets.html)
- Part 6: [How to make a code review](/programming/2024/01/11/how-to-make-a-code-review.html)
- Part 7: [Preconditions and TryFunctions in AL](/programming/2024/01/12/TryFunctions-in-AL.html)
- Part 8: [There is a new sheriff in town](/programming/2026/07/22/there-is-a-new-sheriff-in-town.html)

## Super fast tests covering 100% of your code

- Part 1: [Environment Interfaces - Part 1 - System Environment](/programming/2025/06/26/environment-interface-part-1.html)
- Part 2: [Environment Interfaces - Part 2 - External API](/programming/2025/06/26/environment-interface-part-2.html)
- Part 3: [Environment Interfaces - Part 3 - Standard Application](/programming/2025/06/26/environment-interface-part-3.html)
- Part 4: [Temporary Tables in Tests](/programming/2025/06/26/temporary-tables-in-tests.html)

---

[View the normal web page](https://www.finnpedersenfrance.com/programming/2024/01/05/BC-Advanced-Rulesets.html)
