Do not apply ES6+ specific rules in non ES6+ environements
See original GitHub issueI’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:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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 anecmaVersion: 6
option that changes parsing semantics, but this isn’t the case for all parsers.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 usingeslint: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.