rspec/rules/S3003/javascript/comments-and-links.adoc

68 lines
2.5 KiB
Plaintext
Raw Normal View History

=== On 2015-11-18T17:47:57Z Elena Vilchik Wrote:
\[~ann.campbell.2] I'm stuck with this rule. Could you help me with a draft?
Initially idea was to check that binary operations are called with operands of same type. But further investigations shown that it's common practice to use what ever types you want :)
So I found out cases when expected result might differ from actual (see SONARJS-450), and I think that this rule should check only these particular cases. Now I don't know what should be the description and especially the title of this rule.
=== On 2015-11-18T19:51:22Z Ann Campbell Wrote:
Okay [~elena.vilchik], let's narrow this down. We want to raise an issue when:
* String is compared (<, >, +<=+, >=, ==(?), ===(?)) with ... anything? Linked ticket shows ``++str1 < str2++`` but it seems that it would be equally faulty with ``++str1 < obj++`` and ``++str1 >= 4++`` ...?
* Strings are concatenated with non-strings
* dis-similar types are checked for (in)equality. Is this only ``++===++`` or ``++==++`` as well?
=== On 2015-11-19T11:34:42Z Elena Vilchik Wrote:
\[~ann.campbell.2] Not exactly. It should be this way:
* string compared with string only (<, >, +<=+, >=)
----
"123" < "14" // true, lexical comparison <--- Noncompliant
"123" < 14 // false, both casted to numbers
----
Comparison of string with other types is not so dangerous (because actual behaviour is quite expected).
* string concatenated with numbers (because some could expect addition)
----
"123" + 45 // "12345" <--- Noncompliant
----
* check only "===" for any non identical types
----
"1" == 1 // true
"1" === 1 // false, whatever values, if types are different <--- Noncompliant
----
=== On 2015-11-19T19:53:49Z Ann Campbell Wrote:
What do you think of splitting this into two rules:
* Faulty string operations should not be made
* "===" should not be used with dissimilar types
?
Otherwise, the best I've got is: Faulty operations should not be made
=== On 2015-11-20T09:46:42Z Elena Vilchik Wrote:
\[~ann.campbell.2] We decided to split it to 3 rules :)
* String comparisons should not be made (major with suspicious tag)
* Numbers should be added to strings (major with suspicious tag)
* "===" should not be used with dissimilar types (critical with bug tag)
(welcome to change these titles)
Could you create RSPECs?
=== On 2015-11-20T16:38:40Z Elena Vilchik Wrote:
\[~ann.campbell.2] Looks like i explained rule badly. I changed description so that now IMO it reflect the rule idea. Could you check it?
=== On 2015-11-20T16:48:39Z Ann Campbell Wrote:
Looks good [~elena.vilchik]