UNPKG

5.65 kBMarkdownView Raw
1# Salesforce Lightning CLI
2
3The Salesforce Lightning CLI is a code review tool that lets you scan your code for Lightning-specific issues. This tool is extremely useful for preparing your Lightning code for the forthcoming LockerService addition to the Lightning Platform.
4
5Lightning CLI is a linting tool based on the open source ESLint project. Like ESLint, it flags issues it finds in your code. Lightning CLI alerts you to specific issues related to LockerService. Issues that are flagged include incorrect Lightning components code, use of unsupported or private Lightning APIs, and a number of general JavaScript coding issues. Lightning CLI installs into the Heroku Toolbelt, and is used on the command line.
6
7
8## Installation
9
10Lightning CLI relies on Heroku Toolbelt. Make sure you have the `heroku` command installed correctly before attempting to use this tool. More information about Heroku Toolbelt is available here:
11
12https://devcenter.heroku.com/articles/getting-started-with-nodejs#set-up
13
14After getting Heroku Toolbelt up and running, install the Lightning CLI plug-in using the following command:
15
16```bash
17heroku plugins:install salesforce-lightning-cli
18```
19
20Once installed, the plugin will be updated whenever you update the Heroku Toolbelt using the `heroku update` command. Do this every week or so to make sure you've got the latest Lightning CLI rules.
21
22
23## Usage
24
25Lightning CLI is run just like any other lint command line tool. The only trick is invoking it through the `heroku` command. Results are output to your shell window.
26
27### Normal Use
28
29You can run the Lightning CLI linter on any folder that contains Lightning components:
30
31```bash
32heroku lightning:lint ./path/to/lightning/components/
33```
34
35**Note:** The Lightning CLI runs only on local files. Download your component code to your machine using the [Metadata API](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/file_based.htm), or a tool such as the [Force.com IDE](https://developer.salesforce.com/page/Force.com_IDE), the [Force.com Migration Tool](https://developer.salesforce.com/page/Force.com_Migration_Tool), or any of a number of third-party options.
36
37### Filtering Files
38
39Sometimes you just want to scan a particular kind of file. The `--files` argument allows you to set a pattern to match files against.
40
41For example, the following command allows you to scan controllers only:
42
43```bash
44heroku lightning:lint ./path/to/lightning/components/ --files **/*Controller.js
45```
46
47### Include Warnings
48
49By default only errors will be output from the Lightning CLI. The `--verbose` argument will also output any warning message during the linting process.
50
51### Custom "House Style" Rules
52
53It's common that different organizations or projects will adopt different JavaScript rules. The Lightning CLI tool is here to help you get ready for LockerService, not enforce salesforce.com coding conventions. To that end, the Lightning CLI rules are divided into two sets, security rules and style rules. The security rules can't be modified, but you can modify or add to the style rules.
54
55Use the `--config` argument to provide a custom rules configuration file. A custom rules configuration file allows you to define your own code style rules, which affect the **style** rules used by the Lightning CLI tool.
56
57The Lightning CLI default style rules are defined in `lib/code-style-rules.js` inside this package. Make a copy of that file, and modify it to match your existing ESLint style rules. Alternatively, you can use your existing ESLint rule configuration file directly. For example:
58
59```bash
60heroku lightning:lint ./path/to/lightning/components/ --config ~/.eslintrc
61```
62
63**Note:** Not all ESLint rules can be added or modified using --config. Only rules that we consider benign or neutral in the context of Lightning Platform are activated by Lightning CLI. And again, you can't override the security rules.
64
65
66## Results
67
68When you run Lightning CLI on your Lightning components code, the tool outputs results for each file scanned.
69
70```bash
71error secure-document Invalid SecureDocument API
72Line:109:29
73 scrapping = document.innerHTML;
74 ^
75
76warning no-plusplus Unary operator '++' used
77Line:120:50
78 for (var i = (index+1); i < sibs.length; i++) {
79 ^
80
81error secure-window Invalid SecureWindow API
82Line:33:21
83 var req = new XMLHttpRequest();
84 ^
85
86error default-case Expected a default case
87Line:108:13
88 switch (e.keyCode) {
89 ^
90```
91
92Issues are displayed, one for each warning or error. Each issue includes the line number, severity, and a brief description of the issue. It also includes the rule name, which you can use to look up a more detailed description of the issue in the Lightning CLI documentation or ESLint documentation, as well as possible resolutions and options for further reading.
93
94Your mission is to review each issue, examine the code in question, and to revise it to eliminate all of the genuine problems.
95
96While no automated tool is perfect, we expect that most errors and warnings generated by Lightning CLI will point to genuine issues in your code, which you should plan to fix before using it with LockerService enabled.
97
98
99## Getting Help
100
101Lightning CLI also provides some built-in help, which you can access at any time with the following commands:
102
103```bash
104heroku lightning --help
105heroku lightning:lint --help
106```
107
108
109## License
110
111The [Salesforce Developer MSA](http://www.sfdcstatic.com/assets/pdf/misc/salesforce_Developer_MSA.pdf) governs your use of the Lightning CLI.