unreturned expressions

Posted on
  • Hello,

    First, thank you for your amazing work. I love what you're doing, and the obvious emphasis on quality/elegance in all of the Espruino variants. I participated in the Pico Kickstarter, and have been intending to get more time in on my device ever since. I've gotten hung up several times on a simple issue that keeps stopping me from fully utilizing this awesome tool to its full potential...

    I use a particular shorthand in much of my code, that I'm just accustomed to and makes is quicker for me to write/maintain my apps. It is valid js, and works in every environment I work in -- though it trips up the Espruino compiler. Here's a simple example:

    var  on = false,
        run = 0;
    setInterval(function() {
      on = !on;
      run && LED1.write(on);  // Here is the key item.
    }, 500);
    

    I often rely on terse chains of logic like this to provide functionality for conditional checks. In our IDE, the following error is shown: "Expected an assignment or function call and instead saw an expression". Prepending the line as a return statement, or assigning the left-hand result to some other input resolves the issue, but is would be much preferred to allow this value to be passed to a null handler as it is in most other environments. Is this possible?

    I realize that there may be special considerations for Espruino's unique attributes, that could make this difficult or impossible to implement. It would make a huge difference to me to be able to code in my typical style however. I also know that many would consider this to be a minor point, but this streamlined approach is perfectly valid EcmaScript, and I would like to leverage my existing code that uses this construct.

    Thank you!

  • Thanks!

    Does the code not actually execute for you then? I just tried it on a recent Espruino build and it seems to work fine.

    Or is the issue that the Web IDE puts the red mark next to the line? Because even though it is saying that, it should upload and work just fine.

    I'd rather not totally remove the check because it probably helps detect a bunch of actual coding errors, but I guess there should really be a way to disable linting because a few people have complained about the linter objecting to other valid (but not normal) JS code.

  • You are right: It does compile! Thanks, and now I feel stupid for not verifying this myself first... Much appreciated :-)

  • +1 for an option to disable linting or having a dialog like "Linter detected code issues, but if you're sure the code is correct, upload anyway?". I was in the same situation as jtrick just recently.

  • Linter detected code issues, but if you're sure the code is correct, upload anyway?

    It should upload regardless unless the number of brackets doesn't match - it's just whether you can put up with having your code covered in red marks or not :)

    If there's code that doesn't upload, please let me know what it is as it might be something in the IDE that needs fixing.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

unreturned expressions

Posted by Avatar for jtrick @jtrick

Actions