[英]Override error message on eslint-plugin-mocha rule
I'm using eslint-plugin-mocha
to put some rules on writing tests with mocha and here is what my .eslintrc.js
file looks like我正在使用
eslint-plugin-mocha
为使用 mocha 编写测试制定一些规则,这是我的.eslintrc.js
文件的样子
module.exports = {
root: true,
parserOptions: {
sourceType: 'module'
},
plugins: ['mocha'],
extends: 'plugin:mocha/recommended',
rules: {
'mocha/valid-test-description': ['error', /^should/]
},
env: {
'mocha': true
}
}
This rule finds any test description that doesn't start with should
.此规则查找任何不以
should
开头的测试描述。 The error message looks like that错误消息看起来像这样
error Invalid "it()" description found mocha/valid-test-description
I'd like the change this error message to be more descriptive but the rule doesn't offer options to change this message.我希望将此错误消息更改为更具描述性,但规则不提供更改此消息的选项。 Do you know how with eslint to configure this ?
你知道如何用 eslint 来配置这个吗?
I've made a PR and this feature is available since version 6.1.0 of eslint-plugin-mocha
.我已经做了一个PR ,这个功能从
eslint-plugin-mocha
6.1.0版开始可用。
Here is how to define the error message:以下是定义错误消息的方法:
rules: {
'mocha/valid-test-description': ['error', { pattern: /^should/, message: 'Should start with "should"' }]
}
// OR
rules: {
'mocha/valid-test-description': ['error', /^should/, ['it', 'specify', 'test'], 'Should start with "should"']
}
The documentation is available here .该文档可在此处获得。
Now the error message is:现在错误信息是:
error Should start with "should" mocha/valid-test-description
Note: the same feature is available for the valid-suite-description
rule.注意:相同的功能可用于
valid-suite-description
规则。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.