gpt4 book ai didi

javascript - 我可以在函数级别设置 jshint 选项吗?

转载 作者:行者123 更新时间:2023-11-30 05:51:02 25 4
gpt4 key购买 nike

我正在使用 jshint 来监控我的代码质量,但我想对代码的不同部分应用不同的规则/选项。

特别是,有一个函数我有意且必须使用按位运算符。对于这个函数,我想设置 /*jshint bitwise:false */。不过,对于我的其余代码,我想设置 /*jshint bitwise:true */。有没有办法做到这一点,而不是将该功能拆分到另一个脚本文件中?我想象它看起来像这样,但看起来这实际上不起作用。

/*jshint bitwise:true */  //not really needed since it's default

function whatever () {
// lots of code here
}

function uses_bitwise () {
/*jshint bitwise:false */
//bitwise code here
}

最佳答案

是的,您在问题中的语法是正确的。来自 The JSHint documentation :

In addition to the --config flag and .jshintrc file you can configure JSHint from within your files using special comments. These comments start either with jshint or global and are followed by a comma-separated list of value. For example, the following snippet will enable warnings about undefined and unused variables and tell JSHint about a global variable named MY_GLOBAL.

/* jshint undef: true, unused: true */
/* global MY_GLOBAL */

You can use both multi- and single-line comments to configure JSHint. These comments are function scoped meaning that if you put them inside a function they will affect only this function’s code.

关于javascript - 我可以在函数级别设置 jshint 选项吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14855565/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com