How to use Code Analysis Tool for AL in BC
Few days ago, the demo was given by me on the code analysis for AL among our team. I would like to share the same knowledge with you on the code analysis.Follow the bellow steps in your project to enable code analysis in the business central.
- Open command pallete ( Ctrl + Shift + P ) and choose either User Setting or Workspace settings.
- Basic setting is al.enablecodeanalysis and make it to true.
- Now, set the al.codeanalyzer with the different values. Here, there are four values (AppSourceCop, CodeCop, PerTenantExtensionCop, UICop) available to use. Here, we will user CodeCop and PerTenantExtensionCop.
- CodeCop is an analyzer that enforce the official AL coding guidelines.
- AppSourceCop is an analyzer that enforce rules that must be respected by extensions meant to be published to Microsoft App Source.
- PerTenantExtensionCop is an analyzer that enforce rules that must be respected by extensions meant to be installed for an individual tenant.
- UICop is an analyzer that enforce rules that must be respected by extensions meant to be customise the web client.
- We can break the code analysis by adding our custom ruleset in the project. Here for the example we will break the code PTE0004 code. To create a new custom rule first of all we need to create a file which follow <name>.ruleset.json . Here, we will create ImportExportExcel.ruleset.json file as below.
- Now, again we will open setting.json file and add the path of the custom ruleset.
- When you build the project after adding the custom ruleset, you can find that error is converted in to the warning for code PTE0004.
Check out the official docs by the microsoft for more information :
I hope this thing will help you for the better coding in the AL😊.
Regards,
Harshil Patel
Comments
Post a Comment