7

When using the sfdx CLI tool, there is documentation on how to use the sfdx force:lightning:lint command here: https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_force_lightning.htm#cli_reference_lint

However, when writing ES6 compliant code like:

const foo = "bar";

Running the linter returns:

error Parsing error: The keyword 'const' is reserved

I attempted using inline environments like so:

const foo = "bar"; // eslint-env es6

I have also tried using parserOptions within the custom .eslintrc file:

{
  "parserOptions": {
    "ecmaVersion": 6
  }
}

But it doesn't seem to respect any changes I try to make to the parserOptions for eslint. Is there any way to override the parserOptions on the javascript linter?

3 Answers 3

7

There is an Aura GitHub repo issue ESLint integration breaking ES6 compatible code where it states...

The Winter '18 patch that went out this week made all ES6 syntax valid to the linter.

While this applies directly to Validation When You Save Code Changes with the Developer Console and not Validation During Development Using the Salesforce CLI, it does confirm ES6 is now supported for Lightning development.

You can provide Custom “House Style” Rules using the --config CONFIG option for sfdx force:lightning:lint, but according to the CLI reference:

Only code style rules are used, while the rest are ignored.

So, attempting to specify ESLint parser options, parserOptions, in a .eslintrc.* file (https://eslint.org/docs/user-guide/configuring#specifying-parser-options), will not work.

3

I don't think it's possible to override es-lint rules used by Lightning Linter and you don't need to do this.

Even that the modern browsers support ES6 syntax natively, but the Lightning Framework supports only ES2015 Strict Mode + Promises. It doesn't support ES6 syntax yet as some old version of google-closure compiler is used to minimize the code, when "Debug" mode is disabled.

By default, the Lightning Component framework runs in production mode. This mode is optimized for performance. It uses the Google Closure Compiler to optimize and minimize the size of the JavaScript code. The method names and code are heavily obfuscated.

Enable Debug Mode for Lightning Components

There is quite old question here Use of ES6 Default Function Parameter Value Spec in Lightning Components and the related issue in Aura GitHub repo https://github.com/forcedotcom/aura/issues/50 but nobody from Salesforce confirmed when ES6 will be supported by Lightning Framework

1

If you are in a pinch you can change the SFDX CLI lightning linter EMCA version in this file:

C:\Program Files\Salesforce CLI\client\node_modules\salesforce-lightning-cli\lib\aura-component-config.js

As @Steals mentioned, ES6 is not officially supported (except Promises). Enabling debug mode masks the lack of support. Once debug mode is disabled ES6 JS might start causing problems that it didn't cause when debug mode was enabled.

It is a bit of a grey area though.

ES6 is not officially supported in Lightning Components. This is particularly important if your users are still on IE11. But there is some advice available as to how and which features to use today. The Lightning Product team is looking at how to move to full ES6 support in Lightning development in the future.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.