• JSLint: "Wrap a ternary expression in parens, ..."

    From emf@21:1/5 to All on Thu Jul 14 16:44:18 2022
    Hi.

    JSLint now does not like this code (that it used to find OK), saying

    "Wrap a ternary expression in parens, with a line break after
    the left paren."

    =================
    orb = (orb0Btn.checked)
    ? 0
    : (orb5Btn.checked)
    ? 5
    : (orb10Btn.checked)
    ? 10
    : (orb15Btn.checked)
    ? 15
    : 20;
    =================

    What is now the correct syntax for the ternary expression?

    Thanks,

    Eustace
    --
    Natal Transits Calculator
    https://emf.neocities.org/nt/nataltransits2.html

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Ram@21:1/5 to emf on Fri Jul 15 06:27:13 2022
    emf <emfril@gmail.com> writes:
    What is now the correct syntax for the ternary expression?

    IIRC, JSLint does not check syntax but its authors idea of style.

    The syntax for the conditional expression is

    ConditionalExpression[In, Yield, Await] :
    ShortCircuitExpression[?In, ?Yield, ?Await]
    ShortCircuitExpression[?In, ?Yield, ?Await] ? AssignmentExpression[+In, ?Yield, ?Await] :
    AssignmentExpression[?In, ?Yield, ?Await]

    , so, you can just write, for example, "0?1:1?2:3"
    (which would evaluate to 2).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Michael Haufe (TNO)@21:1/5 to emf on Fri Jul 15 08:40:11 2022
    On Thursday, July 14, 2022 at 3:44:28 PM UTC-5, emf wrote:
    Hi.

    JSLint now does not like this code (that it used to find OK), saying

    "Wrap a ternary expression in parens, with a line break after
    the left paren."

    =================
    orb = (orb0Btn.checked)
    ? 0
    : (orb5Btn.checked)
    ? 5
    : (orb10Btn.checked)
    ? 10
    : (orb15Btn.checked)
    ? 15
    : 20;
    =================

    What is now the correct syntax for the ternary expression?

    It's just a jslint setting. You can turn that off I'm pretty sure.

    I think it wants:

    (
    p ? truePart : (
    p ? truePart : falsePart
    )
    )


    I think this is because nested ternaries can be a little hard to read if you don't format them properly.

    I prefer ESLint

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From emf@21:1/5 to Stefan Ram on Fri Jul 15 14:19:16 2022
    On 2022-07-15 02:27, Stefan Ram wrote:
    emf <emfril@gmail.com> writes:
    What is now the correct syntax for the ternary expression?

    IIRC, JSLint does not check syntax but its authors idea of style.

    The syntax for the conditional expression is

    ConditionalExpression[In, Yield, Await] :
    ShortCircuitExpression[?In, ?Yield, ?Await]
    ShortCircuitExpression[?In, ?Yield, ?Await] ? AssignmentExpression[+In, ?Yield, ?Await] :
    AssignmentExpression[?In, ?Yield, ?Await]

    , so, you can just write, for example, "0?1:1?2:3"
    (which would evaluate to 2).

    Brilliant! :)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Ram@21:1/5 to emf on Fri Jul 15 18:41:12 2022
    emf <emfril@gmail.com> writes:
    orb = ((orb0Btn.checked)
    ? 0
    : (orb5Btn.checked)
    ? 5
    : (orb10Btn.checked)
    ? 10
    : (orb15Btn.checked)
    ? 15
    : 20);

    I'd ignore whatever JSLint says about this and
    use the following formatting:

    orb =
    orb0Btn.checked? 0:
    orb5Btn.checked? 5:
    orb10Btn.checked? 10:
    orb15Btn.checked? 15:
    20;

    . This is so much clearer and easier to read.
    No need to harp on the fact that it's formally
    a nested structure.

    1 + 2 + 3 + 4 + 5

    also actually is nested:

    ((( 1 + 2 )
    + 3 )
    + 4 )
    + 5

    because it is being parsed left-associatively.
    Still we do not add parentheses and indentations
    to make it look that complicated and difficult
    to read.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From emf@21:1/5 to All on Fri Jul 15 14:24:28 2022
    On 2022-07-15 11:40, Michael Haufe (TNO) wrote:
    On Thursday, July 14, 2022 at 3:44:28 PM UTC-5, emf wrote:
    Hi.

    JSLint now does not like this code (that it used to find OK), saying

    "Wrap a ternary expression in parens, with a line break after
    the left paren."

    =================
    orb = (orb0Btn.checked)
    ? 0
    : (orb5Btn.checked)
    ? 5
    : (orb10Btn.checked)
    ? 10
    : (orb15Btn.checked)
    ? 15
    : 20;
    =================

    What is now the correct syntax for the ternary expression?

    It's just a jslint setting. You can turn that off I'm pretty sure.

    I think it wants:

    (
    p ? truePart : (
    p ? truePart : falsePart
    )
    )


    I think this is because nested ternaries can be a little hard to read if you don't format them properly.

    I prefer ESLint

    OK, JSLint does not find anything wrong with this

    orb = ((orb0Btn.checked)
    ? 0
    : (orb5Btn.checked)
    ? 5
    : (orb10Btn.checked)
    ? 10
    : (orb15Btn.checked)
    ? 15
    : 20);

    The only now warning is:

    1. Bad assignment to 'panel'. 89.5
    panel = document.getElementById("panel");

    however the program (see sig below in (nataltransits2.js) still
    does not work...

    Eustace
    --
    Natal Transits Calculator
    https://emf.neocities.org/nt/nataltransits2.html

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Ram@21:1/5 to Stefan Ram on Sat Jul 16 12:19:51 2022
    ram@zedat.fu-berlin.de (Stefan Ram) writes:
    orb =
    orb0Btn.checked? 0:
    orb5Btn.checked? 5:
    orb10Btn.checked? 10:
    orb15Btn.checked? 15:
    20;

    Or,

    orb =
    orb0Btn. checked? 0:
    orb5Btn. checked? 5:
    orb10Btn.checked? 10:
    orb15Btn.checked? 15:
    20;

    . Now, imagine that someone does not know all details of the
    ternary operator well, but has a basic idea of it. In which
    way could he be mislead by this?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Michael Haufe (TNO)@21:1/5 to emf on Sat Jul 16 08:37:31 2022
    On Friday, July 15, 2022 at 1:24:37 PM UTC-5, emf wrote:
    [...]
    The only now warning is:

    1. Bad assignment to 'panel'. 89.5
    panel = document.getElementById("panel");

    however the program (see sig below in (nataltransits2.js) still
    does not work...
    Eustace

    ESLint points out a number of issues remaining:

    <https://emf.neocities.org/nt/nataltransits2.js>

    11:9 'ephem' is not defined. (no-undef)

    15:16 'ephem' is not defined. (no-undef)

    19:9 'ephem' is not defined. (no-undef)

    20:9 'ephem' is not defined. (no-undef)

    29:9 'reader' is not defined. (no-undef)

    30:16 'reader' is not defined. (no-undef)

    38:5 'reader' is not defined. (no-undef)

    39:5 'reader' is not defined. (no-undef)

    40:5 'reader' is not defined. (no-undef)

    49:16 'getBDay' is not defined. (no-undef)

    81:9 'findTransits' is not defined. (no-undef)

    83:9 'panel' is not defined. (no-undef)

    89:5 'panel' is not defined. (no-undef)

    91:22 'e' is defined but never used. (no-unused-vars)


    You have to declare a variable before assigning to it.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From emf@21:1/5 to Stefan Ram on Sat Jul 16 17:27:59 2022
    On 2022-07-16 08:19, Stefan Ram wrote:
    ram@zedat.fu-berlin.de (Stefan Ram) writes:
    orb =
    orb0Btn.checked? 0:
    orb5Btn.checked? 5:
    orb10Btn.checked? 10:
    orb15Btn.checked? 15:
    20;

    Or,

    orb =
    orb0Btn. checked? 0:
    orb5Btn. checked? 5:
    orb10Btn.checked? 10:
    orb15Btn.checked? 15:
    20;

    . Now, imagine that someone does not know all details of the
    ternary operator well, but has a basic idea of it. In which
    way could he be mislead by this?

    Thanks! Your idea is very simple and easy to understand!

    emf
    --
    Natal Transits Calculator
    https://emf.neocities.org/nt/nataltransits2.html

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From emf@21:1/5 to All on Sat Jul 16 17:46:17 2022
    On 2022-07-16 11:37, Michael Haufe (TNO) wrote:
    On Friday, July 15, 2022 at 1:24:37 PM UTC-5, emf wrote:
    [...]
    The only now warning is:

    1. Bad assignment to 'panel'. 89.5
    panel = document.getElementById("panel");

    however the program (see sig below in (nataltransits2.js) still
    does not work...
    Eustace

    ESLint points out a number of issues remaining:

    <https://emf.neocities.org/nt/nataltransits2.js>

    11:9 'ephem' is not defined. (no-undef)

    15:16 'ephem' is not defined. (no-undef)

    19:9 'ephem' is not defined. (no-undef)

    20:9 'ephem' is not defined. (no-undef)

    29:9 'reader' is not defined. (no-undef)

    30:16 'reader' is not defined. (no-undef)

    38:5 'reader' is not defined. (no-undef)

    39:5 'reader' is not defined. (no-undef)

    40:5 'reader' is not defined. (no-undef)

    49:16 'getBDay' is not defined. (no-undef)

    81:9 'findTransits' is not defined. (no-undef)

    83:9 'panel' is not defined. (no-undef)

    89:5 'panel' is not defined. (no-undef)

    91:22 'e' is defined but never used. (no-unused-vars)


    You have to declare a variable before assigning to it.

    There was only 1 warning because in the process of JSLinting I
    had added imported globals. This was nataltransits2.js, and
    there is also a nataltransits.js,

    Well, I have to start checking the program from the beginning to
    find out where the bug is. Then I may seek the advise of this
    newsgroup again.

    The thing is that the webpage was working fine before... I'm
    thinking of starting to comment out one "use strict" at a time,
    to see if at some point the program will start working again...

    Thanks to all,

    Eustace
    --
    Natal Transits Calculator
    https://emf.neocities.org/nt/nataltransits2.html

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)