{"action":"created","issue":{"url":"https://api.github.com/repos/jacksonrayhamilton/JSLint/issues/1","labels_url":"https://api.github.com/repos/jacksonrayhamilton/JSLint/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/jacksonrayhamilton/JSLint/issues/1/comments","events_url":"https://api.github.com/repos/jacksonrayhamilton/JSLint/issues/1/events","html_url":"https://github.com/jacksonrayhamilton/JSLint/pull/1","id":60890559,"number":1,"title":"Add option to tolerate the use of the 'in' operator.","user":{"login":"Xotic750","id":216041,"avatar_url":"https://avatars.githubusercontent.com/u/216041?v=3","gravatar_id":"","url":"https://api.github.com/users/Xotic750","html_url":"https://github.com/Xotic750","followers_url":"https://api.github.com/users/Xotic750/followers","following_url":"https://api.github.com/users/Xotic750/following{/other_user}","gists_url":"https://api.github.com/users/Xotic750/gists{/gist_id}","starred_url":"https://api.github.com/users/Xotic750/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Xotic750/subscriptions","organizations_url":"https://api.github.com/users/Xotic750/orgs","repos_url":"https://api.github.com/users/Xotic750/repos","events_url":"https://api.github.com/users/Xotic750/events{/privacy}","received_events_url":"https://api.github.com/users/Xotic750/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-03-12T20:07:34Z","updated_at":"2015-03-13T01:17:05Z","closed_at":"2015-03-12T20:10:35Z","pull_request":{"url":"https://api.github.com/repos/jacksonrayhamilton/JSLint/pulls/1","html_url":"https://github.com/jacksonrayhamilton/JSLint/pull/1","diff_url":"https://github.com/jacksonrayhamilton/JSLint/pull/1.diff","patch_url":"https://github.com/jacksonrayhamilton/JSLint/pull/1.patch"},"body":"Consider the following code:\r\n```javascript\r\n(function () {\r\n    'use strict';\r\n    /*jslint devel: true */\r\n    /*globals Array, Object */\r\n    /*properties\r\n        '0', '1', '2', '3', '4', '6', '7', call, create, forEach, hasOwnProperty,\r\n        length, log, prototype\r\n    */\r\n\r\n    var arrayLike = {\r\n            0: 'a',\r\n            1: 'b',\r\n            2: null,\r\n            3: 'd',\r\n            4: undefined,\r\n            6: 'f',\r\n            7: NaN,\r\n            length: 8\r\n        },\r\n        anArrayLike = Object.create(arrayLike, {}),\r\n        length = anArrayLike.length,\r\n        index,\r\n        item;\r\n\r\n    console.log('Using Array.prototype.forEach');\r\n    // Correct: output matches the expected input\r\n    Array.prototype.forEach.call(anArrayLike, function (item, index) {\r\n        console.log('forEach', index, item);\r\n    });\r\n\r\n    console.log('\\nIterate based on length, no filter');\r\n    // Incorrect: outputs everything, even 'holes'\r\n    for (index = 0; index < length; index += 1) {\r\n        item = anArrayLike[index];\r\n        console.log('length', index, item);\r\n    }\r\n\r\n    console.log('\\nIterate based on length, hasOwnProperty filter');\r\n    // Incorrect: nothing logged\r\n    for (index = 0; index < length; index += 1) {\r\n        if (anArrayLike.hasOwnProperty(index)) {\r\n            item = anArrayLike[index];\r\n            console.log('hasOwnProperty', index, item);\r\n        }\r\n    }\r\n\r\n    console.log('\\nIterate based on length, filter based on comparison with undefined');\r\n    // Incorrect: everything output except index 4 and the 'hole' at index 5\r\n    for (index = 0; index < length; index += 1) {\r\n        item = anArrayLike[index];\r\n        if (item !== undefined) {\r\n            console.log('undefined', index, item);\r\n        }\r\n    }\r\n\r\n    console.log('\\nIterate based on length, in filter');\r\n    // Correct: output matches the expected input, but fails jslint because of 'in'\r\n    for (index = 0; index < length; index += 1) {\r\n        if (index in anArrayLike) {\r\n            item = anArrayLike[index];\r\n            console.log('in', item);\r\n        }\r\n    }\r\n}());\r\n```\r\nhttp://jsfiddle.net/Xotic750/rLj4e1a7/\r\n\r\n```\r\nUsing Array.prototype.forEach\r\nforEach 0 a\r\nforEach 1 b\r\nforEach 2 null\r\nforEach 3 d\r\nforEach 4 undefined\r\nforEach 6 f\r\nforEach 7 NaN\r\n\r\nIterate based on length, no filter\r\nlength 0 a\r\nlength 1 b\r\nlength 2 null\r\nlength 3 d\r\nlength 4 undefined\r\nlength 5 undefined\r\nlength 6 f\r\nlength 7 NaN\r\n\r\nIterate based on length, hasOwnProperty filter\r\n\r\nIterate based on length, filter based on comparison with undefined\r\nundefined 0 a\r\nundefined 1 b\r\nundefined 2 null\r\nundefined 3 d\r\nundefined 6 f\r\nundefined 7 NaN\r\n\r\nIterate based on length, in filter\r\nin 0 a\r\nin 1 b\r\nin 2 null\r\nin 3 d\r\nin 4 undefined\r\nin 6 f\r\nin 7 NaN\r\n```\r\n\r\nNothing too odd about that code, but it doesn't pass JSLint.\r\n>Unexpected 'in'. Compare with undefined, or use the hasOwnProperty method instead.\r\n>        if (index in anArrayLike) { \r\n\r\nYou can see that the suggestions do not produce the same expected result, on by using `in` are the results correct.\r\n\r\nI can't see any reason for this warning, `in` seems very clear in it's purpose? How else can you get the expected result?\r\n\r\nThat's pretty annoying when all points to it being the correct solution, other than using the ES5 `Array#forEach`. \r\n\r\nMy projects use the `'for' with 'in' filtering` in numerous places, but will not pass JSLint and my IDE throws up the warnings. \r\n\r\ncomparing the `in` method with the `Array#forEach` it appears faster too, as it has a little less work to do. So I can get a little more performance by tailoring my code in this way.\r\n\r\nhttp://jsperf.com/jslint-in-warning\r\n\r\nI'd like to suggest an option:\r\n\r\n`/*jslint in: true */`\r\n\r\nThanks.\r\n"},"comment":{"url":"https://api.github.com/repos/jacksonrayhamilton/JSLint/issues/comments/78731294","html_url":"https://github.com/jacksonrayhamilton/JSLint/pull/1#issuecomment-78731294","issue_url":"https://api.github.com/repos/jacksonrayhamilton/JSLint/issues/1","id":78731294,"user":{"login":"jacksonrayhamilton","id":5356588,"avatar_url":"https://avatars.githubusercontent.com/u/5356588?v=3","gravatar_id":"","url":"https://api.github.com/users/jacksonrayhamilton","html_url":"https://github.com/jacksonrayhamilton","followers_url":"https://api.github.com/users/jacksonrayhamilton/followers","following_url":"https://api.github.com/users/jacksonrayhamilton/following{/other_user}","gists_url":"https://api.github.com/users/jacksonrayhamilton/gists{/gist_id}","starred_url":"https://api.github.com/users/jacksonrayhamilton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jacksonrayhamilton/subscriptions","organizations_url":"https://api.github.com/users/jacksonrayhamilton/orgs","repos_url":"https://api.github.com/users/jacksonrayhamilton/repos","events_url":"https://api.github.com/users/jacksonrayhamilton/events{/privacy}","received_events_url":"https://api.github.com/users/jacksonrayhamilton/received_events","type":"User","site_admin":false},"created_at":"2015-03-13T01:17:05Z","updated_at":"2015-03-13T01:17:05Z","body":"> I still see no good reason to not allow me to mark my `in`s as tolerable\r\n\r\nI think Crockford wants to reduce the amount of options in JSLint. Many of the options in the current version only serve to reduce the quality of your code, and that contradicts the purpose of a linter. Ideally your code should pass without any \"Tolerate...\" options enabled. And it certainly could if you wrote it a little differently.\r\n\r\n> Why not mark all methods and operators that call the [[HasProperty]] internal method etc, as unsafe?\r\n\r\nMaybe they should be. Though that opens up another can of worms because even basic property access touches the prototype. You might want to ask him about that.\r\n\r\n`in` is disallowed here because it is typically misused for the purpose of checking for own properties. `[[HasProperty]]` is probably suitable in other situations.\r\n\r\n> Disallows `this` or disallows `Object.create`?\r\n\r\n`this`. `Object.create` implies that you are using prototypes, which means that you probably need `this` to access data within methods. (If you were using parasitic inheritance then you wouldn't need prototypes nor `this`.) Though while disallowing `this` implies that `Object.create` isn't as useful in the context of prototypal inheritance, I forgot that `Object.create(null)` is useful for *avoiding* prototypal inheritance. So it should stick around, if not for the sole purpose of calling the function with `null`."}}