-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebUI: Correctly apply changed "save path" of RSS rules #21030
Conversation
@@ -742,12 +745,14 @@ | |||
$("lastMatchText").textContent = "QBT_TR(Last Match: Unknown)QBT_TR[CONTEXT=AutomatedRssDownloader]"; | |||
} | |||
|
|||
if (rulesList[ruleName].torrentParams.stopped === null) | |||
// use `== null` to check for both `null` and `undefined` | |||
if (rulesList[ruleName].torrentParams.stopped == null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general it is recommended to use
===
instead of==
. The proposed solution is an exception to this rule. The JSHint syntax checker even provides theeqnull
option for this reason.From the jQuery style guide:
Strict equality checks (===) should be used in favor of ==. The only exception is when checking for undefined and null by way of null.
So I turned on the smart mode of ESLint eqeqeq
rule so that it allows for such a comparison.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still I would like to enforce strict comparison operators unconditionally, it keeps the code uniform. It is verbose in these code but we only have a few instances for it (2 so far).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I consider verbose in this case is a plus. It become clear that it is expecting null
and undefined
values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I consider verbose in this case is a plus. It become clear that it is expecting
null
andundefined
values.
Ok. I had a feeling about it.
I just feel difficulty understanding JS. Is the following correct?
if ((rulesList[ruleName].torrentParams.stopped === undefined) || (rulesList[ruleName].torrentParams.stopped === null))
I noticed that someone describes check for undefined
as the following:
typeof(some_variable) === "undefined"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that there are benefits to being verbose, but have also found this smart rule to be an improvement to convenience on other projects with much stricter codebases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyway, it still requires verbosity either in the code or in the comment (so that someone does not break it later by replacing ==
with ===
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You avoid this by enforcing the general rule that all checks against null or undefined use ==
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I consider verbose in this case is a plus. It become clear that it is expecting
null
andundefined
values.Ok. I had a feeling about it. I just feel difficulty understanding JS. Is the following correct?
if ((rulesList[ruleName].torrentParams.stopped === undefined) || (rulesList[ruleName].torrentParams.stopped === null))I noticed that someone describes check for
undefined
as the following:typeof(some_variable) === "undefined"
It depends. If some_variable
is declared but hasn't assigned a value then some_variable === undefined
will hold. If some_variable
wasn't declared then some_variable === undefined
will throw exception and typeof(some_variable) === "undefined"
must be used.
Closes #20141.