{"action":"created","issue":{"url":"https://api.github.com/repos/eslint/eslint/issues/6974","repository_url":"https://api.github.com/repos/eslint/eslint","labels_url":"https://api.github.com/repos/eslint/eslint/issues/6974/labels{/name}","comments_url":"https://api.github.com/repos/eslint/eslint/issues/6974/comments","events_url":"https://api.github.com/repos/eslint/eslint/issues/6974/events","html_url":"https://github.com/eslint/eslint/issues/6974","id":173264647,"number":6974,"title":"Proposal for Parser Services","user":{"login":"nzakas","id":38546,"avatar_url":"https://avatars.githubusercontent.com/u/38546?v=3","gravatar_id":"","url":"https://api.github.com/users/nzakas","html_url":"https://github.com/nzakas","followers_url":"https://api.github.com/users/nzakas/followers","following_url":"https://api.github.com/users/nzakas/following{/other_user}","gists_url":"https://api.github.com/users/nzakas/gists{/gist_id}","starred_url":"https://api.github.com/users/nzakas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nzakas/subscriptions","organizations_url":"https://api.github.com/users/nzakas/orgs","repos_url":"https://api.github.com/users/nzakas/repos","events_url":"https://api.github.com/users/nzakas/events{/privacy}","received_events_url":"https://api.github.com/users/nzakas/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/eslint/eslint/labels/core","name":"core","color":"c7def8"},{"url":"https://api.github.com/repos/eslint/eslint/labels/evaluating","name":"evaluating","color":"fef2c0"},{"url":"https://api.github.com/repos/eslint/eslint/labels/feature","name":"feature","color":"bfd4f2"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":14,"created_at":"2016-08-25T17:34:56Z","updated_at":"2016-08-26T14:28:23Z","closed_at":null,"body":"**Problem**\r\n\r\nJavaScript dialects like Flow and TypeScript often have additional utilities that can be used for various purposes (i.e., a type checker). Currently, there is no way to easily expose these utilities to rules, as they sometimes require access to the state information that created the AST (the TypeScript type checker is like this). This cuts off ESLint rules from useful utilities. \r\n\r\n**Background Discussions**\r\n\r\nhttps://github.com/eslint/typescript-eslint-parser/issues/61#issuecomment-241567437\r\nhttps://github.com/eslint/eslint/issues/5040#issuecomment-174206925\r\n\r\n**Proposal**\r\n\r\n**tl;dr** Allow parsers to optionally export *parser services* that can be retrieved through a new method on the `context` object.\r\n\r\nFirst, allow parsers to expose a special `parseForESLint()` method in addition to the de facto standard `parse()` method. The `parseForESLint()` method would receive the same argument as `parse()`, but would return an object in this form:\r\n\r\n```\r\n{\r\n    ast: ast,     // the AST as returned from parse()\r\n    services: {\r\n        serviceName: someObject     // a service to provide to rules\r\n    }\r\n}\r\n```\r\n\r\nIf `parseForESLint()` is found, that will be used by ESLint, otherwise `parse()` is used. Doing this allows us to add additional ESLint-specific properties without needing to add them on an ESTree structure (where they don't belong). This also opens up the possibility of adding other ESLint-specific functionality in this return object in the future.\r\n\r\nThen, we'd add a ~~`context.getParserService()` method~~ `context.parserServices` object such that you can use it in a rule like this:\r\n\r\n```js\r\nvar service = context.parserServices.serviceName;\r\n```\r\n\r\nThere would be no restrictions on the type or format of services that can be exposed through this mechanism. It's completely free-form. \r\n\r\n----\r\n\r\nI'd love to get some feedback on this proposal from @JamesHenry @jeffmo @hzoo @alexeagle"},"comment":{"url":"https://api.github.com/repos/eslint/eslint/issues/comments/242750795","html_url":"https://github.com/eslint/eslint/issues/6974#issuecomment-242750795","issue_url":"https://api.github.com/repos/eslint/eslint/issues/6974","id":242750795,"user":{"login":"platinumazure","id":284282,"avatar_url":"https://avatars.githubusercontent.com/u/284282?v=3","gravatar_id":"","url":"https://api.github.com/users/platinumazure","html_url":"https://github.com/platinumazure","followers_url":"https://api.github.com/users/platinumazure/followers","following_url":"https://api.github.com/users/platinumazure/following{/other_user}","gists_url":"https://api.github.com/users/platinumazure/gists{/gist_id}","starred_url":"https://api.github.com/users/platinumazure/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/platinumazure/subscriptions","organizations_url":"https://api.github.com/users/platinumazure/orgs","repos_url":"https://api.github.com/users/platinumazure/repos","events_url":"https://api.github.com/users/platinumazure/events{/privacy}","received_events_url":"https://api.github.com/users/platinumazure/received_events","type":"User","site_admin":false},"created_at":"2016-08-26T14:28:23Z","updated_at":"2016-08-26T14:28:23Z","body":"Not sure if @alberto is referencing a return value object or an API on the parser itself-- I'll ask about the latter: Why not just allow parsers to export an `eslintServices` (or `lintServices`) object as well as `parse` and look for that?"}}
{"actor":{"display_login":"platinumazure"}}