Multiple string interpolation Mostly robocop and hound give "line is too long" for such code statements. I just wanted to know which one is better and preferable way.

This one is a way to avoid making the message long so just do multiple string interpolation:

timeGet = "&lt;span class='message'&gt;after #{getTime2(online, offline)}&lt;/span&gt;"

logs[index].extra = {message: "Camera came online #{timeGet}"}


This next one is to not do multiple string interpolation but just expand the JSON object to the new line to avoid "line is too long". What do you think is a good and preferable way of coding?

logs[index].extra = {
  message: "Camera came online &lt;span class='message'&gt;after #{getTime2(online, offline)}&lt;/span&gt;"
}
For long strings in CoffeeScript consider using the heredocs notation:

logs[index].extra = {
  message: """
           Camera came online
           &lt;span class='message'&gt;
             after #{getTime2(online, offline)}
           &lt;/span&gt;
           """
}


or simply concatenate multiple lines:

logs[index].extra = {
  message: "Camera came online" +
           "&lt;span class='message'&gt;" +
           "  after #{getTime2(online, offline)}" +
           "&lt;/span&gt;"
}


The extra newlines and multiple spaces shouldn't matter in HTML since they're all trimmed to one space by the renderer (except defined otherwise, e.g. in pre or code).



It wasn't your question, but please also consider this syntax for defining an object and adding a field to it. I think it's better readable due to less indentation, it's more explicit and doesn't make anyone thing you'd add on top of an existing object:

logs[index].extra = {}
logs[index].extra.message = "Camera came online" +
                            "&lt;span class='message'&gt;" +
                            "  after #{getTime2(online, offline)}" +
                            "&lt;/span&gt;"


The code from this example is equivalent to the code above it.