- Salesforce has created linting rules to minimize Lightning Web Components programming mistakes.
- Linting finds errors in your code while you’re editing, before you compile.
- It analyzes source code to flag programming errors, bugs, stylistic errors, and suspicious constructs.
- Take for instance, the following example:
const test = 'I am a test';
console.log(`Test: ${test}`);
const test = 'Another one.';
- We’re declaring the constant testtwice, which our javascript engine won’t be happy about.
- With the proper linter settings and watch configuration, instead of getting caught later as an error when the code runs, you’ll immediately get an error through your linter running in the background:
10:9 error Parsing error: Identifier 'test' has already been declared
8 | const test = 'I am a test';
9 | console.log(`Test: ${2}`);
> 10 | const test = 'Another one.';
| ^
- What all can linting help with?
- Flagging bugs in your code from syntax errors
- Giving you warnings when code may not be intuitive
- Providing suggestions for common best practices
- Keeping track of TODO’s and FIXME’s
- Keeping a consistent code style
- If you’re using a Salesforce DX project, you don’t have to set up linting manually.
- If you aren’t using a Salesforce DX project, install the ESLint rules from the command line.
Leave a comment