Fix comment in abstract methods (#12185)

This commit is contained in:
Lucas Duailibe authored and GitHub committed 2022-01-29 19:25:53 -03:00
1 parent e3efd11401
commit 72ac2bbe5f
5 files changed
+78

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
#### Fix misplaced argument comment in abstract methods (#12185 by @duailibe)
<!-- prettier-ignore -->
```ts
// Input
abstract class Foo {
abstract bar(
/** comment explaining userId param */
userId
)
}
// Prettier stable
abstract class Foo {
abstract bar(userId);
/** comment explaining userId param */
}
// Prettier main
abstract class Foo {
abstract bar(
/** comment explaining userId param */
userId
);
}
```
+1
View File
@@ -459,6 +459,7 @@ function handleMethodNameComments({
if (
enclosingNode &&
precedingNode &&
getNextNonSpaceNonCommentCharacter(text, comment, locEnd) === "(" &&
// "MethodDefinition" is handled in getCommentChildNodes
(enclosingNode.type === "Property" ||
enclosingNode.type === "TSDeclareMethod" ||
@@ -28,6 +28,40 @@ abstract class AbstractRule {
================================================================================
`;
exports[`abstract_methods.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
| printWidth
=====================================input======================================
abstract class AbstractFoo {
abstract method1(/* comment */ arg: string);
abstract method2(
/* comment */
arg: string
);
abstract method3(
// comment
arg: string
);
}
=====================================output=====================================
abstract class AbstractFoo {
abstract method1(/* comment */ arg: string);
abstract method2(
/* comment */
arg: string
);
abstract method3(
// comment
arg: string
);
}
================================================================================
`;
exports[`after_jsx_generic.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
@@ -602,6 +636,8 @@ export class Point {
mismatchedIndentation() {}
inline /* foo*/ (/* bar */) /* baz */ {}
noBody(/* comment */ arg);
}
=====================================output=====================================
@@ -651,6 +687,8 @@ export class Point {
mismatchedIndentation() {}
inline /* foo*/(/* bar */) /* baz */ {}
noBody(/* comment */ arg);
}
================================================================================
@@ -0,0 +1,11 @@
abstract class AbstractFoo {
abstract method1(/* comment */ arg: string);
abstract method2(
/* comment */
arg: string
);
abstract method3(
// comment
arg: string
);
}
@@ -44,4 +44,6 @@ export class Point {
mismatchedIndentation() {}
inline /* foo*/ (/* bar */) /* baz */ {}
noBody(/* comment */ arg);
}