Skip to content

Commit

Permalink
Fix: do not autofix object-shorthand with comments (fixes #10038) (#1…
Browse files Browse the repository at this point in the history
…0238)

* Fix: do not autofix object-shorthand with comments (fixes #10038)

* Fix: catch comments before and after colon (fixes 10038)
  • Loading branch information
malcolmsgroves authored and not-an-aardvark committed Apr 27, 2018
1 parent 4672b56 commit f9c7371
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rules/object-shorthand.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ module.exports = {
const keyText = sourceCode.text.slice(firstKeyToken.range[0], lastKeyToken.range[1]);
let keyPrefix = "";

if (sourceCode.commentsExistBetween(lastKeyToken, node.value)) {
return null;
}

if (node.value.async) {
keyPrefix += "async ";
}
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/rules/object-shorthand.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,16 @@ ruleTester.run("object-shorthand", rule, {
output: "var x = {\n *f() {\n /* comment */\n a(b);\n }\n }",
errors: [METHOD_ERROR]
},
{
code: "var x = {\n f: /* comment */ function() {\n }\n }",
output: null,
errors: [METHOD_ERROR]
},
{
code: "var x = {\n f /* comment */: function() {\n }\n }",
output: null,
errors: [METHOD_ERROR]
},
{
code: "var x = {y: function() {}}",
output: "var x = {y() {}}",
Expand Down

0 comments on commit f9c7371

Please sign in to comment.