diff --git a/.prettierrc.yml b/.prettierrc.yml index 7aaa141..f649aef 100644 --- a/.prettierrc.yml +++ b/.prettierrc.yml @@ -1 +1,2 @@ printWidth: 100 +trailingComma: "es5" diff --git a/.restyled.yaml b/.restyled.yaml new file mode 100644 index 0000000..03b811d --- /dev/null +++ b/.restyled.yaml @@ -0,0 +1,10 @@ +--- +restylers: + - prettier: + image: "restyled/restyler-prettier:v3.2.5-2" + arguments: ["--print-width=100", "--trailing-comma=es5"] + - clang-format: + include: + - "**/*.c*" + - "**/*.h*" + - "*" diff --git a/Dockerfile b/Dockerfile index abe570d..65fbccb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -41,4 +41,4 @@ RUN rm -rf \ /work/js-toxcore-c*/node_modules \ /work/js-toxcore-c*/coverage.lcov \ /work/js-toxcore-c*/package-lock.json -RUN diff -ru /work/js-toxcore-c /work/js-toxcore-c.orig +RUN diff -ru /work/js-toxcore-c.orig /work/js-toxcore-c diff --git a/examples/bin/promises-example.js b/examples/bin/promises-example.js index bed0093..6de6eff 100755 --- a/examples/bin/promises-example.js +++ b/examples/bin/promises-example.js @@ -126,18 +126,19 @@ var initCallbacks = function (callback) { getStatus = tox.getFriendStatusAsync(e.friend()), getConnectionStatus = tox.getFriendConnectionStatusAsync(e.friend()); - Promise.join(getName, getStatusMessage, getStatus, getConnectionStatus, function ( - name, - statusMessage, - status, - connectionStatus - ) { - console.log("Friend " + e.friend() + " profile:"); - console.log(" Name: " + name); - console.log(" Status message: " + statusMessage); - console.log(" Status: " + status); - console.log(" Connection status: " + connectionStatus); - }); + Promise.join( + getName, + getStatusMessage, + getStatus, + getConnectionStatus, + function (name, statusMessage, status, connectionStatus) { + console.log("Friend " + e.friend() + " profile:"); + console.log(" Name: " + name); + console.log(" Status message: " + statusMessage); + console.log(" Status: " + status); + console.log(" Connection status: " + connectionStatus); + } + ); } if (e.message() === "lastonline") { diff --git a/lib/tox.js b/lib/tox.js index 9309d07..d95dfc3 100644 --- a/lib/tox.js +++ b/lib/tox.js @@ -1032,16 +1032,18 @@ Tox.prototype.addFriendNoRequest = function (publicKey, callback) { if (!this._checkHandle(callback)) return; publicKey = fromHex(publicKey); var eptr = ref.alloc(TOX_ERR_FRIEND_ADD); - this.getLibrary().tox_friend_add_norequest.async(this.getHandle(), publicKey, eptr, function ( - err, - friend - ) { - var terr = errors.friendAdd(eptr.deref()); - if (!err && terr) err = terr; - if (callback) { - callback(err, friend); + this.getLibrary().tox_friend_add_norequest.async( + this.getHandle(), + publicKey, + eptr, + function (err, friend) { + var terr = errors.friendAdd(eptr.deref()); + if (!err && terr) err = terr; + if (callback) { + callback(err, friend); + } } - }); + ); }; /** @@ -1067,17 +1069,19 @@ Tox.prototype.addFriendNoRequestSync = function (publicKey) { Tox.prototype.deleteFriend = function (friend, callback) { if (!this._checkHandle(callback)) return; var eptr = ref.alloc(TOX_ERR_FRIEND_DELETE); - this.getLibrary().tox_friend_delete.async(this.getHandle(), friend, eptr, function ( - err, - success - ) { - var terr = errors.friendDelete(eptr.deref()); - if (!err && terr) err = terr; - if (!err && !success) err = errors.unsuccessful(); - if (callback) { - callback(err); + this.getLibrary().tox_friend_delete.async( + this.getHandle(), + friend, + eptr, + function (err, success) { + var terr = errors.friendDelete(eptr.deref()); + if (!err && terr) err = terr; + if (!err && !success) err = errors.unsuccessful(); + if (callback) { + callback(err); + } } - }); + ); }; /** @@ -1102,16 +1106,18 @@ Tox.prototype.getFriendByPublicKey = function (publicKey, callback) { if (!this._checkHandle(callback)) return; publicKey = fromHex(publicKey); var eptr = ref.alloc(TOX_ERR_FRIEND_BY_PUBLIC_KEY); - this.getLibrary().tox_friend_by_public_key.async(this.getHandle(), publicKey, eptr, function ( - err, - friend - ) { - var terr = errors.friendByPublicKey(eptr.deref()); - if (!err && terr) err = terr; - if (callback) { - callback(err, friend); + this.getLibrary().tox_friend_by_public_key.async( + this.getHandle(), + publicKey, + eptr, + function (err, friend) { + var terr = errors.friendByPublicKey(eptr.deref()); + if (!err && terr) err = terr; + if (callback) { + callback(err, friend); + } } - }); + ); }; /** @@ -1205,20 +1211,22 @@ Tox.prototype.hasFriendSync = function (friend) { Tox.prototype.getFriendLastOnline = function (friend, callback) { if (!this._checkHandle(callback)) return; var eptr = ref.alloc(TOX_ERR_FRIEND_GET_LAST_ONLINE); - this.getLibrary().tox_friend_get_last_online.async(this.getHandle(), friend, eptr, function ( - err, - timeval - ) { - var terr = errors.friendGetLastOnline(eptr.deref()); - if (!err && terr) err = terr; + this.getLibrary().tox_friend_get_last_online.async( + this.getHandle(), + friend, + eptr, + function (err, timeval) { + var terr = errors.friendGetLastOnline(eptr.deref()); + if (!err && terr) err = terr; - var date; - if (!err) date = getDateFromUInt64(timeval); + var date; + if (!err) date = getDateFromUInt64(timeval); - if (callback) { - callback(err, date); + if (callback) { + callback(err, date); + } } - }); + ); }; /** @@ -1530,17 +1538,20 @@ Tox.prototype.getTcpPortSync = function () { Tox.prototype.setTyping = function (friend, typing, callback) { if (!this._checkHandle(callback)) return; var eptr = ref.alloc(TOX_ERR_SET_TYPING); - this.getLibrary().tox_self_set_typing.async(this.getHandle(), friend, typing, eptr, function ( - err, - success - ) { - var terr = errors.setTyping(eptr.deref()); - if (!err && terr) err = terr; - if (!err && !success) err = errors.unsuccessful(); - if (callback) { - callback(err); + this.getLibrary().tox_self_set_typing.async( + this.getHandle(), + friend, + typing, + eptr, + function (err, success) { + var terr = errors.setTyping(eptr.deref()); + if (!err && terr) err = terr; + if (!err && !success) err = errors.unsuccessful(); + if (callback) { + callback(err); + } } - }); + ); }; /** diff --git a/package-lock.json b/package-lock.json index 07b4e49..e099f7a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3012,9 +3012,9 @@ } }, "prettier": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.0.5.tgz", - "integrity": "sha512-7PtVymN48hGcO4fGjybyBSIWDsLU4H4XlvOHfq91pz9kkGlonzwTfYkaIEwiRg/dAJF9YlbsduBAgtYLi+8cFg==", + "version": "3.2.5", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.2.5.tgz", + "integrity": "sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==", "dev": true }, "process-on-spawn": { diff --git a/package.json b/package.json index 81fd40b..1289f5c 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "mktemp": "^1.0.0", "mocha": "^10.2.0", "nyc": "^15.0.1", - "prettier": "^2.0.5", + "prettier": "^3.2.5", "should": "^13.2.3" } } diff --git a/test/tox.js b/test/tox.js index 6afe289..f831ec0 100644 --- a/test/tox.js +++ b/test/tox.js @@ -98,7 +98,7 @@ describe("Tox", function () { it("should throw an exception", function () { (function () { tox.getFriendByPublicKeySync(fakePublicKeys[0]); - }.should.throw()); + }).should.throw(); }); it("should return an exception (async)", function (done) { @@ -113,7 +113,7 @@ describe("Tox", function () { it("should throw an exception", function () { (function () { tox.getFriendPublicKeySync(0); - }.should.throw()); + }).should.throw(); }); it("should return an exception (async)", function (done) { @@ -128,7 +128,7 @@ describe("Tox", function () { it('should throw an exception if friend doesn"t exist', function () { (function () { tox.deleteFriendSync(0); - }.should.throw()); + }).should.throw(); }); it('should return an exception if friend doesn"t exist', function (done) { @@ -158,7 +158,7 @@ describe("Tox", function () { var publicKey = fakePublicKeys[2]; (function () { tox.getFriendByPublicKeySync(publicKey); - }.should.throw()); + }).should.throw(); // Add and try again var added = tox.addFriendNoRequestSync(publicKey); var retrieved = tox.getFriendByPublicKeySync(publicKey); @@ -363,7 +363,7 @@ describe("Tox", function () { it("should throw a not-bound error if not listening on udp", function () { (function () { toxNoUdp.getUdpPortSync(); - }.should.throw()); + }).should.throw(); }); it("should return a not-bound error if not listening on udp (async)", function (done) { @@ -376,7 +376,7 @@ describe("Tox", function () { it("should throw an error if no handle", function () { (function () { toxDead.getUdpPortSync(); - }.should.throw()); + }).should.throw(); }); it("should return an error if no handle (async)", function (done) { @@ -391,7 +391,7 @@ describe("Tox", function () { it("should throw a not-bound error if not a tcp relay", function () { (function () { tox.getTcpPortSync(); - }.should.throw()); + }).should.throw(); }); it("should return a not-bound error if not a tcp relay (async)", function (done) { @@ -502,7 +502,7 @@ describe("Tox", function () { // Should throw TOX_ERR_DECRYPTION_FAILED (function () { new Tox({ data: edata, pass: "notThePass" }); - }.should.throw()); + }).should.throw(); }); it("should not try to decrypt if no passphrase is given", function () { @@ -512,7 +512,7 @@ describe("Tox", function () { // Should throw TOX_ERR_NEW_LOAD_ENCRYPTED (function () { new Tox({ data: edata }); - }.should.throw()); + }).should.throw(); }); });