question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Comments in between if, else-if and else blocks produces syntax error

See original GitHub issue

It seems when there are in-line comments between if blocks the else or else-if line is drug up into the comments line resulting in a syntax error. This was produced by running prettier no additional options.

//
// checks the parent element for time range values or date values
function to_and_from_timestamps(parent) {
    var from_ts = '';
    var to_ts = '';
    var time_values = get_all_form_values(parent);
    //
    // getting time range data
    if (time_values.hasOwnProperty('time_range')) {
        from_ts = time_values['time_range'].split('|')[0] + ' 00:00:00';
        to_ts = time_values['time_range'].split('|')[1] + ' 23:59:59';
    }
    // using calendar inputs instead
    else {
        from_ts = '{st-year}-{st-month}-{st-day} 00:00:00'.format(time_values);
        to_ts = '{en-year}-{en-month}-{en-day} 23:59:59'.format(time_values);
    }
    //
    return { from_ts: from_ts, to_ts: to_ts };
}

becomes…

//
// checks the parent element for time range values or date values
function to_and_from_timestamps(parent) {
  var from_ts = "";
  var to_ts = "";
  var time_values = get_all_form_values(parent);
  //
  // getting time range data
  if (time_values.hasOwnProperty("time_range")) {
    from_ts = time_values["time_range"].split("|")[0] + " 00:00:00";
    to_ts = time_values["time_range"].split("|")[1] + " 23:59:59";
  }
  // using calendar inputs instead else {
    from_ts = "{st-year}-{st-month}-{st-day} 00:00:00".format(time_values);
    to_ts = "{en-year}-{en-month}-{en-day} 23:59:59".format(time_values);
  }
  //
  return { from_ts: from_ts, to_ts: to_ts };
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:6
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
jlongstercommented, Jan 16, 2017

Thanks. Comments are going to be re-hauled this week and should be a lot more stable.

0reactions
jlongstercommented, Jan 26, 2017

See #487 as a follow-up, it no longer produces invalid code but we need to fix the formatting

Read more comments on GitHub >

github_iconTop Results From Across the Web

if / else errors - learn how to fix these - Codecademy
Typically the following error messages are caused by faulty if/else syntax ------ - *"syntax error"* - *"missing operand; found else"* - *"Unexpected token ......
Read more >
else if statement in java returning syntax error - Stack Overflow
Following that, there are two lines of code which execute without problem and then an else is discovered and it causes the error....
Read more >
Else-If in Python – Python If Statement Example Syntax
In the if-else statement, we have two branches incase the statement is true or false. The if block is executed in case the...
Read more >
Control flow and error handling - JavaScript - MDN Web Docs
In general, it's good practice to always use block statements—especially when nesting if statements: if (condition) { // Statements for when ...
Read more >
Python Keywords: An Introduction
Python keywords make up the fundamental building blocks of any Python program. In this tutorial, you'll learn the basic syntax and usage for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found