How to fix error as implicit braces are forbidden by coffee-lint checking tool? - coffeescript

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?

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);

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

Related

Why are the javafx Input checks not working in scala

How to perform input checks in TextInputDialog in JavaFX?
The above link basically covers the answer to my question but it doesn't work for me in scala. I have a TextField (eTextField) and I want to check that it contains either a R or D. If it does than the button (ePR_ePD) should be enabled. Here is the part of my code that should do it, but it doesn't enable the button:
val isInvalid: BooleanBinding = Bindings.createBooleanBinding(() => !isValid(eTextField.getText, eTextField.textProperty))
println(isInvalid)
ePR_ePD.disableProperty().bind(isInvalid)
def isValid (eText: String, eTextProp: StringProperty): Boolean = {
println(eText.contains("R")||eText.contains("D"))
eText.contains("R")||eText.contains("D")
}
When the eTextField contains a R or D my output is:
BooleanBinding [invalid]
true
and when it does not contain either my output is:
BooleanBinding [invalid]
false
But in both cases the ePR_ePD button says disabled. It appears it is something to do with the BooleanBinding, since it is always invalid.
Also not sure why isValid(eTextField.getText, eTextField.textProperty) needs to have the textProperty parameter, but that is what the answer in the link showed. Also tried "var isInvalid..." but that didn't help.
According to the documentation and as noted in the comments, createBooleanBinding takes two arguments, the function and the observable.
The function just tests the property value so isValid does not need the second argument. (The clue is that the second argument is not actually used)
def isValid (eText: String): Boolean =
eText.contains("R")|| eText.contains("D")
The property itself is passed as a second parameter to createBooleanBinding rather than to isValid:
createBooleanBinding(() => !isValid(eTextField.getText), eTextField.textProperty)
This works, after I fixed the problem that I forgot to enter the fx:id in SceneBuilder for the ePR_ePD button:
(In the initialize() method of the fxml controller:)
val isInvalid: BooleanBinding = Bindings.createBooleanBinding( () => !(isValid(eTextField.getText)), eTextField.textProperty)
ePR_ePD.disableProperty().bind(isInvalid)
}
(Outside the initialize() method:)
def isValid (eText: String): Boolean = {
println(eText.contains("R")||eText.contains("D"))
eText.contains("R")||eText.contains("D")
}
The only odd thing is that it appears to call isValid twice when I use another method to automatically change the contents of the eTextField. My output is false false when there is no R or D in the field and true true when either is present.
This also works, without an isValid method:
(In the initialize() method of the fxml controller:)
val isInvalid: BooleanBinding = Bindings.createBooleanBinding(
() => !(eTextField.getText.contains("R")||eTextField.getText.contains("D")), eTextField.textProperty
)
ePR_ePD.disableProperty().bind(isInvalid)
Thanks to everyone for your help!

FilterOperator bug in using quotes, same code different behavior across systems/time

this.getView().getModel().read("/QualificationProficiencySet", {
filters: [new sap.ui.model.Filter({
path: "Qobjid",
operator: sap.ui.model.FilterOperator.EQ,
value1: nQObjid
})],
success: function(data) {
that._profData = data.results;
that._oQuickView.setModel(new sap.ui.model.json.JSONModel(that._profData), "proficiencyModel");
// delay because addDependent will do a async rerendering and the actionSheet will immediately close without it.
jQuery.sap.delayedCall(200, that, function() {
that._oQuickView.openBy(oLink);
});
},
error: function(evt) {}
});
nQObjidis of type string - always.
Yesterday on our development system I saw the error
"Invalid parametertype used at function 'eq' (Position: 8)"
I noticed that the filter was appended in the URL without single quotes around the value of nQObjid. Strange because at the moment it's added as the value of the filter operator it's clearly a string. I couldn't find any related issues, but I put a (dirty) workaround in place by doing value1: "'"+nQObjid+"'".
This worked, until today, same system, didn't change the code, but suddenly the quotes are part of the value inside the gateway. So I remove the "'"again and tested, works. Then I transport the solution to production to find out that I now have the same problem on production with "Invalid parametertype used at function 'eq'.. Another user on production does not have this issue, so I'm a bit lost.
Similar issue: new SAPUI5 updat to 1.42 has odata bug "Invalid Parameters...
This may not solve your problem but it's too long for a comment, that's why I am posting it here:
When doing a read request, the framework is making a call to a helper class: V2 ODataModel.js Line #4231
aUrlParams = ODataUtils._createUrlParamsArray(mUrlParams);
The helper class then calls a private method: ODataUtils.js Line #72
return "$filter=" + this._createFilterParams(aFilters, oMetadata, oEntityType);
This private method is doing a bunch of stuff, most importantly calling another private method which is actually building the strings ODataUtils.js Line #128
sFilterParam = that._createFilterSegment(oFilter.sPath, oMetadata, oEntityType, oFilterSegment.operator, oFilterSegment.value1, oFilterSegment.value2, sFilterParam);
One of the first thing this method does is formatting your value, and I guess here is where your problem occurs: ODataUtils.js Line #393
oValue1 = this.formatValue(oValue1, sType);
The formatValue function takes your value and its Edm.Type and depending on that type does different stuff. If your objectId is a string, then it should put single quotes at the beginning and the end: ODataUtils.js Line #468
sValue = "'" + String(vValue).replace(/'/g, "''") + "'";
If the type is undefined or some weird value that UI5 doesn't know, then your value is simply cast to a String (which is probably what happens in your case).
Why is the type undefined or weird? That's where you come in... you have to do a little debugging to find out what the actual values are. If the UI5 code is unreadable you can put sap-ui-debug=true as an URL parameter:
my.sap.system.com:8000/sap/bc/ui5_ui5/sap/ztest/index.html?sap-ui-debug=true
If it's a timing issue (metadata has not been loaded for whatever reasons) then wrapping your code in a Promise might help:
var oModel = this.getView().getModel();
oModel.metadataLoaded().then(function() {
oModel.read("/QualificationProficiencySet", {
// ...
});
}

Correct way to return function value instead of binding in Coffeescript

I can't seem to find a concise answer to this question. What is the correct coffeescriptic way to return the value from _otherInstanceMethod when calling #_instanceMethod instead of the function binding itself?
x = _instanceMethod: () ->
#_otherInstanceMethod key: 'value'
Edit (thanks commenters)
This returns:
x = function () {
[...] # function body omitted
});
Instead of
x = 'some value returned by _otherInstanceMethod'
I would like the value to be returned instead of the function binding to _otherInstanceMethod
Being totally new to Coffeescript, this was my fault. I was calling the instance method like:
#_instanceMethod
instead of
#_instanceMethod()
Sorry for the trouble, voting to delete
In CoffeeScript #something translated into this.something regardless of the underlying variable type. This means you can use # only in conjuction with properties, with methods you still ought to use good old this.

Coffeescript and markup based JS execution

From another thread here I found this great tutorial on markup based JS execution
Garber-Irish solution:
http://www.viget.com/inspire/extending-paul-irishs-comprehensive-dom-ready-execution/.
I'm checking out how I can do parts of this in Coffeescript.
This works OK:
SITENAME.surveys.show = ->
alert "Hello CoffeeScript"
Which renders out:
SITENAME.surveys.show = function() {
return alert("Hello CoffeeScript");
};
This one is not so happy:
SITENAME.surveys.new = ->
alert "Hello CoffeeScript"
SITENAME.surveys["new"] = function() {
return alert("Hello CoffeeScript");
};
I'm new to Coffeescript and doing a codeschool.com course on it now.
I guess the "new" keyword is special for coffeescript.
Is there any workaround for this?
Thanks!
new is special in JavaScript and CoffeeScript is aware of this so it's emitting code that will actually work even though it's bad practice to name methods using reserved keywords.
If you need to use new, you can use [] to define the function:
SITENAME.surveys['new'] = ->
alert "Hello CoffeeScript"
and to call it:
SITENAME.surveys['new']()
Demo: http://jsfiddle.net/ambiguous/Y3qnt/
A quick review of your link suggests that you'll be accessing the function with something like:
controller = 'surveys'
action = 'new'
SITENAME[controller][action]()
So it doesn't matter what the methods are called as you'll always be referring to them by their (string) name anyway.

; expected but <place your favourite keyword here> found

I'm trying to write a class for a scala project and I get this error in multiple places with keywords such as class, def, while.
It happens in places like this:
var continue = true
while (continue) {
[..]
}
And I'm sure the error is not there since when I isolate that code in another class it doesn't give me any error.
Could you please give me a rule of thumb for such errors? Where should I find them? are there some common syntactic errors elsewhere when this happens?
It sounds like you're using reserved keywords as variable names. "Continue", for instance, is a Java keyword.
You probably don't have parentheses or braces matched somewhere, and the compiler can't tell until it hits a structure that looks like the one you showed.
The other possibility is that Scala sometimes has trouble distinguishing between the end of a statement with a new one on the next line, and a multi-line statement. In that case, just drop the ; at the end of the first line and see if the compiler's happy. (This doesn't seem like it fits your case, as Scala should be able to tell that nothing should come after true, and that you're done assigning a variable.)
Can you let us know what this code is inside? Scala expects "expressions" i.e. things that resolve to a particular value/type. In the case of "var continue = true", this does not evaluate to a value, so it cannot be at the end of an expression (i.e. inside an if-expression or match-expression or function block).
i.e.
def foo() = {
var continue = true
while (continue) {
[..]
}
}
This is a problem, as the function block is an expression and needs to have an (ignored?) return value, i.e.
def foo() = {
var continue = true
while (continue) {
[..]
}
()
}
() => a value representing the "Unit" type.
I get this error when I forget to put an = sign after a function definition:
def function(val: String):Boolean {
// Some stuff
}