{"action":"created","issue":{"url":"https://api.github.com/repos/prettier/prettier/issues/918","repository_url":"https://api.github.com/repos/prettier/prettier","labels_url":"https://api.github.com/repos/prettier/prettier/issues/918/labels{/name}","comments_url":"https://api.github.com/repos/prettier/prettier/issues/918/comments","events_url":"https://api.github.com/repos/prettier/prettier/issues/918/events","html_url":"https://github.com/prettier/prettier/issues/918","id":212200095,"number":918,"title":"[RFC] Editor Integration","user":{"login":"vjeux","id":197597,"avatar_url":"https://avatars3.githubusercontent.com/u/197597?v=3","gravatar_id":"","url":"https://api.github.com/users/vjeux","html_url":"https://github.com/vjeux","followers_url":"https://api.github.com/users/vjeux/followers","following_url":"https://api.github.com/users/vjeux/following{/other_user}","gists_url":"https://api.github.com/users/vjeux/gists{/gist_id}","starred_url":"https://api.github.com/users/vjeux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vjeux/subscriptions","organizations_url":"https://api.github.com/users/vjeux/orgs","repos_url":"https://api.github.com/users/vjeux/repos","events_url":"https://api.github.com/users/vjeux/events{/privacy}","received_events_url":"https://api.github.com/users/vjeux/received_events","type":"User","site_admin":false},"labels":[{"id":516128597,"url":"https://api.github.com/repos/prettier/prettier/labels/Needs%20discussion","name":"Needs discussion","color":"0052cc","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2017-03-06T17:53:49Z","updated_at":"2017-03-25T09:00:09Z","closed_at":null,"body":"Editors are the main place where we want people to use prettier, in order for it to be a great experience it should have the following properties:\r\n\r\n- Use the version of prettier that the project uses. If not, fall back to an arbitrary version.\r\n- When saving, use the options specified by the project, otherwise fall back to an arbitrary configuration.\r\n- When reading a file that is inside of a project using prettier, and if an option is enabled, reformat the code using the local user preferences.\r\n\r\n## Proposal\r\n\r\nAllow people adding their configuration options inside of prettier in `package.json`:\r\n\r\n```js\r\n{\r\n  ...\r\n\r\n  \"prettier\": {\r\n    \"bracketSpacing\": false,\r\n    \"trailingComma\": \"all\"\r\n  }\r\n}\r\n```\r\n\r\n## How to find a package version of prettier?\r\n\r\nGiven a file with a path `a/b/c/d/e.js`, we want to crawl up the tree up until we find a file `package.json`.\r\n\r\nIt should check in this order:\r\n\r\n- `a/b/c/d/package.json`\r\n- `a/b/c/package.json`\r\n- `a/b/package.json`\r\n- `a/package.json`\r\n- `package.json`\r\n\r\nIf it doesn't find one, then the file isn't inside of a prettier repo.\r\n\r\nIf it finds one in `a/b/package.json`, then look at the file `a/b/node_modules/.bin/prettier`. If it finds one, then use this prettier binary.\r\n\r\n## How to deal with caching?\r\n\r\nThis is a fair amount of io to be done for each invocation. If you want to add caching, you want to be careful, here are the things to watch out for:\r\n\r\n- `a/b/package.json` is updated\r\n- `a/b/node_modules/.bin/prettier` is updated\r\n- `a/b/c/package.json` or `a/b/c/d/package.json` is created\r\n\r\n## How to find the configuration associated to a package version of prettier?\r\n\r\nGiven that a package version of prettier is always in `a/b/node_modules/.bin/prettier` and the package configuration is always in `a/b/package.json`, we can inside of prettier check if `../../package.json` exists, and if it does read it and use the prettier key.\r\n\r\nIf prettier is being used as a CLI with `require('prettier')`, I'm not sure how to find it and if it's even a good idea to.\r\n\r\n## How do you resolve conflicting rules?\r\n\r\nI suggest that we merge rules one by one and the order they are loaded in/override each other is:\r\n- First load `package.json` rules\r\n- Then load CLI arguments which override the one above\r\n\r\nFor example,\r\n\r\n```js\r\n// package.json\r\n{ \"prettier\": {\"trailingComma\": \"all\", \"singleQuote\": true} }\r\n```\r\n\r\n```js\r\nprettier --trailing-comma es5 --parser flow\r\n```\r\n\r\nwould result in\r\n\r\n```js\r\n{singleQuote: true, trailingComma: 'es5', parser: 'flow'}\r\n```\r\n\r\n## How to make it fast?\r\n\r\nBecause all the integrations now have to use the cli and can no longer just use the local require version, we're going to pay js/node startup time on every single invocation.\r\n\r\nI recommend adding an option to prettier bin `--json-rpc`. With this, you can open the prettier process once and send formatting commands through stdin/stdout without having to restart it every time.\r\n\r\nA sample connection looks like this:\r\n\r\n```js\r\n-->\r\nContent Length: xxx\r\n{\"jsonrpc\": \"2.0\", \"method\": \"format\", \"params\": [\"abc\", {\"trailingComma\": \"es6\"}], \"id\": 1}\r\n\r\n<--\r\nContent Length: xxx\r\n{\"jsonrpc\": \"2.0\", \"result\": {\"formatted\": \"abc;\", \"error\": null}, \"id\": 1}\r\n```\r\n\r\n## Conclusion\r\n\r\nLet me know what you think :)"},"comment":{"url":"https://api.github.com/repos/prettier/prettier/issues/comments/289199162","html_url":"https://github.com/prettier/prettier/issues/918#issuecomment-289199162","issue_url":"https://api.github.com/repos/prettier/prettier/issues/918","id":289199162,"user":{"login":"bakkot","id":1653598,"avatar_url":"https://avatars1.githubusercontent.com/u/1653598?v=3","gravatar_id":"","url":"https://api.github.com/users/bakkot","html_url":"https://github.com/bakkot","followers_url":"https://api.github.com/users/bakkot/followers","following_url":"https://api.github.com/users/bakkot/following{/other_user}","gists_url":"https://api.github.com/users/bakkot/gists{/gist_id}","starred_url":"https://api.github.com/users/bakkot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bakkot/subscriptions","organizations_url":"https://api.github.com/users/bakkot/orgs","repos_url":"https://api.github.com/users/bakkot/repos","events_url":"https://api.github.com/users/bakkot/events{/privacy}","received_events_url":"https://api.github.com/users/bakkot/received_events","type":"User","site_admin":false},"created_at":"2017-03-25T09:00:09Z","updated_at":"2017-03-25T09:00:09Z","body":"Most JS I write does not live in an npm package, so this would do nothing for me.\r\n\r\nI know that's kind of unusual, but I thought it worth mentioning - package.json is an npm thing, not a JS thing."}}
{"actor":{"display_login":"bakkot"}}