覆盖eslint-plugin-mocha规则上的错误消息 [英] Override error message on eslint-plugin-mocha rule

查看:108
本文介绍了覆盖eslint-plugin-mocha规则上的错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 eslint-plugin-mocha 为使用Mocha编写测试制定一些规则,这是我的 .eslintrc.js 文件的外观

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

module.exports = {
  root: true,
  parserOptions: {
    sourceType: 'module'
  },
  plugins: ['mocha'],
  extends: 'plugin:mocha/recommended',
  rules: {
    'mocha/valid-test-description': ['error', /^should/]
  },
  env: {
    'mocha': true
  }
}

此规则可找到所有以 should 开头的测试描述.错误消息看起来像这样

This rule finds any test description that doesn't start with should. The error message looks like that

error  Invalid "it()" description found  mocha/valid-test-description

我希望此错误消息的更改更具描述性,但规则不提供更改此消息的选项.您知道如何用eslint进行配置吗?

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 ?

推荐答案

我制作了 6.1.0 ( eslint-plugin-mocha ).

I've made a PR and this feature is available since version 6.1.0 of eslint-plugin-mocha.

以下是定义错误消息的方法:

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"']
}

该文档可用这里.

现在错误消息是:

error  Should start with "should"  mocha/valid-test-description

注意: 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆