可以修改ESLint提供的错误消息吗?

huangapple go评论129阅读模式
英文:

Is it possible to modify the error messages given by ESLint?

问题

在我的日常工作中,我们使用ESLint来确保每个人都在正确的方向上前进。我想知道是否可以利用linting错误/警告消息来引导用户查看我们内部的政策/处理linting问题的指南?

是否有一种方法可以修改ESLint的错误/警告消息以实现这一点?

我简单地研究了一下使用自定义规则,但我大部分需要的是针对现有规则,比如"no implicit any"。

英文:

In my day job we use ESLint to make sure everyone rows in the right direction. I'm wondering if we can leverage the linting error/warning messages to direct users to our internal policy/how to guides on addressing the linting issues presented?

Is there a way to modify ESLint error/warning messages to do this?

I took a quick look into using custom rules, but most of what I'm looking for is for existing rules like "no implicit any".

答案1

得分: 1

抱歉,无法支持自定义任何规则的错误消息。请参阅Issue 15821

nzakas的回应如下:

感谢您的建议。不幸的是,这实际上并不切实可行。没有一种集中实现这一点的方法,这意味着需要修改近300个规则,这不仅是我们的小团队能够承担的工作量,而且不值得去尝试的机会成本。

请记住,您始终可以创建自定义规则,以完全满足您的需求。

因此,要实现消息自定义,需要由各个规则自行实现,有一些规则已经做到了。请参阅这个关于 eslint-plugin-mocha 的回答

英文:

Unfortunately no. There appears to be no support for customizing the error message of any rule. See Issue 15821.

The response from nzakas was:

> Thanks for the suggestion. Unfortunately, this is just not practical. There is no way to centrally implement this, so it would mean modifying nearly 300 rules, and that is not only more work than our small team can commit to, but not worth the opportunity cost to attempt.
>
> Remember, you can always create custom rules that do exactly what you want.

So it's up to individual rules to implement message customization, which some have. (See this Answer about eslint-plugin-mocha).

huangapple
  • 本文由 发表于 2023年3月7日 04:52:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/75655735.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定