From 16ed595086f8bfa720abdd9aafe4f32ece0d4f52 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Fri, 17 Mar 2017 11:00:01 -0700 Subject: [PATCH] Preserve comment position for last arg or method (#1025) In #856, it handled a bunch of cases but missed class methods Fixes #905 --- src/comments.js | 3 +- .../comments/__snapshots__/jsfmt.spec.js.snap | 28 +++++++++++++++++++ tests/comments/last-arg.js | 7 +++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/comments.js b/src/comments.js index 2873caaf..101044ea 100644 --- a/src/comments.js +++ b/src/comments.js @@ -519,7 +519,8 @@ function handleLastFunctionArgComments( precedingNode.type === "Identifier" && enclosingNode && (enclosingNode.type === "ArrowFunctionExpression" || - enclosingNode.type === "FunctionExpression") && + enclosingNode.type === "FunctionExpression" || + enclosingNode.type === "ClassMethod") && followingNode && followingNode.type !== "Identifier" ) { diff --git a/tests/comments/__snapshots__/jsfmt.spec.js.snap b/tests/comments/__snapshots__/jsfmt.spec.js.snap index 62a5da09..9dea2739 100644 --- a/tests/comments/__snapshots__/jsfmt.spec.js.snap +++ b/tests/comments/__snapshots__/jsfmt.spec.js.snap @@ -1246,6 +1246,13 @@ f = function( currentRequest: {a: number}, // TODO this is a very very very very long comment that makes it go > 80 columns ) {}; + +class X { + f( + currentRequest: {a: number}, + // TODO this is a very very very very long comment that makes it go > 80 columns + ) {} +} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ type f = ( currentRequest: { a: number } @@ -1266,6 +1273,13 @@ f = function( currentRequest: { a: number } // TODO this is a very very very very long comment that makes it go > 80 columns ) {}; + +class X { + f( + currentRequest: { a: number } + // TODO this is a very very very very long comment that makes it go > 80 columns + ) {} +} " `; @@ -1289,6 +1303,13 @@ f = function( currentRequest: {a: number}, // TODO this is a very very very very long comment that makes it go > 80 columns ) {}; + +class X { + f( + currentRequest: {a: number}, + // TODO this is a very very very very long comment that makes it go > 80 columns + ) {} +} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ type f = ( currentRequest: { a: number } @@ -1309,6 +1330,13 @@ f = function( currentRequest: { a: number } // TODO this is a very very very very long comment that makes it go > 80 columns ) {}; + +class X { + f( + currentRequest: { a: number } + // TODO this is a very very very very long comment that makes it go > 80 columns + ) {} +} " `; diff --git a/tests/comments/last-arg.js b/tests/comments/last-arg.js index 5a82baef..865da046 100644 --- a/tests/comments/last-arg.js +++ b/tests/comments/last-arg.js @@ -17,3 +17,10 @@ f = function( currentRequest: {a: number}, // TODO this is a very very very very long comment that makes it go > 80 columns ) {}; + +class X { + f( + currentRequest: {a: number}, + // TODO this is a very very very very long comment that makes it go > 80 columns + ) {} +}