summaryrefslogtreecommitdiffstats
path: root/docs/code-quality/lint/linters/eslint-plugin-mozilla/prefer-boolean-length-check.rst
blob: cd6ee4e5441cc8f23986151dd65afc3c6f4a9c4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
prefer-boolean-length-check
===========================

Prefers using a boolean length check rather than comparing against zero.

Examples of incorrect code for this rule:
-----------------------------------------

.. code-block:: js

    if (foo.length == 0) {}
    if (foo.length > 0) {}
    if (foo && foo.length == 0) {}
    function bar() { return foo.length > 0 }

Examples of correct code for this rule:
---------------------------------------

.. code-block:: js

    if (foo.length && foo.length) {}
    if (!foo.length) {}
    var a = foo.length > 0
    function bar() { return !!foo.length }