Search and Top Navigation
#15192 closed bug (notabug)
Opened May 26, 2017 10:13PM UTC
Closed May 27, 2017 01:13AM UTC
Clean code
Reported by: | dgofman | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | none |
Component: | ui.core | Version: | 1.12.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
I am wondering why you are excluding ===
and !==
validation from jshint.
When I am evaluating code by using jshint I am getting many warning:
Expected !==
and instead saw !=
.
One of critical issue in your core widget on line 35
https://github.com/jquery/jquery-ui/blob/master/ui/widget.js#L35
You are implemented for loop such as:
for ( i = 0; ( elem = elems[ i ] ) != null; i++ ) {
however ( elem = elems[ i ] )
will never will be null i most cases is "undefined"
If I will change to strong type such as:
for ( i = 0; ( elem = elems[ i ] ) !== null; i++ ) {
I will be in infinite loop and browser will be freezes.
I will suggest make changes and fix this loops as well either:
for ( i = 0; ( elem = elems[ i ] ) !== undefined; i++ )
or
for ( i = 0; !!( elem = elems[ i ] ); i++ )
to handle null and undefined
Thanks,
David
Attachments (0)
Change History (3)
Changed May 26, 2017 10:22PM UTC by comment:1
Changed May 26, 2017 10:29PM UTC by comment:2
description: | I am wondering why you are excluding '===' and '!==' validation from jshint. \ \ When I am evaluating code by using jshint I am getting many warning: \ \ Expected '!==' and instead saw '!='. \ \ One of critical issue in your core widget on line 35 \ \ https://github.com/jquery/jquery-ui/blob/master/ui/widget.js#L35 \ \ You are implemented for loop such as: \ \ for ( i = 0; ( elem = elems[ i ] ) != null; i++ ) { \ \ however "( elem = elems[ i ] )" will never will be null i most cases is "undefined" \ \ If I will change to strong type such as: \ \ for ( i = 0; ( elem = elems[ i ] ) !== null; i++ ) { \ \ I will be in infinite loop and browser will be freezes. \ \ \ I will suggest make changes and fix this loops as well either: \ \ for ( i = 0; ( elem = elems[ i ] ) !== undefined; i++ ) \ or \ for ( i = 0; !!( elem = elems[ i ] ); i++ ) \ \ to handle null and undefined \ \ Thanks, \ David \ → I am wondering why you are excluding `===` and `!==` validation from jshint. \ \ When I am evaluating code by using jshint I am getting many warning: \ \ Expected `!==` and instead saw `!=`. \ \ One of critical issue in your core widget on line 35 \ \ https://github.com/jquery/jquery-ui/blob/master/ui/widget.js#L35 \ \ You are implemented for loop such as: \ \ {{{#!javascript \ for ( i = 0; ( elem = elems[ i ] ) != null; i++ ) { \ }}} \ \ however `( elem = elems[ i ] )` will never will be null i most cases is "undefined" \ \ If I will change to strong type such as: \ \ {{{#!javascript \ for ( i = 0; ( elem = elems[ i ] ) !== null; i++ ) { \ }}} \ \ I will be in infinite loop and browser will be freezes. \ \ \ I will suggest make changes and fix this loops as well either: \ \ {{{#!javascript \ for ( i = 0; ( elem = elems[ i ] ) !== undefined; i++ ) \ }}} \ or \ {{{#!javascript \ for ( i = 0; !!( elem = elems[ i ] ); i++ ) \ }}} \ \ to handle null and undefined \ \ Thanks, \ David |
---|
Changed May 27, 2017 01:13AM UTC by comment:3
resolution: | → notabug |
---|---|
status: | new → closed |
Your coding standards differing from ours is not a bug.
PR: https://github.com/jquery/jquery-ui/pull/1819