本文介绍了为当地发展创造不同的陪同规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个激励人的示例:我正在开发一些代码,想弄清楚出了什么问题,所以我有

Here's a motivating example: I am developing some code and want to figure out what's going wrong, so I have

function foo() {
    console.log("Look its 2016 and I'm still printf debugging");
}

除了...我们的构建过程将esLint作为构建系统的一部分运行,并且如果esLint失败,按设计可以防止甚至运行其余的构建管道。 error意外的控制台语句无控制台

Except... our build process runs esLint as part of the build system and by-design prevents even running the rest of the build pipeline if esLint fails. error Unexpected console statement no-console

我真正想要的是设置 dev 环境,其中某些规则已关闭(或转换为警告),然后在 production 环境中打开了严格的规则。而且我希望能够轻松地在本地进行切换,以便在将代码提交到CI服务器之前可以验证我的代码是否正常。

What I effectively want is to set up a dev environment where certain rules are turned off (or converted to warnings), and then a production environment with the strict rules turned on. And I want to be able to easily toggle that locally so I can verify my code works before submitting it to a CI server.

我找不到任何相关的代码段为了做到这一点,这让我很难过。我的构建环境只是 npm 脚本(仅使用esLint CLI + package.json),但是我很乐意从另一个构建环境中移植解决方案。

I can't find any relevant code snippets to make this happen, which makes me sad. My build environment is just npm scripts (just using the esLint CLI + package.json), but I would be happy to port a solution from another build environment.

现在,我剩下的是 // eslint-disable-line 或在本地修改 .eslintrc 文件,并祈祷我从未意外地将其签入。必须有更好的方法。

Right now, I'm left with either // eslint-disable-line or locally modifying an .eslintrc file and praying I never accidentally check that in by accident. There must be a better way.

推荐答案

从github上的相关线程中:

From a related thread on github: https://github.com/eslint/eslint/issues/6460#issuecomment-226967834

看来我要做的是制作一个 dev.eslintrc 或类似的东西,并扩展主要的 .eslintrc 。然后我可以根据需要使用命令行args在两个规则集之间切换。

It looks like what I am going to do is make a dev.eslintrc or similar and have that extend the main .eslintrc. And then I can use command line args to switch between the two rulesets as needed.

这篇关于为当地发展创造不同的陪同规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 21:08