简体   繁体   English

ESlint:在未转译的 ES5 代码库中突出显示 ES6 代码

[英]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.随后我们的部分代码库必须用 ES5 编写,以便向后兼容旧版浏览器。

The problem we're having is enforcing the use of ES5 code within these legacy scripts.我们遇到的问题是在这些遗留脚本中强制使用 ES5 代码。 There are a lot of places in the code where ES6 features (let, const, destructuring, object shorthand) are already used.代码中有很多地方已经使用了 ES6 特性(let、const、解构、object 简写)。

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.添加 ecmaVersion 设置为 5 的 eslint 配置并不理想,因为解析器在达到 es6 功能时抛出异常的方式,随后意味着不会发生额外的文件 linting。 So you need to resolve all es6 type exceptions before this becomes an option.因此,您需要先解决所有 es6 类型的异常,然后再将其变为一个选项。

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.简而言之,它是一个 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?我的问题是,除了构建一些突出 es6 功能的自定义 eslint 插件之外,还有其他我可能错过的解决方案吗?

As per @VLAZ' suggestion根据@VLAZ 的建议

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

using the following config in eslintrc:在 eslintrc 中使用以下配置:

{
  "plugins": [
    "es5"
  ]
}

Worked perfectly for what we needed it for.完美地满足了我们的需要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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