Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

54 lines
1.8 KiB
Plaintext

== Why is this an issue?
Reading a non-existent property on an object always returns ``++undefined++``. Doing so is usually an error; either in the name of the property or the type of the variable being accessed.
If an attempt is made to access properties of a primitive, the primitive is automatically encased in a primitive-wrapper object for the operation. But being "promoted" to an object doesn't mean that the primitive will actually have properties to access. The wrapper object still won't have the non-existent property and ``++undefined++`` will be returned instead.
This rule raises an issue when an attempt is made to access properties of a primitive. Thus this rule should only be activated when you don't use monkey patching for standard objects, like ``++Number++``, ``++Boolean++`` and ``++String++``.
=== Noncompliant code example
[source,javascript]
----
x = 42;
y = x.length; // Noncompliant, Number type doesn't have "length" property
----
=== Exceptions
The Ember framework introduces a few extensions to ``++String++``. Since it is a widely used package, the following ``++String++`` properties will not trigger this rule even though they are not built-in:
* ``++camelize++``
* ``++capitalize++``
* ``++classify++``
* ``++dasherize++``
* ``++decamelize++``
* ``++fmt++``
* ``++loc++``
* ``++underscore++``
* ``++w++``
ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)
=== on 1 Nov 2019, 17:34:52 Elena Vilchik wrote:
See \https://github.com/SonarSource/SonarJS/issues/1698
=== on 21 Oct 2020, 16:44:43 Guillaume Dequenne wrote:
Dropping this rule as it has low value. See:
https://github.com/SonarSource/SonarJS/issues/2208
https://github.com/SonarSource/SonarJS/issues/1698
endif::env-github,rspecator-view[]