Monday, April 20, 2020

Learning Business Central Development from Scratch: The Four Different Code Analyzers

By Steve Endow

As part of the AL Development Online Training class, I'm working on my first AL project.

When you create a new AL project in VS Code, one of the many options available are the "al.enableCodeAnalysis" and "al.codeAnalyzers" settings in one of your "settings.json" files.

Update: Here is a blog post by "Waldo" (Eric Wauters) on enabling the AL code analyzers

Option 1: Save the options in the User settings.json file.  This will enable the AL code analyzers for all of your projects.  If you always want the same settings for all of your projects, this option might be the easiest.

CTRL + comma  ->  Extensions  ->  AL Language extension  -> Code Analyzers  ->  Edit in settings.json

AL Code Analyzer Settings in the User Settings File

Option 2:  Save the options in each Workspace settings.json file.  This will allow you to have different code analyzer settings for each AL project.  The Workspace settings file is the one that you see in your File Explorer pane on the left side of the VS Code window, under the .vscode folder.

Workspace Settings File

Based on the intellisense suggestions offered by VS Code, I happened to learn that there are four code analyzers.  But I don't yet know which ones I should enable in my project.  I'm sure I'll learn that soon.

Here's some basic info on each.  I'm open to more info and suggestions on when to use each, or when to not use some of them.

App Source Cop

"AppSourceCop is an analyzer that enforces rules that must be respected by extensions meant to be published to Microsoft AppSource."

I suppose if you aren't planning on deploying your extension to AppSource, you can omit this cop?  But perhaps this cop provides some suggestions for AL best practices, even if you aren't going to publish on AppSource?


Code Cop

"CodeCop is an analyzer that enforces the official AL Coding Guidelines."

Sounds pretty legit.  This one sounds like a must-have for all AL projects.

Per Tenant Extension Cop

"PerTenantExtensionCop is an analyzer that enforces rules that must be respected by extensions meant to be installed for individual tenants."

My guess is that this is the alternative to AppSourceCop?  If you aren't planning on publishing to AppSource, then you must be planning on installing an extension in a single tenant?  And you'd therefore want to use PerTenantExtensionCop instead?

I'm missing what?

The one issue I ran into with PerTenantExtensionCop is that it immediately gave me a warning about "missing a matching permission set".  I don't yet know what that means, but it looked like a hassle I didn't want to deal with yet, so I removed PerTenantExtensionCop from my user settings file for the time being.

UI Cop

"UICop is an analyzer that enforces rules that must be respected by extensions meant to customize the Web Client."

That seems pretty straightforward--if I'm going to be working with UI elements on the Business Central Web Client, UICop presumably helps me avoid dumb mistakes.  Gotcha.

And Waldo recommended that I use UICop.  So that's really all I need to know.  Do what Waldo says.

As you wish

Steve Endow is a Microsoft MVP in Los Angeles.  He works with Dynamics 365 Business Central, Power Automate, Power Apps, Azure, Dynamics GP, SQL Server, and .NET

You can also find him on Twitter and YouTube

No comments:

Post a Comment

All comments must be reviewed and approved before being published. Your comment will not appear immediately.

How many digits can a Business Central Amount field actually support?

 by Steve Endow (If anyone has a technical explanation for the discrepancy between the Docs and the BC behavior, let me know!) On Sunday nig...