JShint和下面这行代码有一点问题。
$location.path('map-' + map.id + '/venue-' + map.attributes.default_venue.value);
我得到了错误,Identifier 'default_venue' is not in camel case.
这通常不是问题,但我不能控制变量名-它是通过JSON API引入的。
对于受影响的变量或它们出现的行,我有没有办法抑制这个问题?
如果以前有人问过这个问题,我很抱歉,我很确定一定是这样,但我找不到解决方案。
发布于 2013-10-18 19:52:19
JSHint遵循函数级别的指令,因此您可以找到封闭的函数并向其添加camelcase
选项。下面是一个例子:
/*jshint camelcase: true */
var not_camel_case = 1; // Warns
function example() {
/*jshint camelcase: false */
var not_camel_case = 2; // Does not warn
}
发布于 2014-11-18 23:41:26
我将来自api的属性的名称放在一个单独的字符串中。例如:
var defaultVenueAttributeKey = 'default_venue';
$location.path('map-' + map.id + '/venue-' + map.attributes[defaultVenueAttributeKey].value);
它有点冗长,但您可以将来自您的API的所有属性名称组合在一起,这样可以更容易地响应API更改。
发布于 2017-06-18 15:26:37
被接受的答案/*jshint camelcase: true */
对我不起作用。我仍然得到了错误。
我看了看docs,发现这个解决方案对我很有效:
/*eslint camelcase: ["error", {properties: "never"}]*/
https://stackoverflow.com/questions/19448446
复制相似问题