由于 coffee-lint 检查工具禁止隐式大括号,如何修复错误?
How to fix error as implicit braces are forbidden by coffee-lint checking tool?
我有简单的 CoffeeScript 代码,在与 jQuery 集成时运行良好。
但是 coffee-lint
代码检查工具显示以下错误
coffeelint file.coffee
Implicit braces are forbidden.
我的密码是
$ ->
$("#selector").dialog
modal: true
可能导致此错误的原因是什么?
你有一个coffeelint config file? If yes, check that no_implicit_braces policy没有改过(默认忽略)。
这将是您需要的最小更改。我建议为函数调用添加 ()
,但此规则不关心这些。
$ ->
$("#selector").dialog {
modal: true
}
modal: true
暗示是一个对象。为了说明启用此规则的好处,假设您有一些非常相似的代码接受参数。
makeDialog = (foo) ->
$("#selector").dialog
modal: true,
foo: foo,
这段代码看起来不错,甚至可以正确编译。但在某些时候,您会注意到 foo: foo
可以简化。
makeDialog = (foo) ->
$("#selector").dialog
modal: true,
foo,
现在您的代码已损坏。 CoffeeScript 正确地猜测 modal: true
是隐含对象上的 属性,它是 dialog
的第一个参数,但它不知道 foo
是否是第二个 [=28] =] 在该对象上或函数的第二个参数。它最终编译成这样:
return $("#selector").dialog({ modal: true }, foo);
我有简单的 CoffeeScript 代码,在与 jQuery 集成时运行良好。
但是 coffee-lint
代码检查工具显示以下错误
coffeelint file.coffee
Implicit braces are forbidden.
我的密码是
$ ->
$("#selector").dialog
modal: true
可能导致此错误的原因是什么?
你有一个coffeelint config file? If yes, check that no_implicit_braces policy没有改过(默认忽略)。
这将是您需要的最小更改。我建议为函数调用添加 ()
,但此规则不关心这些。
$ ->
$("#selector").dialog {
modal: true
}
modal: true
暗示是一个对象。为了说明启用此规则的好处,假设您有一些非常相似的代码接受参数。
makeDialog = (foo) ->
$("#selector").dialog
modal: true,
foo: foo,
这段代码看起来不错,甚至可以正确编译。但在某些时候,您会注意到 foo: foo
可以简化。
makeDialog = (foo) ->
$("#selector").dialog
modal: true,
foo,
现在您的代码已损坏。 CoffeeScript 正确地猜测 modal: true
是隐含对象上的 属性,它是 dialog
的第一个参数,但它不知道 foo
是否是第二个 [=28] =] 在该对象上或函数的第二个参数。它最终编译成这样:
return $("#selector").dialog({ modal: true }, foo);