Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable usage of certain ES2015 features with ESLint 2?

Tags:

In ESLint 1, I can use the ecmaFeatures option to disable or enable certain language features. E.g.

ecmaFeatures:
  defaultParams:  false

Above config disables defaultParams.

This is very useful because in runtime like Node, not all features are available, and I don't want to use a transpiler.

But in ESLint 2, that was removed. You only got ecmaVersion, which doesn't alerting on usage of ES2015 features at all even if you give it a ecmaVersion of 5. I guess this make sense since the JavaScript interpreter will complain about the usage of unsupported syntax at interpretation time, but what about developing for browsers have different level of ES2015 support? Syntax that works for Chrome won't work for IE9.

Is there any way to lint the usage of language features, e.g. disable destructuring?

like image 657
Daiwei Avatar asked Apr 05 '16 20:04

Daiwei


People also ask

How do I disable a specific ESLint rule?

If you want to disable an ESLint rule in a file or on a specific line, you can add a comment. On a single line: const message = 'foo'; console. log(message); // eslint-disable-line no-console // eslint-disable-next-line no-console console.

How do I disable ESLint for few lines?

To temporarily turn off ESLint, you should add a block comment /* eslint-disable */ before the lines that you're interested in: /* eslint-disable */ console.

How do I ignore files in ESLint?

You can tell ESLint to ignore specific files and directories using ignorePatterns in your config files. ignorePatterns patterns follow the same rules as . eslintignore .


1 Answers

no-restricted-syntax rule disallows specific syntax. This "syntax" is meaning the types of AST nodes. The spec of AST is here: https://github.com/estree/estree

eslint-plugin-node's no-unsupported-features rule disallows unsupported ECMA features by specific Node's version. I don't know whether a similar rule for browsers exists or not.

like image 198
mysticatea Avatar answered Sep 28 '22 02:09

mysticatea