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
744 stars 245 forks source link

Code analyzer reports warnings for app.json #4597

Closed makuhn closed 5 years ago

makuhn commented 5 years ago

Code analyzer reports warnings for app.json which does'nt make sense: image Full message:

Analyzer 'Microsoft.Dynamics.Nav.CodeCop.Design.Rule137DoNotDeclareVariablesThatAreUnused' threw an exception of type 'System.InvalidCastException' with message 'System.InvalidCastException: Das Objekt des Typs "Microsoft.Dynamics.Nav.CodeAnalysis.Syntax.IdentifierNameOrEmptySyntax" kann nicht in Typ "Microsoft.Dynamics.Nav.CodeAnalysis.Syntax.IdentifierNameSyntax" umgewandelt werden.
   bei Microsoft.Dynamics.Nav.CodeCop.Design.Rule137DoNotDeclareVariablesThatAreUnused.UnusedVariableAnalyzer.AnalyzeSyntaxNode(SyntaxNodeAnalysisContext context) in C:\a\810\s\source\Prod\Microsoft.Dynamics.Nav.CodeCop\Design\Rule137DoNotDeclareVariablesThatAreUnused.cs:Zeile 171.
   bei Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__DisplayClass52_1.<ExecuteSyntaxNodeAction>b__1() in C:\a\810\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:Zeile 745.
   bei Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock(DiagnosticAnalyzer analyzer, Action analyze, Nullable`1 info) in C:\a\810\s\source\Prod\Microsoft.Dynamics.Nav.CodeAnalysis\DiagnosticAnalyzer\AnalyzerExecutor.cs:Zeile 1082.'

It seems that code analyzer also checks the app.json file against the rules.

AL Language extension version: 2.1.91153

AL code analysis is configured as follows:

{
    "al.enableCodeAnalysis": true,
    "al.codeAnalyzers": [
        "${AppSourceCop}",
        "${CodeCop}",
        "${UICop}"
    ],
    "al.ruleSetPath": "..\\..\\Config\\Custom.ruleset.json"
}

Custom.ruleset.json:

{
    "name": "Custom Ruleset",
    "description":"Custom Ruleset",
    "rules":[
        {
            "id": "AA0005",
            "action": "None"
        },
        {
            "id": "AA0008",
            "action": "None"
        },
        {
            "id": "AA0137",
            "action": "Error",
            "justification": "Variable '{0}' is unused in '{1}'."
        },
        {
            "id": "AS0011",
            "action": "Error"
        },
        {
            "id": "AS0016",
            "action": "None"
        },
        {
            "id": "AA0074",
            "action": "None"
        }
    ]
}
qutreson commented 5 years ago

Hi @makuhn, thank you for reporting this issue. An exception is thrown when executing the analyzer rule Rule137DoNotDeclareVariablesThatAreUnused. There is then nothing wrong with your app.json, the app.json is reported there because we use it at the default location for this kind of compiler runtime errors. Closing the issue as duplicate of #4588.