{"action":"created","comment":{"url":"https://api.github.com/repos/xojs/xo/pulls/comments/204617226","pull_request_review_id":139727239,"id":204617226,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwNDYxNzIyNg==","diff_hunk":"@@ -114,6 +114,20 @@ updateNotifier({pkg: cli.pkg}).notify();\n \n const {input, flags: opts} = cli;\n \n+// Make data types for `opts.space` match those of the API\n+if (typeof opts.space === 'string') {\n+\tif (/^\\d$/.test(opts.space)) {","path":"main.js","position":6,"original_position":6,"commit_id":"56bc0dec7c235238f6e0aa480b40aad2dbfda295","original_commit_id":"56bc0dec7c235238f6e0aa480b40aad2dbfda295","user":{"login":"pvdlg","id":3250552,"node_id":"MDQ6VXNlcjMyNTA1NTI=","avatar_url":"https://avatars0.githubusercontent.com/u/3250552?v=4","gravatar_id":"","url":"https://api.github.com/users/pvdlg","html_url":"https://github.com/pvdlg","followers_url":"https://api.github.com/users/pvdlg/followers","following_url":"https://api.github.com/users/pvdlg/following{/other_user}","gists_url":"https://api.github.com/users/pvdlg/gists{/gist_id}","starred_url":"https://api.github.com/users/pvdlg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pvdlg/subscriptions","organizations_url":"https://api.github.com/users/pvdlg/orgs","repos_url":"https://api.github.com/users/pvdlg/repos","events_url":"https://api.github.com/users/pvdlg/events{/privacy}","received_events_url":"https://api.github.com/users/pvdlg/received_events","type":"User","site_admin":false},"body":"I didn't see this comment. The problem if we drop the `+` is that `xo --space 10` will be considered as trying to lint the file `10`. I'm not sure this is what we want. @sindresorhus did you considered that case?","created_at":"2018-07-24T03:56:46Z","updated_at":"2018-07-24T03:56:46Z","html_url":"https://github.com/xojs/xo/pull/342#discussion_r204617226","pull_request_url":"https://api.github.com/repos/xojs/xo/pulls/342","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/xojs/xo/pulls/comments/204617226"},"html":{"href":"https://github.com/xojs/xo/pull/342#discussion_r204617226"},"pull_request":{"href":"https://api.github.com/repos/xojs/xo/pulls/342"}},"in_reply_to_id":204603031},"pull_request":{"url":"https://api.github.com/repos/xojs/xo/pulls/342","id":203145361,"node_id":"MDExOlB1bGxSZXF1ZXN0MjAzMTQ1MzYx","html_url":"https://github.com/xojs/xo/pull/342","diff_url":"https://github.com/xojs/xo/pull/342.diff","patch_url":"https://github.com/xojs/xo/pull/342.patch","issue_url":"https://api.github.com/repos/xojs/xo/issues/342","number":342,"state":"open","locked":false,"title":"Fix CLI's `--space` option parsing","user":{"login":"noahbrenner","id":24858379,"node_id":"MDQ6VXNlcjI0ODU4Mzc5","avatar_url":"https://avatars3.githubusercontent.com/u/24858379?v=4","gravatar_id":"","url":"https://api.github.com/users/noahbrenner","html_url":"https://github.com/noahbrenner","followers_url":"https://api.github.com/users/noahbrenner/followers","following_url":"https://api.github.com/users/noahbrenner/following{/other_user}","gists_url":"https://api.github.com/users/noahbrenner/gists{/gist_id}","starred_url":"https://api.github.com/users/noahbrenner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/noahbrenner/subscriptions","organizations_url":"https://api.github.com/users/noahbrenner/orgs","repos_url":"https://api.github.com/users/noahbrenner/repos","events_url":"https://api.github.com/users/noahbrenner/events{/privacy}","received_events_url":"https://api.github.com/users/noahbrenner/received_events","type":"User","site_admin":false},"body":"Overview\r\n========\r\n\r\nEnsure that the `space` value, if present, is either a number or a boolean before passing it to the main API.  The space option is intended to act as either a boolean or a number option, but it is implemented as a string option out of necessity, which led to a few bugs.\r\n\r\nBugs fixed\r\n----------\r\n\r\nHere are the results of several invocations before and after applying this PR:\r\n\r\n### `xo --space=4`\r\n\r\n#### Before fix:\r\n* Expect 2-space indents.\r\n  * The value of `space` is the *string* `'4'`.\r\n  * The value is truthy, resulting in the space option being activated.\r\n  * The value is not a number, resulting in the default of 2 being used.\r\n\r\n#### Now:\r\n* Expect 4-space indents.\r\n  * The value of `space` is the *number* `4`.\r\n\r\n### `xo --space file.js`\r\n\r\n#### Before fix:\r\n* Check all files in the CWD and expect 2-space indents.\r\n  * The value of `space` is `'file.js'`.\r\n  * The value is truthy and not a number, so expect 2-space indents.\r\n  * There are no recognized positional recognized, so check all files.\r\n    - This is a subtle bug, since the desired file *is* usually checked, it's just not checked exclusively.\r\n\r\n#### Now:\r\n* Check only `file.js` and expect 2-space indents.\r\n\r\n### `xo --space`\r\n\r\n#### Before fix:\r\n* Expect tab indents.\r\n  * The value of `space` is the empty string.\r\n  * The value is falsey, so it is not used, instead defaulting to tabs.\r\n\r\n#### Now:\r\n* Expect 2-space indents.\r\n\r\nEdge cases\r\n----------\r\n\r\nThese are some quirks that are still present after this PR.  Some of them may actually be desired, depending on your viewpoint, others perhaps less so.  Let me know if there are any that you would like me to address.\r\n\r\n* `xo --space=false`: `'false'` is treated as a file name and 2-space indents are expected.  It is similar for `--space=true`.\r\n* `xo --space=3.0`: `'3.0'` is treated as a file name and 2-space indents are expected.  The implementation in this PR only recognizes numbers if they contain nothing but digits. This also applies to negative numbers (no `-` allowed).\r\n* The radix is always treated as `10`, even with leading `0`s.\r\n* `xo --space=0`: Tabs will be expected, since the value is falsey.\r\n* There is no check against `Number.MAX_SAFE_INTEGER`, so weird rounding and overflow can happen if someone wants the worst indent ever.\r\n* `xo --space=4 --no-space`: This results in an array of `['4', false]`, so `space` will be truthy, 2-space indents will be expected, and this array will be passed to the main API as if it were a positional argument.\r\n* Since non-number values of `space` are now assumed to be file names (or globs), it is possible to specify a filename before the end of the command line options: `xo --space file.js --quiet another.js`.\r\n\r\nReferences\r\n----------\r\n\r\nSome relevant lines elsewhere in the code base:\r\n\r\n* Whether to expect tabs or spaces is [based on the truthiness of the space option](https://github.com/xojs/xo/blob/master/lib/options-manager.js#L152), not just its *presence*.\r\n* Setting the number of spaces to something other than the default of 2 [depends on the value being a number](https://github.com/xojs/xo/blob/master/lib/options-manager.js#L127) (not a string, for example).\r\n\r\nCloses #339\r\nPossibly relevant to #212 when specifying a file directly after `--space`","created_at":"2018-07-23T08:33:45Z","updated_at":"2018-07-24T03:56:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"17798c2c07f75788f20120fe16c2cab2307cf350","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/xojs/xo/pulls/342/commits","review_comments_url":"https://api.github.com/repos/xojs/xo/pulls/342/comments","review_comment_url":"https://api.github.com/repos/xojs/xo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/xojs/xo/issues/342/comments","statuses_url":"https://api.github.com/repos/xojs/xo/statuses/56bc0dec7c235238f6e0aa480b40aad2dbfda295","head":{"label":"noahbrenner:space-parsing","ref":"space-parsing","sha":"56bc0dec7c235238f6e0aa480b40aad2dbfda295","user":{"login":"noahbrenner","id":24858379,"node_id":"MDQ6VXNlcjI0ODU4Mzc5","avatar_url":"https://avatars3.githubusercontent.com/u/24858379?v=4","gravatar_id":"","url":"https://api.github.com/users/noahbrenner","html_url":"https://github.com/noahbrenner","followers_url":"https://api.github.com/users/noahbrenner/followers","following_url":"https://api.github.com/users/noahbrenner/following{/other_user}","gists_url":"https://api.github.com/users/noahbrenner/gists{/gist_id}","starred_url":"https://api.github.com/users/noahbrenner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/noahbrenner/subscriptions","organizations_url":"https://api.github.com/users/noahbrenner/orgs","repos_url":"https://api.github.com/users/noahbrenner/repos","events_url":"https://api.github.com/users/noahbrenner/events{/privacy}","received_events_url":"https://api.github.com/users/noahbrenner/received_events","type":"User","site_admin":false},"repo":{"id":141320007,"node_id":"MDEwOlJlcG9zaXRvcnkxNDEzMjAwMDc=","name":"xo","full_name":"noahbrenner/xo","owner":{"login":"noahbrenner","id":24858379,"node_id":"MDQ6VXNlcjI0ODU4Mzc5","avatar_url":"https://avatars3.githubusercontent.com/u/24858379?v=4","gravatar_id":"","url":"https://api.github.com/users/noahbrenner","html_url":"https://github.com/noahbrenner","followers_url":"https://api.github.com/users/noahbrenner/followers","following_url":"https://api.github.com/users/noahbrenner/following{/other_user}","gists_url":"https://api.github.com/users/noahbrenner/gists{/gist_id}","starred_url":"https://api.github.com/users/noahbrenner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/noahbrenner/subscriptions","organizations_url":"https://api.github.com/users/noahbrenner/orgs","repos_url":"https://api.github.com/users/noahbrenner/repos","events_url":"https://api.github.com/users/noahbrenner/events{/privacy}","received_events_url":"https://api.github.com/users/noahbrenner/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/noahbrenner/xo","description":"❤️ JavaScript happiness style linter","fork":true,"url":"https://api.github.com/repos/noahbrenner/xo","forks_url":"https://api.github.com/repos/noahbrenner/xo/forks","keys_url":"https://api.github.com/repos/noahbrenner/xo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/noahbrenner/xo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/noahbrenner/xo/teams","hooks_url":"https://api.github.com/repos/noahbrenner/xo/hooks","issue_events_url":"https://api.github.com/repos/noahbrenner/xo/issues/events{/number}","events_url":"https://api.github.com/repos/noahbrenner/xo/events","assignees_url":"https://api.github.com/repos/noahbrenner/xo/assignees{/user}","branches_url":"https://api.github.com/repos/noahbrenner/xo/branches{/branch}","tags_url":"https://api.github.com/repos/noahbrenner/xo/tags","blobs_url":"https://api.github.com/repos/noahbrenner/xo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/noahbrenner/xo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/noahbrenner/xo/git/refs{/sha}","trees_url":"https://api.github.com/repos/noahbrenner/xo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/noahbrenner/xo/statuses/{sha}","languages_url":"https://api.github.com/repos/noahbrenner/xo/languages","stargazers_url":"https://api.github.com/repos/noahbrenner/xo/stargazers","contributors_url":"https://api.github.com/repos/noahbrenner/xo/contributors","subscribers_url":"https://api.github.com/repos/noahbrenner/xo/subscribers","subscription_url":"https://api.github.com/repos/noahbrenner/xo/subscription","commits_url":"https://api.github.com/repos/noahbrenner/xo/commits{/sha}","git_commits_url":"https://api.github.com/repos/noahbrenner/xo/git/commits{/sha}","comments_url":"https://api.github.com/repos/noahbrenner/xo/comments{/number}","issue_comment_url":"https://api.github.com/repos/noahbrenner/xo/issues/comments{/number}","contents_url":"https://api.github.com/repos/noahbrenner/xo/contents/{+path}","compare_url":"https://api.github.com/repos/noahbrenner/xo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/noahbrenner/xo/merges","archive_url":"https://api.github.com/repos/noahbrenner/xo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/noahbrenner/xo/downloads","issues_url":"https://api.github.com/repos/noahbrenner/xo/issues{/number}","pulls_url":"https://api.github.com/repos/noahbrenner/xo/pulls{/number}","milestones_url":"https://api.github.com/repos/noahbrenner/xo/milestones{/number}","notifications_url":"https://api.github.com/repos/noahbrenner/xo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/noahbrenner/xo/labels{/name}","releases_url":"https://api.github.com/repos/noahbrenner/xo/releases{/id}","deployments_url":"https://api.github.com/repos/noahbrenner/xo/deployments","created_at":"2018-07-17T17:08:05Z","updated_at":"2018-07-23T09:22:38Z","pushed_at":"2018-07-23T09:28:57Z","git_url":"git://github.com/noahbrenner/xo.git","ssh_url":"git@github.com:noahbrenner/xo.git","clone_url":"https://github.com/noahbrenner/xo.git","svn_url":"https://github.com/noahbrenner/xo","homepage":"","size":404,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"xojs:master","ref":"master","sha":"404d81ba415e89911856bf2fa3755ef1478ad36b","user":{"login":"xojs","id":12815325,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEyODE1MzI1","avatar_url":"https://avatars3.githubusercontent.com/u/12815325?v=4","gravatar_id":"","url":"https://api.github.com/users/xojs","html_url":"https://github.com/xojs","followers_url":"https://api.github.com/users/xojs/followers","following_url":"https://api.github.com/users/xojs/following{/other_user}","gists_url":"https://api.github.com/users/xojs/gists{/gist_id}","starred_url":"https://api.github.com/users/xojs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xojs/subscriptions","organizations_url":"https://api.github.com/users/xojs/orgs","repos_url":"https://api.github.com/users/xojs/repos","events_url":"https://api.github.com/users/xojs/events{/privacy}","received_events_url":"https://api.github.com/users/xojs/received_events","type":"Organization","site_admin":false},"repo":{"id":40053602,"node_id":"MDEwOlJlcG9zaXRvcnk0MDA1MzYwMg==","name":"xo","full_name":"xojs/xo","owner":{"login":"xojs","id":12815325,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEyODE1MzI1","avatar_url":"https://avatars3.githubusercontent.com/u/12815325?v=4","gravatar_id":"","url":"https://api.github.com/users/xojs","html_url":"https://github.com/xojs","followers_url":"https://api.github.com/users/xojs/followers","following_url":"https://api.github.com/users/xojs/following{/other_user}","gists_url":"https://api.github.com/users/xojs/gists{/gist_id}","starred_url":"https://api.github.com/users/xojs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xojs/subscriptions","organizations_url":"https://api.github.com/users/xojs/orgs","repos_url":"https://api.github.com/users/xojs/repos","events_url":"https://api.github.com/users/xojs/events{/privacy}","received_events_url":"https://api.github.com/users/xojs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/xojs/xo","description":"❤️ JavaScript happiness style linter","fork":false,"url":"https://api.github.com/repos/xojs/xo","forks_url":"https://api.github.com/repos/xojs/xo/forks","keys_url":"https://api.github.com/repos/xojs/xo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/xojs/xo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/xojs/xo/teams","hooks_url":"https://api.github.com/repos/xojs/xo/hooks","issue_events_url":"https://api.github.com/repos/xojs/xo/issues/events{/number}","events_url":"https://api.github.com/repos/xojs/xo/events","assignees_url":"https://api.github.com/repos/xojs/xo/assignees{/user}","branches_url":"https://api.github.com/repos/xojs/xo/branches{/branch}","tags_url":"https://api.github.com/repos/xojs/xo/tags","blobs_url":"https://api.github.com/repos/xojs/xo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/xojs/xo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/xojs/xo/git/refs{/sha}","trees_url":"https://api.github.com/repos/xojs/xo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/xojs/xo/statuses/{sha}","languages_url":"https://api.github.com/repos/xojs/xo/languages","stargazers_url":"https://api.github.com/repos/xojs/xo/stargazers","contributors_url":"https://api.github.com/repos/xojs/xo/contributors","subscribers_url":"https://api.github.com/repos/xojs/xo/subscribers","subscription_url":"https://api.github.com/repos/xojs/xo/subscription","commits_url":"https://api.github.com/repos/xojs/xo/commits{/sha}","git_commits_url":"https://api.github.com/repos/xojs/xo/git/commits{/sha}","comments_url":"https://api.github.com/repos/xojs/xo/comments{/number}","issue_comment_url":"https://api.github.com/repos/xojs/xo/issues/comments{/number}","contents_url":"https://api.github.com/repos/xojs/xo/contents/{+path}","compare_url":"https://api.github.com/repos/xojs/xo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/xojs/xo/merges","archive_url":"https://api.github.com/repos/xojs/xo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/xojs/xo/downloads","issues_url":"https://api.github.com/repos/xojs/xo/issues{/number}","pulls_url":"https://api.github.com/repos/xojs/xo/pulls{/number}","milestones_url":"https://api.github.com/repos/xojs/xo/milestones{/number}","notifications_url":"https://api.github.com/repos/xojs/xo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/xojs/xo/labels{/name}","releases_url":"https://api.github.com/repos/xojs/xo/releases{/id}","deployments_url":"https://api.github.com/repos/xojs/xo/deployments","created_at":"2015-08-01T16:57:19Z","updated_at":"2018-07-23T09:01:31Z","pushed_at":"2018-07-23T09:28:58Z","git_url":"git://github.com/xojs/xo.git","ssh_url":"git@github.com:xojs/xo.git","clone_url":"https://github.com/xojs/xo.git","svn_url":"https://github.com/xojs/xo","homepage":"","size":410,"stargazers_count":3899,"watchers_count":3899,"language":"JavaScript","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":174,"mirror_url":null,"archived":false,"open_issues_count":58,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":174,"open_issues":58,"watchers":3899,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/xojs/xo/pulls/342"},"html":{"href":"https://github.com/xojs/xo/pull/342"},"issue":{"href":"https://api.github.com/repos/xojs/xo/issues/342"},"comments":{"href":"https://api.github.com/repos/xojs/xo/issues/342/comments"},"review_comments":{"href":"https://api.github.com/repos/xojs/xo/pulls/342/comments"},"review_comment":{"href":"https://api.github.com/repos/xojs/xo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/xojs/xo/pulls/342/commits"},"statuses":{"href":"https://api.github.com/repos/xojs/xo/statuses/56bc0dec7c235238f6e0aa480b40aad2dbfda295"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"pvdlg"}}