Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #40987 > unrolled thread
| Started by | emf <emfril@gmail.com> |
|---|---|
| First post | 2022-07-14 16:44 -0400 |
| Last post | 2022-07-15 14:19 -0400 |
| Articles | 7 — 2 participants |
Back to article view | Back to comp.lang.javascript
JSLint: "Wrap a ternary expression in parens, ..." emf <emfril@gmail.com> - 2022-07-14 16:44 -0400
Re: JSLint: "Wrap a ternary expression in parens, ..." "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2022-07-15 08:40 -0700
Re: JSLint: "Wrap a ternary expression in parens, ..." emf <emfril@gmail.com> - 2022-07-15 14:24 -0400
Re: JSLint: "Wrap a ternary expression in parens, ..." "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2022-07-16 08:37 -0700
Re: JSLint: "Wrap a ternary expression in parens, ..." emf <emfril@gmail.com> - 2022-07-16 17:46 -0400
Re: JSLint: "Wrap a ternary expression in parens, ..." emf <emfril@gmail.com> - 2022-07-16 17:27 -0400
Re: JSLint: "Wrap a ternary expression in parens, ..." emf <emfril@gmail.com> - 2022-07-15 14:19 -0400
| From | emf <emfril@gmail.com> |
|---|---|
| Date | 2022-07-14 16:44 -0400 |
| Subject | JSLint: "Wrap a ternary expression in parens, ..." |
| Message-ID | <tapv73$1pkf$1@gioia.aioe.org> |
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
[toc] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2022-07-15 08:40 -0700 |
| Message-ID | <ff42c0ad-120d-4a19-9a04-e4b47f2b0a92n@googlegroups.com> |
| In reply to | #40987 |
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
[toc] | [prev] | [next] | [standalone]
| From | emf <emfril@gmail.com> |
|---|---|
| Date | 2022-07-15 14:24 -0400 |
| Message-ID | <tasbct$11ej$1@gioia.aioe.org> |
| In reply to | #40989 |
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
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2022-07-16 08:37 -0700 |
| Message-ID | <8fdd197b-5ad1-4d87-8358-40a1d7cb559fn@googlegroups.com> |
| In reply to | #40991 |
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.
[toc] | [prev] | [next] | [standalone]
| From | emf <emfril@gmail.com> |
|---|---|
| Date | 2022-07-16 17:46 -0400 |
| Message-ID | <tavbjb$12sf$1@gioia.aioe.org> |
| In reply to | #40994 |
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
[toc] | [prev] | [next] | [standalone]
| From | emf <emfril@gmail.com> |
|---|---|
| Date | 2022-07-16 17:27 -0400 |
| Message-ID | <tavah4$nfj$1@gioia.aioe.org> |
| In reply to | #40991 |
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
[toc] | [prev] | [next] | [standalone]
| From | emf <emfril@gmail.com> |
|---|---|
| Date | 2022-07-15 14:19 -0400 |
| Message-ID | <tasb35$svu$1@gioia.aioe.org> |
| In reply to | #40987 |
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! :)
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web