简体   繁体   中英

ESlint: Highlighting ES6 code in an non-transpiled ES5 codebase

We currently have a problem with our build pipeline that prevents certain parts of our legacy codebase from being transpiled.

Subsequently parts of our codebase have to be written in ES5 in order to be backwards compatible with older browsers.

The problem we're having is enforcing the use of ES5 code within these legacy scripts. There are a lot of places in the code where ES6 features (let, const, destructuring, object shorthand) are already used.

Adding an eslint config with the ecmaVersion set to 5 is not ideal because of the way the parser throws an exception on reaching an es6 feature, subsequently meaning no additional linting of the file happens. So you need to resolve all es6 type exceptions before this becomes an option.

We are unable to undertake a grand refactor of the code like this at present. As some parts are still being actively worked on. It is, in a word, a sh*tshow.

My question is, short of building some custom eslint plugin that highlights es6 features, is there any other solution that I may have missed?

As per @VLAZ' suggestion

https://github.com/nkt/eslint-plugin-es5

using the following config in eslintrc:

{
  "plugins": [
    "es5"
  ]
}

Worked perfectly for what we needed it for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM