{"action":"created","issue":{"url":"https://api.github.com/repos/eslint/eslint/issues/3373","labels_url":"https://api.github.com/repos/eslint/eslint/issues/3373/labels{/name}","comments_url":"https://api.github.com/repos/eslint/eslint/issues/3373/comments","events_url":"https://api.github.com/repos/eslint/eslint/issues/3373/events","html_url":"https://github.com/eslint/eslint/issues/3373","id":100453337,"number":3373,"title":"Verify if a value is returned for all code paths","user":{"login":"awerlang","id":589286,"avatar_url":"https://avatars.githubusercontent.com/u/589286?v=3","gravatar_id":"","url":"https://api.github.com/users/awerlang","html_url":"https://github.com/awerlang","followers_url":"https://api.github.com/users/awerlang/followers","following_url":"https://api.github.com/users/awerlang/following{/other_user}","gists_url":"https://api.github.com/users/awerlang/gists{/gist_id}","starred_url":"https://api.github.com/users/awerlang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/awerlang/subscriptions","organizations_url":"https://api.github.com/users/awerlang/orgs","repos_url":"https://api.github.com/users/awerlang/repos","events_url":"https://api.github.com/users/awerlang/events{/privacy}","received_events_url":"https://api.github.com/users/awerlang/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/eslint/eslint/labels/triage","name":"triage","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-08-12T02:45:55Z","updated_at":"2015-08-14T08:14:44Z","closed_at":null,"body":"I would like to work for a follow-up of #481.\r\n\r\nAugment `consistent-return` rule with an option `allCodePaths` (off by default).\r\n\r\nIf it is on, then if a value is returned for a given code path, then a value should be returned for every code path.\r\n\r\nThese are warning:\r\n\r\n```js\r\nif (true) return true;\r\n```\r\n```js\r\nif (true) return; return true;\r\n```\r\n\r\nThese are not:\r\n\r\n```js\r\nif (true) return;\r\n```\r\n```js\r\nif (true) return true; return false;\r\n```\r\n\r\nFor this rule, only `return <expression>;` shall be considered.\r\n\r\nCurrent version: v1.1.0\r\n\r\nPseudo-code:\r\n\r\n```\r\nreturnStatus(BlockStatement node):\r\n\tstatus := returnStatus(...node.body);\r\n\tcase always in status\r\n\t\tResult := always;\r\n\tcase maybe in status\r\n\t\tResult := maybe;\r\n\tcase default:\r\n\t\tResult := never;\r\n\r\nreturnStatus(IfStatement node):\r\n\tcase returns(node.then) && returns(node.else)\r\n\t\tResult := always;\r\n\tcase returns(node.then) <> returns(node.else)\r\n\t\tResult := maybe;\r\n\tcase default:\r\n\t\tResult := never;\r\n\r\nreturnStatus(ReturnStatement node):\r\n\tcase node.argument\r\n\t\tResult := always;\r\n\tResult := never;\r\n\r\nreturnStatus(Statement node):\r\n\tResult := never;\r\n```\r\n\r\nThis listing is not complete for all statements, but will check that.\r\n\r\nIt is just needed to have `returnStatus` computed for immediate children, currently I thinking about it. It would be easy to mutate each node in-place, but I haven't see any rule doing that. I plan to maintain it as a simple visitor instead of querying children.\r\n\r\nAm I missing something important or there's already a WIP on this?\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/eslint/eslint/issues/comments/131014750","html_url":"https://github.com/eslint/eslint/issues/3373#issuecomment-131014750","issue_url":"https://api.github.com/repos/eslint/eslint/issues/3373","id":131014750,"user":{"login":"mysticatea","id":1937871,"avatar_url":"https://avatars.githubusercontent.com/u/1937871?v=3","gravatar_id":"","url":"https://api.github.com/users/mysticatea","html_url":"https://github.com/mysticatea","followers_url":"https://api.github.com/users/mysticatea/followers","following_url":"https://api.github.com/users/mysticatea/following{/other_user}","gists_url":"https://api.github.com/users/mysticatea/gists{/gist_id}","starred_url":"https://api.github.com/users/mysticatea/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mysticatea/subscriptions","organizations_url":"https://api.github.com/users/mysticatea/orgs","repos_url":"https://api.github.com/users/mysticatea/repos","events_url":"https://api.github.com/users/mysticatea/events{/privacy}","received_events_url":"https://api.github.com/users/mysticatea/received_events","type":"User","site_admin":false},"created_at":"2015-08-14T08:14:44Z","updated_at":"2015-08-14T08:14:44Z","body":"escope is using [esrecurse](https://github.com/estools/esrecurse), this is a library to traverse AST.\r\nBut eslint is using estraverse, so cannot use esrecurse.\r\n\r\nesrecurse can control timing of traversing child nodes. This is needed for code path analysis.\r\nOn the other hand, esrecurse cannot process many eslint rules in traversing once like estraverse. Because esrecurse's logic is recursively.\r\n\r\nNow, I'm thinking an utility for path analysis in my eslint plugin.\r\nMaybe it becomes like thing which does map-reduce paths in main traversing.\r\n\r\n"}}