jslint-org / jslint

JSLint, The JavaScript Code Quality and Coverage Tool
https://www.jslint.com
The Unlicense
3.62k stars 461 forks source link

error on for...of statement #176

Open n-a-m-e opened 8 years ago

n-a-m-e commented 8 years ago

Firstly thanks for writing jslint, secondly I found this new for-of loop that javascript has https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of but js lint throws the error

Expected ';' and instead saw 'of'.
(function(){
    'use strict';
    let arr = [3, 5, 7];
    let i;
    arr.foo = "hello";

    for (i of arr) {
        console.log(i); // logs "3", "5", "7", "hello"
    }
}());

I could always use forEach instead but then I can't break out of the loop

(function () {
    'use strict';
    let arr = [3, 5, 7];
    arr.foo = "hello";
    arr.forEach(function (element, index) {
        console.log(element); // logs "3", "5", "7"
        console.log(index);   // logs "0", "1", "2"
    });
}());

what is your opinion, is the for of loop useful or should I use something else instead. Thanks

douglascrockford commented 8 years ago

The for of statement is a new ES6 feature that has not yet been proven to be a good part.

Try arr.every.

Recursion is becoming a better approach than looping.

Akuli commented 3 weeks ago

Could this perhaps be reconsidered? It's been 8 more years, and at least to me, for...of loops did turn out to be a good part. If maintainers agree, I might implement this during the next few weeks.

I'm new to JSLint, and really I like it: it is a self-contained, dependency-free tool that just works without npm hell. The one thing I don't like is that jslint cannot parse my loops.

douglascrockford commented 3 weeks ago

I think that is a good idea. We could also relax the restrictions on 'let' in scopes. Some of the JSLint rules were to get us thru some standard transitions, and I think those are way behind us now.

kaizhu256 commented 2 weeks ago

// test_cause: // ["for", "stmt_for", "unexpected_a", "for", 1]

        warn("unexpected_a", the_for);
    }
    check_not_top_level(the_for);
    functionage.loop += 1;
    advance("(");
    token_now.free = true;
    if (token_nxt.id === ";") {

...