diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js index 65eabd6f..04912ef6 100644 --- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -3852,12 +3852,18 @@ const functionCompositionFunctionNames = new Set([ "connect", // Redux "createSelector" // Reselect ]); +const ordinaryMethodNames = new Set([ + "connect" // GObject, MongoDB +]); function isFunctionCompositionFunction(node) { switch (node.type) { case "OptionalMemberExpression": case "MemberExpression": { - return isFunctionCompositionFunction(node.property); + return ( + isFunctionCompositionFunction(node.property) && + !ordinaryMethodNames.has(node.property.name) + ); } case "Identifier": { return functionCompositionFunctionNames.has(node.name); diff --git a/tests/functional_composition/__snapshots__/jsfmt.spec.js.snap b/tests/functional_composition/__snapshots__/jsfmt.spec.js.snap index 3cda2fd0..ca9068fa 100644 --- a/tests/functional_composition/__snapshots__/jsfmt.spec.js.snap +++ b/tests/functional_composition/__snapshots__/jsfmt.spec.js.snap @@ -115,6 +115,34 @@ this.subscriptions.add( ================================================================================ `; +exports[`gobject_connect.js 1`] = ` +====================================options===================================== +parsers: ["flow", "babel", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +button.connect( + "clicked", + () => doSomething() +); +app.connect( + "activate", + async () => { + await data.load(); + win.show_all(); + } +); + +=====================================output===================================== +button.connect("clicked", () => doSomething()); +app.connect("activate", async () => { + await data.load(); + win.show_all(); +}); + +================================================================================ +`; + exports[`lodash_flow.js 1`] = ` ====================================options===================================== parsers: ["flow", "babel", "typescript"] @@ -215,6 +243,29 @@ foo(6); ================================================================================ `; +exports[`mongo_connect.js 1`] = ` +====================================options===================================== +parsers: ["flow", "babel", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +MongoClient.connect( + "mongodb://localhost:27017/posts", + (err, db) => { + assert.equal(null, err); + db.close(); + } +); + +=====================================output===================================== +MongoClient.connect("mongodb://localhost:27017/posts", (err, db) => { + assert.equal(null, err); + db.close(); +}); + +================================================================================ +`; + exports[`ramda_compose.js 1`] = ` ====================================options===================================== parsers: ["flow", "babel", "typescript"] diff --git a/tests/functional_composition/gobject_connect.js b/tests/functional_composition/gobject_connect.js new file mode 100644 index 00000000..d8dd25ab --- /dev/null +++ b/tests/functional_composition/gobject_connect.js @@ -0,0 +1,11 @@ +button.connect( + "clicked", + () => doSomething() +); +app.connect( + "activate", + async () => { + await data.load(); + win.show_all(); + } +); diff --git a/tests/functional_composition/mongo_connect.js b/tests/functional_composition/mongo_connect.js new file mode 100644 index 00000000..50b18212 --- /dev/null +++ b/tests/functional_composition/mongo_connect.js @@ -0,0 +1,7 @@ +MongoClient.connect( + "mongodb://localhost:27017/posts", + (err, db) => { + assert.equal(null, err); + db.close(); + } +);