{"action":"created","issue":{"url":"https://api.github.com/repos/eslint/eslint/issues/3460","labels_url":"https://api.github.com/repos/eslint/eslint/issues/3460/labels{/name}","comments_url":"https://api.github.com/repos/eslint/eslint/issues/3460/comments","events_url":"https://api.github.com/repos/eslint/eslint/issues/3460/events","html_url":"https://github.com/eslint/eslint/issues/3460","id":102095727,"number":3460,"title":"Ability to get a previous node from the context","user":{"login":"denis-sokolov","id":113721,"avatar_url":"https://avatars.githubusercontent.com/u/113721?v=3","gravatar_id":"","url":"https://api.github.com/users/denis-sokolov","html_url":"https://github.com/denis-sokolov","followers_url":"https://api.github.com/users/denis-sokolov/followers","following_url":"https://api.github.com/users/denis-sokolov/following{/other_user}","gists_url":"https://api.github.com/users/denis-sokolov/gists{/gist_id}","starred_url":"https://api.github.com/users/denis-sokolov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/denis-sokolov/subscriptions","organizations_url":"https://api.github.com/users/denis-sokolov/orgs","repos_url":"https://api.github.com/users/denis-sokolov/repos","events_url":"https://api.github.com/users/denis-sokolov/events{/privacy}","received_events_url":"https://api.github.com/users/denis-sokolov/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":3,"created_at":"2015-08-20T09:04:06Z","updated_at":"2015-08-20T09:47:34Z","closed_at":null,"body":"I am writing a few rules catching common typos in multiple assignment statements. For example:\r\n\r\n```js\r\nfoo.x = getX();\r\nfoo.x = getY(); \r\n```\r\n\r\nClearly this is a mistake. While I declare `ExpressionStatement` to be the scope of my rule, I need to \"peek\" to see the previous node and check whether it assigns to the same variable.\r\n\r\nCurrently `context` already provides `getTokenBefore`, `getNodeByRangeIndex`, and other convenience methods. It seems reasonable for it to have a `getNodeBefore` method.\r\nI can almost simulate it with `getNodeByRangeIndex(node.range[0] - 1)`, but that's hacky and breaks if there are multiple whitespace characters between the nodes.\r\n\r\nIs there a chance to see a `getNodeBefore` or a similar method on the context or in the ast-utils?\r\n"},"comment":{"url":"https://api.github.com/repos/eslint/eslint/issues/comments/132957911","html_url":"https://github.com/eslint/eslint/issues/3460#issuecomment-132957911","issue_url":"https://api.github.com/repos/eslint/eslint/issues/3460","id":132957911,"user":{"login":"denis-sokolov","id":113721,"avatar_url":"https://avatars.githubusercontent.com/u/113721?v=3","gravatar_id":"","url":"https://api.github.com/users/denis-sokolov","html_url":"https://github.com/denis-sokolov","followers_url":"https://api.github.com/users/denis-sokolov/followers","following_url":"https://api.github.com/users/denis-sokolov/following{/other_user}","gists_url":"https://api.github.com/users/denis-sokolov/gists{/gist_id}","starred_url":"https://api.github.com/users/denis-sokolov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/denis-sokolov/subscriptions","organizations_url":"https://api.github.com/users/denis-sokolov/orgs","repos_url":"https://api.github.com/users/denis-sokolov/repos","events_url":"https://api.github.com/users/denis-sokolov/events{/privacy}","received_events_url":"https://api.github.com/users/denis-sokolov/received_events","type":"User","site_admin":false},"created_at":"2015-08-20T09:47:34Z","updated_at":"2015-08-20T09:47:34Z","body":"That works if I use the 0-th range index, not the 1-st:\r\n\r\n```js\r\ngetNodeByRangeIndex(context.getTokenBefore(node).range[0])\r\n```\r\n\r\nThank you, @lo1tuma.\r\n\r\n\r\nStill, this seems something that is beneficial to abstract away in a `getPreviousNode`, as opposed to copying across rules, isn't it?"}}