Properly support member chains comments (#668)
When there is a comment right before the first `.`, we want to force break such that the comment is printed on its own line. Note: this needs to be based on-top of #667 as it always indent the first `.` Fixes #613
This commit is contained in:
1 parent
c4b83c7653
commit
ec6ffbe063
4 files changed
+42
-18
No files matched your search
+7
-2
@@ -2253,12 +2253,12 @@ function printMemberChain(path, options, print) {
|
||||
}
|
||||
|
||||
const printedGroups = groups.map(printGroup);
|
||||
|
||||
const oneLine = concat(printedGroups);
|
||||
const hasComment = groups.length >= 2 && groups[1][0].node.comments;
|
||||
|
||||
// If we only have a single `.`, we shouldn't do anything fancy and just
|
||||
// render everything concatenated together.
|
||||
if (groups.length <= 2) {
|
||||
if (groups.length <= 2 && !hasComment) {
|
||||
return group(oneLine);
|
||||
}
|
||||
|
||||
@@ -2268,6 +2268,11 @@ function printMemberChain(path, options, print) {
|
||||
printIndentedGroup(groups.slice(shouldMerge ? 2 : 1), hardline)
|
||||
]);
|
||||
|
||||
// If there's a comment, we don't want to print in one line.
|
||||
if (hasComment) {
|
||||
return group(expanded);
|
||||
}
|
||||
|
||||
// If any group but the last one has a hard line, we want to force expand
|
||||
// it. If the last group is a function it's okay to inline if it fits.
|
||||
if (printedGroups.slice(0, -1).some(willBreak)) {
|
||||
|
||||
@@ -364,14 +364,12 @@ export type BuckWebSocketMessage =
|
||||
};
|
||||
|
||||
// Missing one level of indentation because of the comment
|
||||
const rootEpic = (actions, store) => combineEpics(...epics)(
|
||||
actions,
|
||||
store
|
||||
)// Log errors and continue.
|
||||
.catch((err, stream) => {
|
||||
getLogger().error(err);
|
||||
return stream;
|
||||
});
|
||||
const rootEpic = (actions, store) => combineEpics(...epics)(actions, store)
|
||||
// Log errors and continue.
|
||||
.catch((err, stream) => {
|
||||
getLogger().error(err);
|
||||
return stream;
|
||||
});
|
||||
|
||||
// Two extra levels of indentation because of the comment
|
||||
export type AsyncExecuteOptions =
|
||||
@@ -593,14 +591,12 @@ export type BuckWebSocketMessage =
|
||||
};
|
||||
|
||||
// Missing one level of indentation because of the comment
|
||||
const rootEpic = (actions, store) => combineEpics(...epics)(
|
||||
actions,
|
||||
store
|
||||
)// Log errors and continue.
|
||||
.catch((err, stream) => {
|
||||
getLogger().error(err);
|
||||
return stream;
|
||||
});
|
||||
const rootEpic = (actions, store) => combineEpics(...epics)(actions, store)
|
||||
// Log errors and continue.
|
||||
.catch((err, stream) => {
|
||||
getLogger().error(err);
|
||||
return stream;
|
||||
});
|
||||
|
||||
// Two extra levels of indentation because of the comment
|
||||
export type AsyncExecuteOptions =
|
||||
|
||||
@@ -115,6 +115,23 @@ it(\"should group messages with same created time\", () => {
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`test comment.js 1`] = `
|
||||
"function f() {
|
||||
return observableFromSubscribeFunction()
|
||||
// Debounce manually rather than using editor.onDidStopChanging so that the debounce time is
|
||||
// configurable.
|
||||
.debounceTime(debounceInterval);
|
||||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
function f() {
|
||||
return observableFromSubscribeFunction()
|
||||
// Debounce manually rather than using editor.onDidStopChanging so that the debounce time is
|
||||
// configurable.
|
||||
.debounceTime(debounceInterval);
|
||||
}
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`test first_long.js 1`] = `
|
||||
"export default function theFunction(action$, store) {
|
||||
return action$.ofType(THE_ACTION).switchMap(action => Observable
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
function f() {
|
||||
return observableFromSubscribeFunction()
|
||||
// Debounce manually rather than using editor.onDidStopChanging so that the debounce time is
|
||||
// configurable.
|
||||
.debounceTime(debounceInterval);
|
||||
}
|
||||
Reference in new issue
Block a user