Friday, 17 November 2017

Lightning Component Code Review using Command Line Interface (CLI)

The Salesforce world is moving fast with Lightning. Lightning is an efficient and consistent interface to navigate through your org and the Lightning Experience takes things to another level. In order to enables us to leverage our code, ensuring at the same time that we follow the Salesforce recommended best practices, Salesforce has introduced Lightning Command Line Interface(CLI).

WHAT IS LIGHTNING CLI?


Lightning CLI is a Heroku Toolbelt plugin that lets you scan your code for general JavaScript coding issues and Lightning-specific issues. This tool is based on the ESLint project and finds the issues within the JavaScript code.  As your Lightning component mostly consists of client-side code in the form of JavaScript, it becomes pertinent to have code review checks on a periodic basis.

Lightning CLI alerts you to specific issues related to LockerService. Issues that are flagged include incorrect Lightning components code, and usage of unsupported or private JavaScript API methods. Lightning CLI installs into the Heroku Toolbelt, and is used on the command line.

HOW TO USE LIGHTNING CLI?


Step 1: Heroku Installation
Download the Heroku toolbelt on your machine from the following link:
https://toolbelt.heroku.com/

Step 2: Install Salesforce Lightning CLI
Install Lightning CLI as a Heroku Toolbelt plugin. Once this is done, update the Heroku Toolbelt to get the latest Lightning CLI rules.
heroku plugins:install salesforce-lightning-cli



Step 3: Use Salesforce Lightning CLI
  1. To display the Code Review on the command prompt in a text format, use:
    heroku lightning:lint
  2. To display the Code Review on the command prompt in a JSON format, use:
    heroku lightning:lint . -j
  3. To get the Code Review as a File in a json or text format, use:
    heroku lightning:lint .(Source Path) > report.txt

    heroku lightning:lint "D:\Lightning Component\ContactList\src\aura\campingList" > report.txt

    OR
    heroku lightning:lint "D:\Lightning Component\ContactList\src\aura\campingList" -j > report.json



ADVANTAGES

There are quite a few advantages of using the Lightning CLI:
  1. Scan the code locally on the lightning component implemented before submitting the code for reviews
  2. Check/discover the issue related to security and unused variables
  3. Enforce security and code best practices across implementation

I hope you are all set to use the Lightning CLI. In case you feel the need to reference additional knowledge material, the following links are quite helpful:


References




Written by Twinkle Panjabi, Sr. Salesforce Developer at Eternus Solutions

8 comments:

  1. It’s really amazing that we can record what our visitors do on our site. Thanks for sharing this awesome guide. I’m happy that I came across with your site this article is on point,thanks again and have a great day. Keep update more information..

    Hadoop Training in Chennai

    ReplyDelete
  2. very informative blog and very useful for readers. making us to learn more from your blog...
    SAP Basis Training in Chennai

    ReplyDelete
  3. I got lot of information from your blog.And thanks for sharing...
    SAP MM Training in Chennai

    ReplyDelete
  4. Omrdeals.in is an online platform that allows people to find offers and the greatest deals in and around OMR. It is the directory of the business in and around omr. It helps internet users to surf the required deals and offers.

    Offers in Chennai

    ReplyDelete
  5. It is really very excellent. Because of all given information was wonderful and it's very helpful for me. Thanks for sharing
    SAP Training in Chennai
    SAP ABAP Training in Chennai
    SAP FICO Training in Chennai
    SAP MM Training in Chennai

    ReplyDelete
  6. Thanks for the informative article. This is one of the best resources I have found in quite some time. Nicely written and great info. I really cannot thank you enough for sharing.

    OFFERS IN CHENNAI

    ReplyDelete
  7. Benefits of reading your post. This will help in the maintenance of our health.The daily routine will help you lose weight quickly and safely.My life is totally transformed after I followed this diet.I feeling great about myself.

    Herbalife in Chennai
    Herbalife Nutrition Products
    Nutritionclub in Chennai
    Weight Loss in Chennai
    Weight Gain in Chennai

    ReplyDelete