{"action":"created","comment":{"url":"https://api.github.com/repos/eslint/eslint/pulls/comments/96343495","pull_request_review_id":16921273,"id":96343495,"diff_hunk":"@@ -0,0 +1,259 @@\n+/**\n+ * @fileoverview Tests for template-tag-spacing rule.\n+ * @author Jonathan Wilsson\n+ */\n+\n+\"use strict\";\n+\n+//------------------------------------------------------------------------------\n+// Requirements\n+//------------------------------------------------------------------------------\n+\n+const rule = require(\"../../../lib/rules/template-tag-spacing\"),\n+    RuleTester = require(\"../../../lib/testers/rule-tester\");\n+\n+//------------------------------------------------------------------------------\n+// Tests\n+//------------------------------------------------------------------------------\n+\n+const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } });\n+\n+ruleTester.run(\"template-tag-spacing\", rule, {\n+    valid: [\n+        \"tag`name`\",\n+        { code: \"tag`name`\", options: [\"never\"] },\n+        { code: \"tag `name`\", options: [\"always\"] },\n+        \"tag`hello ${name}`\",\n+        { code: \"tag`hello ${name}`\", options: [\"never\"] },\n+        { code: \"tag `hello ${name}`\", options: [\"always\"] },\n+        \"tag/*here's a comment*/`Hello world`\",\n+        { code: \"tag/*here's a comment*/`Hello world`\", options: [\"never\"] },\n+        { code: \"tag /*here's a comment*/`Hello world`\", options: [\"always\"] },\n+        { code: \"tag/*here's a comment*/ `Hello world`\", options: [\"always\"] },\n+        \"new tag`name`\",\n+        { code: \"new tag`name`\", options: [\"never\"] },\n+        { code: \"new tag `name`\", options: [\"always\"] },\n+        \"new tag`hello ${name}`\",\n+        { code: \"new tag`hello ${name}`\", options: [\"never\"] },\n+        { code: \"new tag `hello ${name}`\", options: [\"always\"] },\n+        \"(tag)`name`\",\n+        { code: \"(tag)`name`\", options: [\"never\"] },\n+        { code: \"(tag) `name`\", options: [\"always\"] },\n+        \"(tag)`hello ${name}`\",\n+        { code: \"(tag)`hello ${name}`\", options: [\"never\"] },\n+        { code: \"(tag) `hello ${name}`\", options: [\"always\"] },\n+        \"new (tag)`name`\",\n+        { code: \"new (tag)`name`\", options: [\"never\"] },\n+        { code: \"new (tag) `name`\", options: [\"always\"] },\n+        \"new (tag)`hello ${name}`\",\n+        { code: \"new (tag)`hello ${name}`\", options: [\"never\"] },\n+        { code: \"new (tag) `hello ${name}`\", options: [\"always\"] }\n+    ],\n+    invalid: [\n+        {\n+            code: \"tag `name`\",\n+            output: \"tag`name`\",\n+            errors: [\n+                { message: \"Unexpected space between template tag and template literal.\" }\n+            ]\n+        },\n+        {\n+            code: \"tag `name`\",\n+            output: \"tag`name`\",\n+            errors: [\n+                { message: \"Unexpected space between template tag and template literal.\" }\n+            ],\n+            options: [\"never\"]\n+        },\n+        {\n+            code: \"tag`name`\",\n+            output: \"tag `name`\",\n+            errors: [\n+                { message: \"Missing space between template tag and template literal.\" }\n+            ],\n+            options: [\"always\"]\n+        },\n+        {\n+            code: \"tag /*here's a comment*/`Hello world`\",","path":"tests/lib/rules/template-tag-spacing.js","position":77,"original_position":77,"commit_id":"9e1da1cd1394a4f0fff3ca5970b2838c8987ef1a","original_commit_id":"9e1da1cd1394a4f0fff3ca5970b2838c8987ef1a","user":{"login":"not-an-aardvark","id":11638619,"avatar_url":"https://avatars.githubusercontent.com/u/11638619?v=3","gravatar_id":"","url":"https://api.github.com/users/not-an-aardvark","html_url":"https://github.com/not-an-aardvark","followers_url":"https://api.github.com/users/not-an-aardvark/followers","following_url":"https://api.github.com/users/not-an-aardvark/following{/other_user}","gists_url":"https://api.github.com/users/not-an-aardvark/gists{/gist_id}","starred_url":"https://api.github.com/users/not-an-aardvark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/not-an-aardvark/subscriptions","organizations_url":"https://api.github.com/users/not-an-aardvark/orgs","repos_url":"https://api.github.com/users/not-an-aardvark/repos","events_url":"https://api.github.com/users/not-an-aardvark/events{/privacy}","received_events_url":"https://api.github.com/users/not-an-aardvark/received_events","type":"User","site_admin":false},"body":"I think the best way to fix this would be to get a list of all the comments between the tag and the template literal, then concatenate them to get the resulting text between the two tokens. This would preserve the whitespace in the comments themselves and remove any other whitespace.\r\n\r\nHowever, we should make sure we don't change the behavior of this code:\r\n\r\n```js\r\nfoo // line comment\r\n`bar`\r\n```\r\n\r\nThe implementation I mentioned above would fix that to\r\n\r\n```js\r\nfoo// line comment`bar`\r\n```\r\n\r\nTo avoid this, I think we should avoid doing a fix if there are any line comments between the tag and the template literal.\r\n\r\nSo I would do something along the lines of\r\n\r\n```js\r\ncontext.report({\r\n  // ...\r\n  fix(fixer) {\r\n    const comments = sourceCode.getComments(node.quasi).leading;\r\n\r\n    if (comments.some(comment => comment.type === \"Line\")) {\r\n        return null;\r\n    }\r\n    return fixer.replaceTextRange(\r\n        [tagToken.range[1], literalToken.range[0]],\r\n        comments.reduce((text, comment) => text + sourceCode.getText(comment), \"\")\r\n    );\r\n  }\r\n});\r\n```","created_at":"2017-01-17T04:44:44Z","updated_at":"2017-01-17T04:44:44Z","html_url":"https://github.com/eslint/eslint/pull/7913#discussion_r96343495","pull_request_url":"https://api.github.com/repos/eslint/eslint/pulls/7913","_links":{"self":{"href":"https://api.github.com/repos/eslint/eslint/pulls/comments/96343495"},"html":{"href":"https://github.com/eslint/eslint/pull/7913#discussion_r96343495"},"pull_request":{"href":"https://api.github.com/repos/eslint/eslint/pulls/7913"}}},"pull_request":{"url":"https://api.github.com/repos/eslint/eslint/pulls/7913","id":101336513,"html_url":"https://github.com/eslint/eslint/pull/7913","diff_url":"https://github.com/eslint/eslint/pull/7913.diff","patch_url":"https://github.com/eslint/eslint/pull/7913.patch","issue_url":"https://api.github.com/repos/eslint/eslint/issues/7913","number":7913,"state":"open","locked":false,"title":"New: `template-tag-spacing` rule (fixes #7631)","user":{"login":"jwilsson","id":567607,"avatar_url":"https://avatars.githubusercontent.com/u/567607?v=3","gravatar_id":"","url":"https://api.github.com/users/jwilsson","html_url":"https://github.com/jwilsson","followers_url":"https://api.github.com/users/jwilsson/followers","following_url":"https://api.github.com/users/jwilsson/following{/other_user}","gists_url":"https://api.github.com/users/jwilsson/gists{/gist_id}","starred_url":"https://api.github.com/users/jwilsson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwilsson/subscriptions","organizations_url":"https://api.github.com/users/jwilsson/orgs","repos_url":"https://api.github.com/users/jwilsson/repos","events_url":"https://api.github.com/users/jwilsson/events{/privacy}","received_events_url":"https://api.github.com/users/jwilsson/received_events","type":"User","site_admin":false},"body":"**What is the purpose of this pull request? (put an \"X\" next to item)**\r\n\r\n[ ] Documentation update\r\n[ ] Bug fix ([template](https://raw.githubusercontent.com/eslint/eslint/master/templates/bug-report.md))\r\n[ X ] New rule ([template](https://raw.githubusercontent.com/eslint/eslint/master/templates/rule-proposal.md))\r\n[ ] Changes an existing rule ([template](https://raw.githubusercontent.com/eslint/eslint/master/templates/rule-change-proposal.md))\r\n[ ] Add autofixing to a rule\r\n[ ] Add a CLI option\r\n[ ] Add something to the core\r\n[ ] Other, please explain:\r\n\r\n**Please describe what the rule should do:**\r\nThis rule is very similiar to `func-call-spacing` in the way it will enforce spacing between [template tags](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_template_literals) and their corresponding template literal.\r\n\r\n**What category of rule is this? (place an \"X\" next to just one item)**\r\n\r\n[ X ] Enforces code style\r\n[ ] Warns about a potential error\r\n[ ] Suggests an alternate way of doing something\r\n[ ] Other (please specify:)\r\n\r\n**Provide 2-3 code examples that this rule will warn about:**\r\n\r\n```js\r\n/* eslint template-tag-spacing: [\"error\", \"never\"] */\r\nfunc `foo`\r\n```\r\n\r\n```js\r\n/* eslint template-tag-spacing: [\"error\", \"always\"] */\r\nfunc`foo`\r\n```\r\n\r\n**Why should this rule be included in ESLint (instead of a plugin)?**\r\nSince it's really similar to `func-call-spacing` which is already included in ESLint it makes sense to enforce this styling too, especially since tagged template literals will become more and more common.","created_at":"2017-01-12T20:44:02Z","updated_at":"2017-01-17T04:44:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"65ac1287d5b1944246a3f902d06d58694c057e6a","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/eslint/eslint/pulls/7913/commits","review_comments_url":"https://api.github.com/repos/eslint/eslint/pulls/7913/comments","review_comment_url":"https://api.github.com/repos/eslint/eslint/pulls/comments{/number}","comments_url":"https://api.github.com/repos/eslint/eslint/issues/7913/comments","statuses_url":"https://api.github.com/repos/eslint/eslint/statuses/9e1da1cd1394a4f0fff3ca5970b2838c8987ef1a","head":{"label":"jwilsson:issue7631","ref":"issue7631","sha":"9e1da1cd1394a4f0fff3ca5970b2838c8987ef1a","user":{"login":"jwilsson","id":567607,"avatar_url":"https://avatars.githubusercontent.com/u/567607?v=3","gravatar_id":"","url":"https://api.github.com/users/jwilsson","html_url":"https://github.com/jwilsson","followers_url":"https://api.github.com/users/jwilsson/followers","following_url":"https://api.github.com/users/jwilsson/following{/other_user}","gists_url":"https://api.github.com/users/jwilsson/gists{/gist_id}","starred_url":"https://api.github.com/users/jwilsson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwilsson/subscriptions","organizations_url":"https://api.github.com/users/jwilsson/orgs","repos_url":"https://api.github.com/users/jwilsson/repos","events_url":"https://api.github.com/users/jwilsson/events{/privacy}","received_events_url":"https://api.github.com/users/jwilsson/received_events","type":"User","site_admin":false},"repo":{"id":78778685,"name":"eslint","full_name":"jwilsson/eslint","owner":{"login":"jwilsson","id":567607,"avatar_url":"https://avatars.githubusercontent.com/u/567607?v=3","gravatar_id":"","url":"https://api.github.com/users/jwilsson","html_url":"https://github.com/jwilsson","followers_url":"https://api.github.com/users/jwilsson/followers","following_url":"https://api.github.com/users/jwilsson/following{/other_user}","gists_url":"https://api.github.com/users/jwilsson/gists{/gist_id}","starred_url":"https://api.github.com/users/jwilsson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwilsson/subscriptions","organizations_url":"https://api.github.com/users/jwilsson/orgs","repos_url":"https://api.github.com/users/jwilsson/repos","events_url":"https://api.github.com/users/jwilsson/events{/privacy}","received_events_url":"https://api.github.com/users/jwilsson/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jwilsson/eslint","description":"A fully pluggable tool for identifying and reporting on patterns in JavaScript.","fork":true,"url":"https://api.github.com/repos/jwilsson/eslint","forks_url":"https://api.github.com/repos/jwilsson/eslint/forks","keys_url":"https://api.github.com/repos/jwilsson/eslint/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jwilsson/eslint/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jwilsson/eslint/teams","hooks_url":"https://api.github.com/repos/jwilsson/eslint/hooks","issue_events_url":"https://api.github.com/repos/jwilsson/eslint/issues/events{/number}","events_url":"https://api.github.com/repos/jwilsson/eslint/events","assignees_url":"https://api.github.com/repos/jwilsson/eslint/assignees{/user}","branches_url":"https://api.github.com/repos/jwilsson/eslint/branches{/branch}","tags_url":"https://api.github.com/repos/jwilsson/eslint/tags","blobs_url":"https://api.github.com/repos/jwilsson/eslint/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jwilsson/eslint/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jwilsson/eslint/git/refs{/sha}","trees_url":"https://api.github.com/repos/jwilsson/eslint/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jwilsson/eslint/statuses/{sha}","languages_url":"https://api.github.com/repos/jwilsson/eslint/languages","stargazers_url":"https://api.github.com/repos/jwilsson/eslint/stargazers","contributors_url":"https://api.github.com/repos/jwilsson/eslint/contributors","subscribers_url":"https://api.github.com/repos/jwilsson/eslint/subscribers","subscription_url":"https://api.github.com/repos/jwilsson/eslint/subscription","commits_url":"https://api.github.com/repos/jwilsson/eslint/commits{/sha}","git_commits_url":"https://api.github.com/repos/jwilsson/eslint/git/commits{/sha}","comments_url":"https://api.github.com/repos/jwilsson/eslint/comments{/number}","issue_comment_url":"https://api.github.com/repos/jwilsson/eslint/issues/comments{/number}","contents_url":"https://api.github.com/repos/jwilsson/eslint/contents/{+path}","compare_url":"https://api.github.com/repos/jwilsson/eslint/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jwilsson/eslint/merges","archive_url":"https://api.github.com/repos/jwilsson/eslint/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jwilsson/eslint/downloads","issues_url":"https://api.github.com/repos/jwilsson/eslint/issues{/number}","pulls_url":"https://api.github.com/repos/jwilsson/eslint/pulls{/number}","milestones_url":"https://api.github.com/repos/jwilsson/eslint/milestones{/number}","notifications_url":"https://api.github.com/repos/jwilsson/eslint/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jwilsson/eslint/labels{/name}","releases_url":"https://api.github.com/repos/jwilsson/eslint/releases{/id}","deployments_url":"https://api.github.com/repos/jwilsson/eslint/deployments","created_at":"2017-01-12T19:19:57Z","updated_at":"2017-01-12T19:20:07Z","pushed_at":"2017-01-16T17:39:26Z","git_url":"git://github.com/jwilsson/eslint.git","ssh_url":"git@github.com:jwilsson/eslint.git","clone_url":"https://github.com/jwilsson/eslint.git","svn_url":"https://github.com/jwilsson/eslint","homepage":"http://eslint.org","size":14341,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"eslint:master","ref":"master","sha":"7e04b33028e68555c69cf2568d606cdeab0b7cda","user":{"login":"eslint","id":6019716,"avatar_url":"https://avatars.githubusercontent.com/u/6019716?v=3","gravatar_id":"","url":"https://api.github.com/users/eslint","html_url":"https://github.com/eslint","followers_url":"https://api.github.com/users/eslint/followers","following_url":"https://api.github.com/users/eslint/following{/other_user}","gists_url":"https://api.github.com/users/eslint/gists{/gist_id}","starred_url":"https://api.github.com/users/eslint/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eslint/subscriptions","organizations_url":"https://api.github.com/users/eslint/orgs","repos_url":"https://api.github.com/users/eslint/repos","events_url":"https://api.github.com/users/eslint/events{/privacy}","received_events_url":"https://api.github.com/users/eslint/received_events","type":"Organization","site_admin":false},"repo":{"id":11061773,"name":"eslint","full_name":"eslint/eslint","owner":{"login":"eslint","id":6019716,"avatar_url":"https://avatars.githubusercontent.com/u/6019716?v=3","gravatar_id":"","url":"https://api.github.com/users/eslint","html_url":"https://github.com/eslint","followers_url":"https://api.github.com/users/eslint/followers","following_url":"https://api.github.com/users/eslint/following{/other_user}","gists_url":"https://api.github.com/users/eslint/gists{/gist_id}","starred_url":"https://api.github.com/users/eslint/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eslint/subscriptions","organizations_url":"https://api.github.com/users/eslint/orgs","repos_url":"https://api.github.com/users/eslint/repos","events_url":"https://api.github.com/users/eslint/events{/privacy}","received_events_url":"https://api.github.com/users/eslint/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/eslint/eslint","description":"A fully pluggable tool for identifying and reporting on patterns in JavaScript.","fork":false,"url":"https://api.github.com/repos/eslint/eslint","forks_url":"https://api.github.com/repos/eslint/eslint/forks","keys_url":"https://api.github.com/repos/eslint/eslint/keys{/key_id}","collaborators_url":"https://api.github.com/repos/eslint/eslint/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/eslint/eslint/teams","hooks_url":"https://api.github.com/repos/eslint/eslint/hooks","issue_events_url":"https://api.github.com/repos/eslint/eslint/issues/events{/number}","events_url":"https://api.github.com/repos/eslint/eslint/events","assignees_url":"https://api.github.com/repos/eslint/eslint/assignees{/user}","branches_url":"https://api.github.com/repos/eslint/eslint/branches{/branch}","tags_url":"https://api.github.com/repos/eslint/eslint/tags","blobs_url":"https://api.github.com/repos/eslint/eslint/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/eslint/eslint/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/eslint/eslint/git/refs{/sha}","trees_url":"https://api.github.com/repos/eslint/eslint/git/trees{/sha}","statuses_url":"https://api.github.com/repos/eslint/eslint/statuses/{sha}","languages_url":"https://api.github.com/repos/eslint/eslint/languages","stargazers_url":"https://api.github.com/repos/eslint/eslint/stargazers","contributors_url":"https://api.github.com/repos/eslint/eslint/contributors","subscribers_url":"https://api.github.com/repos/eslint/eslint/subscribers","subscription_url":"https://api.github.com/repos/eslint/eslint/subscription","commits_url":"https://api.github.com/repos/eslint/eslint/commits{/sha}","git_commits_url":"https://api.github.com/repos/eslint/eslint/git/commits{/sha}","comments_url":"https://api.github.com/repos/eslint/eslint/comments{/number}","issue_comment_url":"https://api.github.com/repos/eslint/eslint/issues/comments{/number}","contents_url":"https://api.github.com/repos/eslint/eslint/contents/{+path}","compare_url":"https://api.github.com/repos/eslint/eslint/compare/{base}...{head}","merges_url":"https://api.github.com/repos/eslint/eslint/merges","archive_url":"https://api.github.com/repos/eslint/eslint/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/eslint/eslint/downloads","issues_url":"https://api.github.com/repos/eslint/eslint/issues{/number}","pulls_url":"https://api.github.com/repos/eslint/eslint/pulls{/number}","milestones_url":"https://api.github.com/repos/eslint/eslint/milestones{/number}","notifications_url":"https://api.github.com/repos/eslint/eslint/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/eslint/eslint/labels{/name}","releases_url":"https://api.github.com/repos/eslint/eslint/releases{/id}","deployments_url":"https://api.github.com/repos/eslint/eslint/deployments","created_at":"2013-06-29T23:59:48Z","updated_at":"2017-01-17T02:12:18Z","pushed_at":"2017-01-17T04:44:44Z","git_url":"git://github.com/eslint/eslint.git","ssh_url":"git@github.com:eslint/eslint.git","clone_url":"https://github.com/eslint/eslint.git","svn_url":"https://github.com/eslint/eslint","homepage":"http://eslint.org","size":14407,"stargazers_count":6724,"watchers_count":6724,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1300,"mirror_url":null,"open_issues_count":219,"forks":1300,"open_issues":219,"watchers":6724,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/eslint/eslint/pulls/7913"},"html":{"href":"https://github.com/eslint/eslint/pull/7913"},"issue":{"href":"https://api.github.com/repos/eslint/eslint/issues/7913"},"comments":{"href":"https://api.github.com/repos/eslint/eslint/issues/7913/comments"},"review_comments":{"href":"https://api.github.com/repos/eslint/eslint/pulls/7913/comments"},"review_comment":{"href":"https://api.github.com/repos/eslint/eslint/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/eslint/eslint/pulls/7913/commits"},"statuses":{"href":"https://api.github.com/repos/eslint/eslint/statuses/9e1da1cd1394a4f0fff3ca5970b2838c8987ef1a"}}}}
{"actor":{"display_login":"not-an-aardvark"}}