question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Do not apply ES6+ specific rules in non ES6+ environements

See original GitHub issue

I’m experimenting with eslint:all, and found that when relying on "ecmaVersion": 5 the ES6+ rules still get in, and force me to produce not syntactically correct output.

e.g. prefer-arrow-callback forces to use arrow functions, which cannot work in ES5.

It’ll be cleaner if rules dedicated for ES6+ syntax are simply not applied on files linted with "ecmaVersion": 5 option (and below). For now workaround is to manually disable rules that force ES6 syntax.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
platinumazurecommented, Apr 6, 2017

Additionally, it’s worth noting that eslint:all is very much a “use at your own risk” feature. It won’t work for everybody, and I would expect that people would need to do some per-rule configuration overrides when the default settings don’t or can’t work.

In your case, I would expect you would need to disable all of the ES6 rules for your codebase.

1reaction
not-an-aardvarkcommented, Apr 7, 2017

It might be good to have that cleaned out. I was personally puzzled that ECMAScript version can be set in two different parts of configuration (env and parserOptions). Now you’re saying that there are cases when both are ignored.

The parserOptions config object is just a set of options that get passed to the parser. Parsers can do whatever they want with these options, including ignoring them. The default parser happens to have an ecmaVersion: 6 option that changes parsing semantics, but this isn’t the case for all parsers.

It’ll be way nicer if there’s one straightforward way to set this up, and if some eslint plugin doesn’t respect that, then it should be seen as a bug in a plugin (btw not everyone uses babel).

I agree that it’s important to make eslint easy to configure, but I don’t think limiting the functionality of parsers in the manner you’re suggesting is a good way to do this. One of the design goals of eslint is that everything is pluggable, and naturally, not all parsers will have the same configuration options as the default parser. Rules are generally intended to be runnable regardless of what parser produced their AST, so it wouldn’t make sense to couple the general logic for enabling rules with parser-specific syntax options.

It’s important to note that this is only a problem when using eslint:all. There is a reason all rules are off by default – among other things, not all rules are applicable to all projects. If you’re using eslint:all to get familiar with eslint’s capabilities, then that’s fine (and I’m glad it’s working well for that purpose), but it’s not what eslint’s configuration system is designed and optimized for.

Read more comments on GitHub >

github_iconTop Results From Across the Web

env.es6=false does not disable es6-specific rules · Issue #3686
Environments do not control which rules are on or off. If you are getting Use let or const instead error, you should disable...
Read more >
javascript - Using non ES6 Code in ES6 Module environment
I'm trying to get the MarkerClustererPlus running in a ES6 Module environment and I don't know how to ...
Read more >
ES6 In Depth: Modules - the Web developer blog
ES6 modules are automatically strict-mode code, even if you don't write "use strict"; in them. You can use import and export in modules....
Read more >
16. Modules - Exploring JS
As explained in more detail later, the structure of ES6 modules is static, you can't conditionally import or export things. That brings a...
Read more >
Language Options - ESLint - Pluggable JavaScript Linter
ESLint lets you configure language options specific to the JavaScript used in your project, like custom global variables. You can also use plugins...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found