对不起,我想在发布答案之前尝试一下,但赏金的差不多了。 ; ^)
This answer声称有一种方法可以编写自己的JSHint模块。
让我们假设它像宣传的那样,并已重新合并。
Great instructions here,但要注意,这些都对“jshint-未来”的网站。从该页面
示例代码:
// This module errs on any identifier that doesn't starts with 'kitty'.
function myModule(linter) {
linter.on("Identifier", function (ident) {
if (ident.name && ident.name.slice(0, 5) !== "kitty")
linter.report.addError("C001", "More cats please.");
});
}
下面是关于如何建立一个棉短绒初始部分:
var Linter = require("jshint").Linter;
var code = "<your beautiful JavaScript code here>";
// Create a new instance of Linter.
var linter = new Linter(code);
// Now you can teach JSHint about your predefined variables.
// Note that default JavaScript identifiers are already there.
linter.addGlobals({
jQuery: false,
MyPlugin: true
});
// If you have any JSHint extensions, you can attach them
// to the current instance.
linter.addModule(myModule);
// Finally, parse your code.
linter.parse();
我知道这是非常通用的(你仍然需要研究linter.on
选项超出Identifier
;也有String
,例如),但它看起来很有前途。再次,您可以看到如何使用说明above进行集成。看起来这是used in style.js
的格式。我有不是试过这个呢。只是没有时间在家;道歉。
是否有特定的原因torazaburo的“只需grep
它”的答案不起作用?您是否需要将其作为代码质量工作流程的一部分?如果是这样,这个“写你自己的模块”似乎是要走的路。
如果你喜欢它,也有非常明显的方法来破解JSLint,但我不确定克罗克福德会赞赏。 ; ^)
不,jshint不能这样做。只要在寻找'@ author'的源代码上做一个grep。如果你想要,你可以把它放在一个git pre-commit hook中。或者,如果遇到'@ author',创建文档时可能会导致JSDoc错误。 – 2014-12-03 16:54:20
@torazaburo感谢您的有用评论,它实际上可以是一个合法的答案。 – alecxe 2014-12-03 17:08:29