55 lines
1.1 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
Object literal syntax, which initializes an object's properties inside the object declaration is cleaner and clearer than the alternative: creating an empty object, and then giving it properties one by one.
An issue is raised when the following pattern is met:
* An empty object is created.
* A consecutive single-line statement adds a property to the created object.
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,javascript]
2021-04-28 16:49:39 +02:00
----
let person = {}; // Noncompliant
person.firstName = "John";
person.middleInitial = "Q";
person.lastName = "Public";
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,javascript]
2021-04-28 16:49:39 +02:00
----
let person = {
firstName: "John",
middleInitial: "Q",
lastName: "Public",
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Declare one or more properties of this object inside of the object literal syntax instead of using separate statements.
'''
== Comments And Links
(visible only on this page)
=== on 12 Nov 2015, 18:20:41 Linda Martin wrote:
\[~elena.vilchik] Same here, not sure of the value.
endif::env-github,rspecator-view[]