Newer Version Available
Validation During Development Using the Salesforce CLI
Salesforce DX includes a code analysis and validation tool usable via
the Salesforce CLI. Use force:lightning:lint to scan and
improve your code during development. Validation using the Salesforce CLI doesn’t just help you
avoid Lightning Locker conflicts and anti-patterns. It’s a terrific practice for improving your code
quality and consistency, and to uncover subtle bugs before you commit them to your
codebase.
Validations using the Salesforce CLI are done separately from saving your code to Salesforce. The
results are informational only. Validations performed by the Salesforce CLI fall into two
categories, failures and warnings. Error messages explain both, and are displayed in your shell
window. Here’s some example
output:
1error secure-document Invalid SecureDocument API
2 Line:109:29
3 scraping = document.innerHTML;
4 ^
5
6 warning no-plusplus Unary operator '++' used
7 Line:120:50
8 for (var i = (index+1); i < sibs.length; i++) {
9 ^
10
11 error secure-window Invalid SecureWindow API
12 Line:33:21
13 var req = new XMLHttpRequest();
14 ^
15
16 error default-case Expected a default case
17 Line:108:13
18 switch (e.keyCode) {
19 ^Validations performed using the Salesforce CLI are different from validations performed at save
time in the following important ways.
- The Salesforce CLI uses many more rules to analyze your component code. Save time validations prevent you from making the most fundamental mistakes only. Validation with the Salesforce CLI errs on the side of giving you more information.
- Validation via the Salesforce CLI ignores the API version of your components. Save time validations are performed only for components set to API 41.0 and later.