3

I have simple CoffeeScript code that is working well when integrated with jQuery. But coffee-lint code checking tool shows the following error

coffeelint file.coffee

Implicit braces are forbidden.

My code is

$ ->
  $("#selector").dialog
    modal: true

What might be causing this error?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Eric Chan
  • 1,192
  • 4
  • 16
  • 30

2 Answers2

4

This would be the minimal change you need. I recommend adding the () for the function call, but this rule doesn't care about those.

$ ->
  $("#selector").dialog {
    modal: true
  }

modal: true is implied to be an object. To demonstrate why this rule is good to have enabled, lets say you had some very similar code that accepts a parameter.

makeDialog = (foo) ->
  $("#selector").dialog
    modal: true,
    foo: foo,

This code looks fine, it even compiles correctly. But at some point you notice that foo: foo can be simplified.

makeDialog = (foo) ->
  $("#selector").dialog
    modal: true,
    foo,

Now your code is broken. CoffeeScript correctly guessed that modal: true is a property on an implied object that is the first parameter of dialog, but it doesn't know if foo is a 2nd property on that object or a 2nd parameter to the function. It ends up compiling out to this:

return $("#selector").dialog({ modal: true }, foo);
Asa Ayers
  • 4,854
  • 6
  • 40
  • 57
1

Do you have a coffeelint config file? If yes, check that no_implicit_braces policy has not been changed (defaults to ignore).

Cyril
  • 466
  • 5
  • 7
  • Thank you.But I don't want to change coffeelint.json. I want to keep default configuration and fix issue. – Eric Chan Aug 09 '16 at 16:54
  • Default configuration does not raise any error nor warning for implicit braces. This is why I was asking if you already had a coffeelint.json file, and if it is the case, check that the no_implicit_braces rule is not set to error. – Cyril Aug 10 '16 at 07:26