此页面内容来自 JSHint 项目仓库。如果您发现错误,请 提交问题 或(更好的是)提交请求!
JSHint 报告器是一个 JavaScript 文件,它接收来自 JSHint 的原始数据,并将某些内容输出到控制台(或其他文件,或发送电子邮件;这完全取决于您)。
这是最简单的报告器,如果 JSHint 通过了文件则打印 OK
,否则打印 FAIL
module.exports = {
reporter: function (errors) {
console.log(errors.length ? "FAIL" : "OK");
}
};
每个报告器文件必须公开一个函数 reporter
,该函数接受一个错误数组。此数组的每个条目都具有以下结构
{
file: [string, filename]
error: {
id: [string, usually '(error)'],
code: [string, error/warning code],
reason: [string, error/warning message],
evidence: [string, a piece of code that generated this error]
line: [number]
character: [number]
scope: [string, message scope;
usually '(main)' unless the code was eval'ed]
[+ a few other legacy fields that you don't need to worry about.]
}
}
以及一个实际示例
[
{
file: 'demo.js',
error: {
id: '(error)',
code: 'W117',
reason: '\'module\' is not defined.'
evidence: 'module.exports = {',
line: 3,
character: 1,
scope: '(main)',
// [...]
}
},
// [...]
]
如果您仍然感到困惑,JSHint 仓库有一个 示例报告器。