This is a guest post from Automation Anywhere Most Valuable Pathfinder ChanduMohammad S, a Module Lead and Senior RPA Developer.
Currently, most of us use the manual code review process, which means we wait until development is finished before starting the code review process with the Lead Developer (or the Architect in some organizations). Every developer has a unique way of developing solution; however, to promote consistency across the team or organization, developers will be required to refer to existing Coding Best Practices for Reliability & Maintainability of the Code.
This begs the questions:
-
Do you really need to wait until the development is complete for the code review?
-
Or, during development, If you as an RPA/Citizen Developers, deviate from the set of best practices will the bot editor alert us with remediation steps to deliver the reliable code?
Automation Success Platform comes with a new feature called Code Analysis la.k.a Linter] which helps you define and enforce coding standards easily. In this tutorial, we’ll look at how to enable code analysis in the Automation Success Platform and explore how to use it.
️ Prerequisites:
-
Upgrade your control room to A360.26 version
-
Require below permissions to setup code analysis policy
-
View Policies - Allows you to view the code analysis policy that defines how you can build your automations.
-
Manage Policies - Allows you to view and edit the code analysis policy that defines how you can build your automations.
-
🏗️ Setup Code Analysis Policy
-
Access the control room by entering the user id with the required permissions.
-
Go to Administration, then Policies, as shown below.
-
Click on Edit and select Enabled in the code analysis section.
-
Enable all the required rules under Rules section in Policy editor and select a rule's High or Low severity level based on your organization's policies. Click Save changes.
💡Bonus Tips:
📌 Code Analysis policy is applied to all the control room users.
📌 Numbers less than 30 will not be accepted by the policy editor when providing input for the Action Maximum rule.
📌Variable Naming patterns:
-
Camel case - Variable names in camel case begin with a small letter. If it includes more than one word, the first letter of the subsequent word will be capitalised.
-
Ex: sBaseUrl
-
-
Pascal case - Variable names begin with a capital letter when written in Pascal case. If it includes more than one word, the first letter of the subsequent word will likewise be capital.
-
Ex: SBaseUrl
-
-
Kebab case - Variable names in the kebab case begin with small letters. If it contains more than one word, use a i-] in between them so that the second word begins with a small letter.
-
Ex: sbase-url
-
-
Snake case - It’s similar to kebab case. The only difference is replace the a-] with o_].
-
Ex: sbase_url
-
Code Analysis Rules
The Lead Developer/CoE can define rules based on the Best Practises to be enforced for developing automations across the organization. Code analysis policy editor makes it simple to configure these rules, which are then applicable to all of the Automation Success Platform code editor's available packages and commands.
Let's try to understand anatomy of the Rules in Code Analysis,
🚧Run Code Analysis
While developing the automations, you can run code analysis in both the Private and Public workspaces.
During Development: During Bot development if we (RPAs/Citizen Developers) violate any rules set by Lead Developer/CoE team, you’ll instantly get an indicator via Bot Assistant, which will also guide us on how to resolve the violations. This reduces bot failures in the production environment by allowing us to solve all issues while still in the development stage. And you’ll be adhering to all best practices and guidelines.
Let's explore one of the bots using Bot Assistant,
-
Click on Assistant, expand Issue browser to view the code analysis results.
-
In this scenario we see 7 violations in the bot
-
Go through all the violations one by one and use the provided hints to resolve the issues. Save the bot to see the latest code analysis results in the bot assistant.
The A360.25 release invokes code analysis through the automation page, however in the .26 release, every time you click Save, bot editor will automatically run the code analysis. A new column has been added to the automation page that provides a summary of the code analysis results for every file you have access to. Let's explore various results statuses for code analysis,
-
N/A: Code analysis does not apply to the object because the object is a folder or is not a bot file.
-
Not Scanned: The bot has not been scanned.
-
High severity: The bot has at least one high severity violation.
-
Low severity: The bot has at least one low severity violation, but no high severity violations.
-
No violations: The bot has been scanned in accordance with the current policy, and there are no violations.
Private Workspace: Go to private workspace, choose the bot for which you wish to invoke code analysis, then click the fly-out icon from the rightmost action’s menu e ] . Download the report for further analysis.
Public Workspace: Go to public workspace, choose the bot for which you wish to invoke code analysis, then click the fly-out icon from the rightmost action’s menu n ] . Download the report for further analysis.
You can also invoke code analysis on older version of the same bot by following below steps:
-
Go to public workspace
-
Choose the bot
-
Click the view history icon from the rightmost action’s menu r ]
-
For code analysis, select the earlier version of the bot that interests you, then click the fly-out icon from the rightmost action’s menu l ]
-
Download the report for further analysis.
Conclusion:
Hopefully you enjoyed learning how to use Code Analysis in the Automation Success Platform environment. Code analysis helps you adhere to coding best practices and make the code reliable, efficient, secure, and maintainable.
ChanduMohammad S (Automation Anywhere MVP) is a Module Lead and Senior RPA Developer with a demonstrated history of working in the information technology and services industry. In his free time, he enjoys binge watching, cooking and playing tennis.When he’s not building bots, you can find Chandu on LinkedIn as well as on the Automation Anywhere forums.
If you have an idea for a blog post or tutorial that you think would benefit the Automation Anywhere developer community, let us know at developer@automationanywhere.com.