microsoft / AL

Home of the Dynamics 365 Business Central AL Language extension for Visual Studio Code. Used to track issues regarding the latest version of the AL compiler and developer tools available in the Visual Studio Code Marketplace or as part of the AL Developer Preview builds for Dynamics 365 Business Central.
MIT License
722 stars 242 forks source link

Compiler ignores AA0008 #7682

Closed cegekaJG closed 2 months ago

cegekaJG commented 4 months ago

1. Describe the bug When working with a BC14 extension, the rule AA0008 is ignored both by Visual Studio Code and the compiler when building the application locally. However, when building the application using AL Go, the compiler does correctly detect rule violations.

2. To Reproduce Steps to reproduce the behavior:

app.json

{
  "id": "OMITTED",
  "name": "OMITTED",
  "publisher": "Cegeka",
  "version": "1.0.5.0",
  "brief": "",
  "description": "",
  "privacyStatement": "",
  "EULA": "",
  "help": "",
  "url": "",
  "logo": "",
  "dependencies": [],
  "screenshots": [],
  "platform": "14.0.46080.0",
  "application": "14.21.46103.0",
  "runtime": "3.2",
  "idRanges": [
    {
      "from": 60000,
      "to": 60999
    }
  ],
  "features": [
    "NoImplicitWith",
    "TranslationFile"
  ]
}

.github/AL-Go-settings.json

{
  "buildModes": [
    "Default"
  ],
  "customCodeCops": [
    "https://github.com/StefanMaron/BusinessCentral.LinterCop/releases/latest/download/BusinessCentral.LinterCop.current.dll"
  ],
  "enableCodeCop": true,
  "enablePerTenantExtensionCop": false,
  "enableUICop": true,
  "githubRunner": "windows-latest",
  "rulesetFile": "BC14.ruleset.json",
  "runs-on": "windows-latest",
  "skipUpgrade": true,
  "templateUrl": "https://github.com/microsoft/AL-Go-PTE@main",
  "type": "PTE",
  "applicationDependency": "14.21.46103.0",
  "templateSha": "1e6ebb58fc629cc134759f996f9be9ab6ada7fb4"
}

.AL-Go/settings.json

{
  "country": "at",
  "generateDependencyArtifact": true,
  "appFolders": [],
  "testFolders": [],
  "bcptTestFolders": [],
  "installApps":[],
  "appDependencyProbingPaths":[],
  "artifact": "bcartifacts/OnPrem/14.21.46103.0//closest"
}

al.code-workspace

{
  "folders": [
    {
      "path": "Base"
    },
    {
      "path": ".AL-Go"
    },
    {
      "path": ".github"
    },
    {
      "path": "dependencies"
    },
    {
      "path": "resources"
    },
    {
      "path": "scripts"
    },
    {
      "path": "docs"
    }
  ],
  "settings": {
    "al.assemblyProbingPaths": [
      "./.netpackages",
      "C:/Windows/assembly/"
    ],
    "al.backgroundCodeAnalysis": true,
    "al.codeAnalyzers": [
      "${CodeCop}",
      "${UICop}",
      "${analyzerFolder}BusinessCentral.LinterCop.dll"
    ],
    "al.enableCodeActions": true,
    "al.enableCodeAnalysis": true,
    "al.enableExternalRulesets": true,
    "al.ruleSetPath": "../BC14.ruleset.json",
    "alOutline.addDataItemToReportColumnName": true,
    "alOutline.addToolTipsToPageFields": true,
    "alOutline.codeCleanupActions": [
      "AddApplicationAreas",
      "AddMissingParentheses",
      "ConvertObjectIdsToNames",
      "FixIdentifiersCase",
      "FixKeywordsCase",
      "MakeFlowFieldsReadOnly",
      "RemoveEmptyTriggers",
      "RemoveEmptySections",
      "RemoveStrSubstNoFromError",
      "RemoveWithStatements",
      "RemoveUnusedVariables",
      "RemoveEmptyLines",
      "SortVariables",
      "TrimTrailingWhitespace",
      "FormatDocument"
    ],
    "alOutline.fixCaseRemovesQuotesFromDataTypeIdentifiers": true,
    "alOutline.fixCodeCopMissingParenthesesOnSave": true,
    "alOutline.idReservationProvider": "ALObjectIdNinja",
    "alOutline.openDefinitionInNewTab": true,
    "CRS.ExtensionObjectNamePattern": "<Prefix><BaseName><Suffix>",
    "CRS.FileNamePattern": "<ObjectNameShort>.<ObjectTypeShortPascalCase>.al",
    "CRS.FileNamePatternExtensions": "<ObjectNameShort>.<ObjectTypeShortPascalCase>.al",
    "CRS.FileNamePatternPageCustomizations": "<ObjectNameShort>.<ObjectTypeShortPascalCase>.al",
    "CRS.ObjectNamePrefix": "",
    "CRS.ObjectNameSuffix": " NTK",
    "CRS.RenameWithGit": false,
    "editor.formatOnSave": true,
    "editor.formatOnSaveMode": "modifications",
    "files.autoSave": "afterDelay",
    "files.trimTrailingWhitespace": true,
    "githubPullRequests.assignCreated": "${user}",
    "githubPullRequests.defaultMergeMethod": "squash",
    "githubPullRequests.pullBranch": "always",
    "githubPullRequests.pushBranch": "always",
    "gitlens.advanced.blame.customArguments": [
      "-CCC"
    ],
    "gitlens.advanced.fileHistoryFollowsRenames": true,
    "gitlens.blame.ignoreWhitespace": true
  }
}

Sample page extension:

pageextension 60002 "Assembly Orders NTK" extends "Assembly Orders"
{
    trigger OnOpenPage()
    begin
        Message(UserId);
    end;
}

3. Expected behavior

For Visual Studio Code, violations of AA0008 should be highlighted when opening the AL Object in the editor. For our projects, we use a custom ruleset that escalates the severity of AA0008 from "Warning" to "Error".

When compiling locally, the build should result in failure, reporting a violation of AA0008.

When compiling using the AL Go Build pipeline, the build should result in failure, reporting a violation of AA0008. So while it's possible to compile the BC14 locally, the Build pipeline of AL Go will encounter an error. Projects using other versions of BC (22, 23) do not encounter this problem.

4. Actual behavior

image

The violation (UserId isn't followed by parentheses ()) isn't highlighted by Visual Studio Code.

Microsoft (R) AL Compiler version 12.6.14.18950
Copyright (C) Microsoft Corporation. All rights reserved

Compilation started for project 'Base' containing '30' files at '09:04:16.724'.

Compilation ended at '09:04:19.042'.

Success: The package is created.

No rule violations are detected by the compiler, and the package is created successfully.

Run microsoft/AL-Go-Actions/RunPipeline@v4.1
Run $errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0
Import from C:\ProgramData\BcContainerHelper\6.0.6\BcContainerHelper\BcContainerHelper.ps1
BcContainerHelper version 6.0.6
BC.HelperFunctions emits usage statistics telemetry to Microsoft
use settings and secrets
Analyzing repository
No performance test apps found in bcptTestFolders in .AL-Go\settings.json
Warning: No test apps found in testFolders in .AL-Go\settings.json
Checking appDependencyProbingPaths
Invoke Run-AlPipeline with buildmode Default
Parameters
Pulling generic image
Creating container
Resolving dependencies
Compiling apps

     _____                      _ _ _
    / ____|                    (_) (_)
   | |     ___  _ __ ___  _ __  _| |_ _ __   __ _    __ _ _ __  _ __  ___
   | |    / _ \| '_ ` _ \| '_ \| | | | '_ \ / _` |  / _` | '_ \| '_ \/ __|
   | |____ (_) | | | | | | |_) | | | | | | | (_| | | (_| | |_) | |_) \__ \
    \_____\___/|_| |_| |_| .__/|_|_|_|_| |_|\__, |  \__,_| .__/| .__/|___/
                         | |                 __/ |       | |   | |
                         |_|                |___/        |_|   |_|

  Using custom ruleset
  Using Version 1.0.2147483647.0

  Compiling D:\a\NTK.Base\NTK.Base\Base
  Using Symbols Folder: D:\a\NTK.Base\NTK.Base\.packages
  Processing dependency Microsoft_Application_14.21.46103.0 ()
  Downloading symbols: Microsoft_Application_14.21.46103.0.app
  Url : http://172.27.[25](https://github.com/CBS-BC-AT/NTK.Base/actions/runs/8191875073/job/22402154552#step:8:26)0.208:7049/NAV/dev/packages?publisher=Microsoft&appName=Application&versionText=14.21.46103.0&tenant=default
  Downloading using WebClient
  Processing dependency Microsoft_System_14.0.4[60](https://github.com/CBS-BC-AT/NTK.Base/actions/runs/8191875073/job/22402154552#step:8:62)80.0 ()
  Downloading symbols: Microsoft_System_14.0.46080.0.app
  Url : http://172.27.250.208:7049/NAV/dev/packages?publisher=Microsoft&appName=System&versionText=14.0.46080.0&tenant=default
  Downloading using WebClient
  Compiling...
  .\alc.exe /project:"c:\sources\Base" /packagecachepath:"c:\sources\.packages" /out:"c:\sources\.output\Cegeka_Base_1.0.2147483647.0.app" /analyzer:C:\build\vsix\extension\bin\Analyzers\Microsoft.Dynamics.Nav.CodeCop.dll /analyzer:C:\build\vsix\extension\bin\Analyzers\Microsoft.Dynamics.Nav.UICop.dll /ruleset:c:\sources\BC14.ruleset.json /assemblyprobingpaths:"C:\Program Files (x86)\Microsoft Dynamics NAV\140\RoleTailored Client","C:\Program Files\Microsoft Dynamics NAV\140\Service","C:\Program Files (x86)\Open XML SDK\V2.5\lib","c:\Windows\Microsoft.NET\Assembly"
  Microsoft (R) AL Compiler version 3.0.5.47103
  Copyright (C) Microsoft Corporation. All rights reserved

  Compilation started for project 'Base' containing '30' files at '17:16:19.966'.

  Error: AA0008 You must specify open and close parenthesis after 'RecordId'.
  Error: AA0008 You must specify open and close parenthesis after 'GuiAllowed'.
  Error: AA0008 You must specify open and close parenthesis after 'RecordId'.

  Compilation ended at '17:16:25.918'.

  App generation failed with exit code 1
  Compile-AppInBcContainer Telemetry Correlation Id: 926a83f7-80a5-4dcd-ada1-6[76](https://github.com/CBS-BC-AT/NTK.Base/actions/runs/8191875073/job/22402154552#step:8:79)9e1f78afb
Removing container
Run-AlPipeline Telemetry Correlation Id: 118ec119-d28a-46f1-8087-defa5419f7bc
AL-Go action ran: RunPipeline Telemetry Correlation Id: 74f6dd7e-6753-43c5-a65c-d2467e9dc0e1
Error: Unexpected error when running action. Error Message: App generation failed with exit code 1, StackTrace: at <ScriptBlock>, C:\ProgramData\BcContainerHelper\6.0.6\BcContainerHelper\AppHandling\Compile-AppInNavContainer.ps1: line [77](https://github.com/CBS-BC-AT/NTK.Base/actions/runs/8191875073/job/22402154552#step:8:80)6 <- at Compile-AppInBcContainer, C:\ProgramData\BcContainerHelper\6.0.6\BcContainerHelper\AppHandling\Compile-AppInNavContainer.ps1: line 776 <- at <ScriptBlock>, C:\ProgramData\BcContainerHelper\6.0.6\BcContainerHelper\AppHandling\Run-AlPipeline.ps1: line 817 <- at <ScriptBlock>, C:\ProgramData\BcContainerHelper\6.0.6\BcContainerHelper\AppHandling\Run-AlPipeline.ps1: line 1936 <- at <ScriptBlock>, C:\ProgramData\BcContainerHelper\6.0.6\BcContainerHelper\AppHandling\Run-AlPipeline.ps1: line 1477 <- at <ScriptBlock>, C:\ProgramData\BcContainerHelper\6.0.6\BcContainerHelper\AppHandling\Run-AlPipeline.ps1: line 1470 <- at <ScriptBlock>, C:\ProgramData\BcContainerHelper\6.0.6\BcContainerHelper\AppHandling\Run-AlPipeline.ps1: line 948 <- at Run-AlPipeline, C:\ProgramData\BcContainerHelper\6.0.6\BcContainerHelper\AppHandling\Run-AlPipeline.ps1: line 910 <- at <ScriptBlock>, D:\a\_actions\microsoft\AL-Go-Actions\v4.1\RunPipeline\RunPipeline.ps1: line 368 <- at <ScriptBlock>, D:\a\_temp\e8153caf-d4e5-4cef-b8ec-848fcb00ad96.ps1: line 4 <- at <ScriptBlock>, <No file>: line 1
Error: Process completed with exit code 1.

Edit: Doing further experimentation, I noticed that only select functions don't cause a violation. These are the ones I've noticed so far:

5. Versions:

dannoe commented 4 months ago

You are using a ruleset and specify two different paths: "rulesetFile": "BC14.ruleset.json", and "al.ruleSetPath": "../BC14.ruleset.json",

Make sure that the relative path is correct for vscode.

cegekaJG commented 4 months ago

Both of them are correct - the paths are relative to the config files respectively, and .github/AL-Go-settings.json is located in a subfolder in the repository root. I can tell because other modified rule behavior is being applied to VSC.

kalberes commented 4 months ago

Can you repro with the latest compiler? This repo is for dealing with issues on teh latest compiler version including and emphasizing the pre-release version.

cegekaJG commented 4 months ago

I've tried it both on v12.6.936426 (which is the latest version according to the VS Code Extension and v14.0.956192 (pre-release). In both cases, the violation was ignored, both during analysis and compilation.

dannoe commented 4 months ago

I can not reproduce this.

Are there any AL related settings inside your user settings.json or the folder settings.json?

According to your workspace file your directory structure is the following:

/root/BC14.ruleset.json
/root/foo/al.code-workspace
/root/foo/Base/
/root/foo/.github/AL-Go-settings.json
...

Is this correct?

cegekaJG commented 4 months ago

Not quite - the structure is as follows:

root/
├ .github/
| └ AL-Go-settings.json
├ Base/
| └ app.json 
├ BC14.ruleset.json
└ al.code-workspace

I've gotten the two properties confused in my earlier comment. The AL extension has root/Base as it's CWD, whereas the AL Go pipeline uses root.

I don't have any .vscode/settings.json files, and these are my user settings:

{
    "[al]": {
        "editor.tabSize": 4
    },
    "[jsonc]": {
        "editor.defaultFormatter": "vscode.json-language-features"
    },
    "[markdown]": {
        "editor.defaultFormatter": "DavidAnson.vscode-markdownlint"
    },
    "[powershell]": {
        "editor.defaultFormatter": "ms-vscode.powershell"
    },
    "[python]": {
        "editor.defaultFormatter": "ms-python.black-formatter",
        "editor.formatOnType": true
    },
    "[xml]": {
        "editor.defaultFormatter": "DotJoshJohnson.xml"
    },
    "[yaml]": {
        "editor.defaultFormatter": "redhat.vscode-yaml"
    },
    "al.enableCodeActions": true,
    "alOutline.addDataItemToReportColumnName": true,
    "alOutline.addToolTipsToPageFields": false,
    "alOutline.codeActionsOnSave": [
        "SortVariables",
        "SortProperties",
        "FormatDocument"
    ],
    "alOutline.codeCleanupActions": [
        "ConvertObjectIdsToNames",
        "RemoveStrSubstNoFromError",
        "RemoveWithStatements",
        "RemoveEmptyTriggers",
        "RemoveEmptySections",
        "RemoveBeginEnd",
        "RemoveUnusedVariables",
        "SortVariables",
        "SortProperties",
        "FixKeywordsCase",
        "MakeFlowFieldsReadOnly",
        "FixIdentifiersCase",
        "AddApplicationAreas",
        "AddTableFieldCaptions",
        "RefreshToolTips",
        "AddToolTips",
        "AddMissingParentheses",
        "TrimTrailingWhitespace",
        "RemoveEmptyLines"
    ],
    "alOutline.fixCaseRemovesQuotesFromDataTypeIdentifiers": true,
    "alOutline.fixCodeCopMissingParenthesesOnSave": true,
    "alOutline.openDefinitionInNewTab": true,
    "black-formatter.args": [
        "--line-length",
        "80"
    ],
    "cSpell.enableFiletypes": [
        "!json",
        "!code-workspace"
    ],
    "cSpell.userWords": [
        "Cegeka",
        "ruleset"
    ],
    "diffEditor.ignoreTrimWhitespace": false,
    "editor.accessibilitySupport": "off",
    "editor.bracketPairColorization.independentColorPoolPerBracketType": true,
    "editor.defaultFormatter": "ms-dynamics-smb.al",
    "editor.fontSize": 16,
    "editor.formatOnSave": true,
    "editor.rulers": [
        80
    ],
    "editor.suggestSelection": "first",
    "editor.tabSize": 2,
    "errorLens.enabledDiagnosticLevels": [
        "warning",
        "info"
    ],
    "explorer.confirmDelete": false,
    "explorer.confirmDragAndDrop": false,
    "explorer.confirmPasteNative": false,
    "files.autoSave": "afterDelay",
    "git.autofetch": true,
    "git.confirmSync": false,
    "git.enableSmartCommit": true,
    "git.openRepositoryInParentFolders": "always",
    "git.pruneOnFetch": true,
    "githubPullRequests.assignCreated": "${user}",
    "githubPullRequests.defaultMergeMethod": "squash",
    "githubPullRequests.fileListLayout": "tree",
    "githubPullRequests.notifications": "pullRequests",
    "githubPullRequests.pullBranch": "always",
    "githubPullRequests.pullRequestDescription": "Copilot",
    "githubPullRequests.pushBranch": "always",
    "githubPullRequests.remotes": [
        "origin"
    ],
    "gitlens.advanced.blame.customArguments": [
        "-CC"
    ],
    "gitlens.advanced.fileHistoryFollowsRenames": true,
    "gitlens.advanced.messages": {
        "suppressCommitHasNoPreviousCommitWarning": true
    },
    "gitlens.ai.experimental.openai.model": "gpt-4-1106-preview",
    "gitlens.ai.experimental.provider": "openai",
    "gitlens.blame.ignoreWhitespace": true,
    "gitlens.defaultDateShortFormat": "D MMM, YYYY",
    "gitlens.defaultTimeFormat": "H:mm",
    "json.schemas": [
        {
            "fileMatch": [
                "/.github/AL-Go-Settings.json"
            ],
            "url": "https://raw.githubusercontent.com/microsoft/AL-Go/main/Schema/algoreposettingssyntax.json"
        },
        {
            "fileMatch": [
                "/.AL-Go/settings.json"
            ],
            "url": "https://raw.githubusercontent.com/microsoft/AL-Go/main/Schema/algosettingssyntax.json"
        }
    ],
    "markdown.extension.toc.levels": "2..6",
    "NAB.IncludeTablesAndFieldsInDocs": true,
    "powershell.promptToUpdatePowerShell": false,
    "python.analysis.stubPath": "",
    "security.workspace.trust.untrustedFiles": "open",
    "todo-tree.general.tags": [
        "BUG",
        "HACK",
        "FIXME",
        "TODO",
        "XXX",
        "[ ]",
        "[x]"
    ],
    "todo-tree.regex.regex": "(//|#|<!--|;|/\\*|^|^\\s*(-|\\d+.))\\s*($TAGS)",
    "todohighlight.keywords": [],
    "vsicons.dontShowNewVersionMessage": true,
    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "window.menuBarVisibility": "compact",
    "window.title": "${dirty}${rootName}",
    "workbench.colorCustomizations": {},
    "workbench.iconTheme": "vscode-icons",
    "XLF: Empty": true,
    "XLF: Empty Local Translation": true,
    "XLF: Search": "",
    "XLF: State": false
}
dannoe commented 4 months ago

In your workspace file you have "al.ruleSetPath": "../BC14.ruleset.json", so it will go back one directory (starting from the folder of the workspace file) and look for BC14.ruleset.json there. Can you try to put just "BC14.ruleset.json" and do a Reload window or just restart vsc.

cegekaJG commented 4 months ago

I tried that earlier, I got an error:

An error occurred while loading the included rule set file c:\root\Base\BC14.ruleset.json - Could not find file 'c:\root\Base\BC14.ruleset.json'.

I've also tried removing the custom ruleset entirely, and the compiler still didn't report the violation. By default, the rule action isn't hidden, so it should at least provide a warning. Additionally, all other customizations to the rule severity are being applied correctly, so I don't think the ruleset is the problem.

dannoe commented 4 months ago

I probably found the problem:

UserId, GuiAllowed, etc. are allowed to be called without parenthesis: see https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/system/system-guiallowed-method):

This method can be invoked using property access syntax.

The newest compiler (e.g. Microsoft (R) AL Compiler version 12.6.14.18950) does not warn (or even emit AA0008) on these calls. The compiler used on your pipeline Microsoft (R) AL Compiler version 3.0.5.47103 does still emit this diagnostic.

To be sure you could install the old compiler and test this theory.

Edit: Just test this with a normal procedure:

    trigger OnRun()
    begin
        Message(UserId); // no error/warning
        MyProcedure; // error/warning
    end;

    local procedure MyProcedure()
    begin
    end;
cegekaJG commented 4 months ago

Is this an error or did the rules change? The article on AA0008 doesn't mention anything about exceptions.

kalberes commented 4 months ago

We may update the documentation but we will probably not fix issues that are on the old unsupported versions of the al compiler. @dannoe thanks for the investigation