{"action":"created","issue":{"url":"https://api.github.com/repos/palantir/tslint/issues/1105","repository_url":"https://api.github.com/repos/palantir/tslint","labels_url":"https://api.github.com/repos/palantir/tslint/issues/1105/labels{/name}","comments_url":"https://api.github.com/repos/palantir/tslint/issues/1105/comments","events_url":"https://api.github.com/repos/palantir/tslint/issues/1105/events","html_url":"https://github.com/palantir/tslint/pull/1105","id":147549402,"number":1105,"title":"Add \"no-invalid-this\" rule","user":{"login":"AndyMoreland","id":37327,"avatar_url":"https://avatars.githubusercontent.com/u/37327?v=3","gravatar_id":"","url":"https://api.github.com/users/AndyMoreland","html_url":"https://github.com/AndyMoreland","followers_url":"https://api.github.com/users/AndyMoreland/followers","following_url":"https://api.github.com/users/AndyMoreland/following{/other_user}","gists_url":"https://api.github.com/users/AndyMoreland/gists{/gist_id}","starred_url":"https://api.github.com/users/AndyMoreland/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndyMoreland/subscriptions","organizations_url":"https://api.github.com/users/AndyMoreland/orgs","repos_url":"https://api.github.com/users/AndyMoreland/repos","events_url":"https://api.github.com/users/AndyMoreland/events{/privacy}","received_events_url":"https://api.github.com/users/AndyMoreland/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/palantir/tslint/labels/PR:%20Needs%20Revision","name":"PR: Needs Revision","color":"FBEA92"}],"state":"open","locked":false,"assignee":{"login":"JKillian","id":1400151,"avatar_url":"https://avatars.githubusercontent.com/u/1400151?v=3","gravatar_id":"","url":"https://api.github.com/users/JKillian","html_url":"https://github.com/JKillian","followers_url":"https://api.github.com/users/JKillian/followers","following_url":"https://api.github.com/users/JKillian/following{/other_user}","gists_url":"https://api.github.com/users/JKillian/gists{/gist_id}","starred_url":"https://api.github.com/users/JKillian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JKillian/subscriptions","organizations_url":"https://api.github.com/users/JKillian/orgs","repos_url":"https://api.github.com/users/JKillian/repos","events_url":"https://api.github.com/users/JKillian/events{/privacy}","received_events_url":"https://api.github.com/users/JKillian/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/palantir/tslint/milestones/18","html_url":"https://github.com/palantir/tslint/milestones/TSLint%203.8","labels_url":"https://api.github.com/repos/palantir/tslint/milestones/18/labels","id":1648947,"number":18,"title":"TSLint 3.8","description":"","creator":{"login":"adidahiya","id":723999,"avatar_url":"https://avatars.githubusercontent.com/u/723999?v=3","gravatar_id":"","url":"https://api.github.com/users/adidahiya","html_url":"https://github.com/adidahiya","followers_url":"https://api.github.com/users/adidahiya/followers","following_url":"https://api.github.com/users/adidahiya/following{/other_user}","gists_url":"https://api.github.com/users/adidahiya/gists{/gist_id}","starred_url":"https://api.github.com/users/adidahiya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adidahiya/subscriptions","organizations_url":"https://api.github.com/users/adidahiya/orgs","repos_url":"https://api.github.com/users/adidahiya/repos","events_url":"https://api.github.com/users/adidahiya/events{/privacy}","received_events_url":"https://api.github.com/users/adidahiya/received_events","type":"User","site_admin":false},"open_issues":1,"closed_issues":8,"state":"open","created_at":"2016-03-16T20:41:43Z","updated_at":"2016-04-15T19:38:39Z","due_on":null,"closed_at":null},"comments":11,"created_at":"2016-04-11T20:42:01Z","updated_at":"2016-04-18T17:04:46Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/palantir/tslint/pulls/1105","html_url":"https://github.com/palantir/tslint/pull/1105","diff_url":"https://github.com/palantir/tslint/pull/1105.diff","patch_url":"https://github.com/palantir/tslint/pull/1105.patch"},"body":"This PR adds a rule that flags usage of the `this` keyword outside of class-body scopes.\r\n\r\nOften I find myself refactoring code that looks like:\r\n\r\n```ts\r\nclass Foo {\r\n    private aMethod() {\r\n        doWorkOn(this.someState.x);\r\n    }\r\n}\r\n```\r\n\r\nto pull `aMethod` out into a function that looks like:\r\n\r\n```ts\r\nfunction(someState) {\r\n    doWorkOn(someState.x);\r\n}\r\n```\r\n\r\nWhen I make this change by hand I find that I screw up a lot and accidentally write:\r\n\r\n```ts\r\nfunction(someState) {\r\n    doWorkOn(this.someState.x); /* note `this` */\r\n}\r\n```\r\n\r\nwhich does not cause a compile error because typescript unhelpfully infers `this` with type `any`.\r\n\r\nI've found that `this` outside of a `class` in code that is using ES6-class syntax is almost always a mistake. I wouldn't turn this on by default for all users of tslint, but it'd be very useful in my case (and I imagine for others.)"},"comment":{"url":"https://api.github.com/repos/palantir/tslint/issues/comments/211476898","html_url":"https://github.com/palantir/tslint/pull/1105#issuecomment-211476898","issue_url":"https://api.github.com/repos/palantir/tslint/issues/1105","id":211476898,"user":{"login":"AndyMoreland","id":37327,"avatar_url":"https://avatars.githubusercontent.com/u/37327?v=3","gravatar_id":"","url":"https://api.github.com/users/AndyMoreland","html_url":"https://github.com/AndyMoreland","followers_url":"https://api.github.com/users/AndyMoreland/followers","following_url":"https://api.github.com/users/AndyMoreland/following{/other_user}","gists_url":"https://api.github.com/users/AndyMoreland/gists{/gist_id}","starred_url":"https://api.github.com/users/AndyMoreland/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndyMoreland/subscriptions","organizations_url":"https://api.github.com/users/AndyMoreland/orgs","repos_url":"https://api.github.com/users/AndyMoreland/repos","events_url":"https://api.github.com/users/AndyMoreland/events{/privacy}","received_events_url":"https://api.github.com/users/AndyMoreland/received_events","type":"User","site_admin":false},"created_at":"2016-04-18T17:04:46Z","updated_at":"2016-04-18T17:04:46Z","body":"I've made the four changes you requested. Sorry for the sloppiness!"}}