File tree Expand file tree Collapse file tree 1 file changed +65
-0
lines changed
projects/eslint-plugin/rules/general/docs/rules Expand file tree Collapse file tree 1 file changed +65
-0
lines changed Original file line number Diff line number Diff line change 1+ # Don't use negated ` !Object.keys() ` or double negated ` !!Object.keys() ` expressions as they always evaluate to ` false ` and ` true ` , respectively
2+
3+ This rule enforces that engineers don't use a truthy or falsy value that ` Object.keys() ` can return. Instead, use an expression that is more precise.
4+
5+ ## Rule Details
6+
7+ Examples of ** incorrect** code for this rule:
8+
9+ ``` js
10+ if (! Object .keys ({foo: ' bar' })) {
11+ // do your magic
12+ }
13+ ```
14+
15+ or
16+
17+ ``` js
18+ !! Object .keys ({foo: ' bar' }) && ' test' ;
19+ ```
20+
21+ or
22+
23+ ``` js
24+ const negatedObjectKeys = ! Object .keys ({foo: ' bar' });
25+ ```
26+
27+ or
28+
29+ ``` js
30+ ! Object .keys ({foo: ' bar' }) && true ;
31+ ```
32+
33+ Examples of ** correct** code for this rule:
34+
35+ ``` js
36+ if (Object .keys ({foo: ' bar' })) {
37+ // do your magic
38+ }
39+ ```
40+
41+ or
42+
43+ ``` js
44+ if (Object .keys ({foo: ' bar' }).length ) {
45+ // do your magic
46+ }
47+ ```
48+
49+ or
50+
51+ ``` js
52+ Object .keys ({foo: ' bar' }) && ' test' ;
53+ ```
54+
55+ or
56+
57+ ``` js
58+ if (Object .keys ({foo: ' bar' }).find ((i ) => true )) {
59+ // do your magic
60+ }
61+ ```
62+
63+ ## Further Reading
64+
65+ - https://github.com/liferay/liferay-frontend-projects/issues/10
You can’t perform that action at this time.
0 commit comments