diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 00000000000..b8b711376ac --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,59 @@ +module.exports = { + parserOptions: { + ecmaVersion: 6, + sourceType: "module", + ecmaFeatures: { + } + }, + env: { + browser: true, + node: true, + }, + extends: ["eslint:recommended", "google"], + rules: { + // rules we've always adhered to + "max-len": ["error", { + code: 90, + ignoreComments: true, + }], + curly: ["error", "multi-line"], + + // loosen jsdoc requirements a little + "require-jsdoc": ["error", { + require: { + FunctionDeclaration: false, + } + }], + "valid-jsdoc": ["error", { + requireParamDescription: false, + requireReturn: false, + requireReturnDescription: false, + }], + + // rules we do not want from eslint-recommended + "no-console": ["off"], + "no-constant-condition": ["off"], + "no-empty": ["error", { "allowEmptyCatch": true }], + + // rules we do not want from the google styleguide + "object-curly-spacing": ["off"], + "spaced-comment": ["off"], + + // in principle we prefer single quotes, but life is too short + quotes: ["off"], + + // rules we'd ideally like to adhere to, but the current + // code does not (in most cases because it's still ES5) + // we set these to warnings, and assert that the number + // of warnings doesn't exceed a given threshold + "no-var": ["warn"], + "comma-dangle": ["warn"], + "brace-style": ["warn"], + "prefer-rest-params": ["warn"], + "prefer-spread": ["warn"], + "one-var": ["warn"], + "padded-blocks": ["warn"], + "no-extend-native": ["warn"], + "camelcase": ["warn"], + } +} diff --git a/.jshint b/.jshint deleted file mode 100644 index 871364f405d..00000000000 --- a/.jshint +++ /dev/null @@ -1,11 +0,0 @@ -{ - "node": true, - "jasmine": true, - - "nonew": true, - "curly": true, - "forin": true, - "freeze": false, - "undef": true, - "unused": "vars" -} diff --git a/jenkins.sh b/jenkins.sh index e4dd34d0a9b..58cd6058c93 100755 --- a/jenkins.sh +++ b/jenkins.sh @@ -14,13 +14,8 @@ function fail { npm test || fail "npm test finished with return code $?" -jshint --reporter=checkstyle -c .jshint src spec > jshint.xml || - fail "jshint finished with return code $?" - -gjslint --unix_mode --disable 0131,0211,0200,0222,0212 \ - --max_line_length 90 \ - -r src/ -r spec/ > gjslint.log || - fail "gjslint finished with return code $?" +npm run lint -- -f checkstyle > eslint.xml || + fail "eslint finished with return code $?" # delete the old tarball, if it exists rm -f matrix-js-sdk-*.tgz diff --git a/package.json b/package.json index 9a516853801..6f49090c18b 100644 --- a/package.json +++ b/package.json @@ -7,13 +7,12 @@ "test": "istanbul cover --report cobertura --config .istanbul.yml -i \"lib/**/*.js\" jasmine-node -- spec --verbose --junitreport --captureExceptions", "check": "jasmine-node spec --verbose --junitreport --captureExceptions", "gendoc": "jsdoc -r lib -P package.json -R README.md -d .jsdoc", - "compile": "babel -s -d lib src", "start": "babel -s -w -d lib src", - "build": "jshint -c .jshint lib/ && rimraf dist && mkdir dist && browserify --exclude olm browser-index.js -o dist/browser-matrix.js --ignore-missing && uglifyjs -c -m -o dist/browser-matrix.min.js dist/browser-matrix.js", + "build": "babel -s -d lib src && rimraf dist && mkdir dist && browserify --exclude olm browser-index.js -o dist/browser-matrix.js --ignore-missing && uglifyjs -c -m -o dist/browser-matrix.min.js dist/browser-matrix.js", "dist": "npm run build", "watch": "watchify --exclude olm browser-index.js -o dist/browser-matrix-dev.js -v", - "lint": "jshint -c .jshint src spec && gjslint --unix_mode --disable 0131,0211,0200,0222,0212 --max_line_length 90 -r spec/ -r src/", - "prepublish": "npm run compile && git rev-parse HEAD > git-revision.txt" + "lint": "eslint --max-warnings 3480 src spec", + "prepublish": "npm run lint && npm run build && git rev-parse HEAD > git-revision.txt" }, "repository": { "url": "https://github.com/matrix-org/matrix-js-sdk" @@ -53,10 +52,11 @@ "devDependencies": { "babel-cli": "^6.18.0", "babel-preset-es2015": "^6.18.0", + "eslint": "^3.13.1", + "eslint-config-google": "^0.7.1", "istanbul": "^0.3.13", "jasmine-node": "^1.14.5", "jsdoc": "^3.4.0", - "jshint": "^2.8.0", "rimraf": "^2.5.4", "uglifyjs": "^2.4.10", "watchify": "^3.2.1" diff --git a/spec/.eslintrc.js b/spec/.eslintrc.js new file mode 100644 index 00000000000..44af11935c3 --- /dev/null +++ b/spec/.eslintrc.js @@ -0,0 +1,5 @@ +module.exports = { + env: { + jasmine: true, + }, +} diff --git a/spec/integ/matrix-client-crypto.spec.js b/spec/integ/matrix-client-crypto.spec.js index 9d7cbbd5e75..051df7d0cc6 100644 --- a/spec/integ/matrix-client-crypto.spec.js +++ b/spec/integ/matrix-client-crypto.spec.js @@ -463,7 +463,7 @@ describe("MatrixClient crypto", function() { } beforeEach(function() { - test_utils.beforeEach(this); + test_utils.beforeEach(this); // eslint-disable-line no-invalid-this aliStorage = new sdk.WebStorageSessionStore(new test_utils.MockStorageApi()); aliHttpBackend = new HttpBackend(); diff --git a/spec/integ/matrix-client-event-emitter.spec.js b/spec/integ/matrix-client-event-emitter.spec.js index 82fbd1bd1c5..9f67c5b79b9 100644 --- a/spec/integ/matrix-client-event-emitter.spec.js +++ b/spec/integ/matrix-client-event-emitter.spec.js @@ -10,7 +10,7 @@ describe("MatrixClient events", function() { var selfAccessToken = "aseukfgwef"; beforeEach(function() { - utils.beforeEach(this); + utils.beforeEach(this); // eslint-disable-line no-invalid-this httpBackend = new HttpBackend(); sdk.request(httpBackend.requestFn); client = sdk.createClient({ diff --git a/spec/integ/matrix-client-event-timeline.spec.js b/spec/integ/matrix-client-event-timeline.spec.js index b5cac3959fd..890b564d89c 100644 --- a/spec/integ/matrix-client-event-timeline.spec.js +++ b/spec/integ/matrix-client-event-timeline.spec.js @@ -100,7 +100,7 @@ describe("getEventTimeline support", function() { var client; beforeEach(function() { - utils.beforeEach(this); + utils.beforeEach(this); // eslint-disable-line no-invalid-this httpBackend = new HttpBackend(); sdk.request(httpBackend.requestFn); }); @@ -221,7 +221,7 @@ describe("MatrixClient event timelines", function() { var client, httpBackend; beforeEach(function(done) { - utils.beforeEach(this); + utils.beforeEach(this); // eslint-disable-line no-invalid-this httpBackend = new HttpBackend(); sdk.request(httpBackend.requestFn); @@ -415,7 +415,7 @@ describe("MatrixClient event timelines", function() { }; }); - var tl0, tl2, tl3; + var tl0, tl3; client.getEventTimeline(timelineSet, EVENTS[0].event_id ).then(function(tl) { expect(tl.getEvents().length).toEqual(1); @@ -423,7 +423,6 @@ describe("MatrixClient event timelines", function() { return client.getEventTimeline(timelineSet, EVENTS[2].event_id); }).then(function(tl) { expect(tl.getEvents().length).toEqual(1); - tl2 = tl; return client.getEventTimeline(timelineSet, EVENTS[3].event_id); }).then(function(tl) { expect(tl.getEvents().length).toEqual(1); diff --git a/spec/integ/matrix-client-methods.spec.js b/spec/integ/matrix-client-methods.spec.js index 68d23ccd39f..5a8d17800ad 100644 --- a/spec/integ/matrix-client-methods.spec.js +++ b/spec/integ/matrix-client-methods.spec.js @@ -15,7 +15,7 @@ describe("MatrixClient", function() { var accessToken = "aseukfgwef"; beforeEach(function() { - utils.beforeEach(this); + utils.beforeEach(this); // eslint-disable-line no-invalid-this httpBackend = new HttpBackend(); store = new MatrixInMemoryStore(); @@ -363,7 +363,7 @@ describe("MatrixClient", function() { assertObjectContains(res.chaz.dev2, { verified: 0, // DeviceVerification.UNVERIFIED - keys: { "ed25519:dev2" : ed25519key }, + keys: { "ed25519:dev2": ed25519key }, algorithms: ["2"], unsigned: { "ghi": "def" }, }); diff --git a/spec/integ/matrix-client-opts.spec.js b/spec/integ/matrix-client-opts.spec.js index ca5f5fd50dd..27a9514b46b 100644 --- a/spec/integ/matrix-client-opts.spec.js +++ b/spec/integ/matrix-client-opts.spec.js @@ -53,7 +53,7 @@ describe("MatrixClient opts", function() { }; beforeEach(function() { - utils.beforeEach(this); + utils.beforeEach(this); // eslint-disable-line no-invalid-this httpBackend = new HttpBackend(); }); diff --git a/spec/integ/matrix-client-retrying.spec.js b/spec/integ/matrix-client-retrying.spec.js index 95ebf3b57da..184231d4b25 100644 --- a/spec/integ/matrix-client-retrying.spec.js +++ b/spec/integ/matrix-client-retrying.spec.js @@ -14,7 +14,7 @@ describe("MatrixClient retrying", function() { var room; beforeEach(function() { - utils.beforeEach(this); + utils.beforeEach(this); // eslint-disable-line no-invalid-this httpBackend = new HttpBackend(); sdk.request(httpBackend.requestFn); scheduler = new sdk.MatrixScheduler(); diff --git a/spec/integ/matrix-client-room-timeline.spec.js b/spec/integ/matrix-client-room-timeline.spec.js index c2ef9adb51f..20d678657f4 100644 --- a/spec/integ/matrix-client-room-timeline.spec.js +++ b/spec/integ/matrix-client-room-timeline.spec.js @@ -101,7 +101,7 @@ describe("MatrixClient room timelines", function() { } beforeEach(function(done) { - utils.beforeEach(this); + utils.beforeEach(this); // eslint-disable-line no-invalid-this httpBackend = new HttpBackend(); sdk.request(httpBackend.requestFn); client = sdk.createClient({ diff --git a/spec/integ/matrix-client-syncing.spec.js b/spec/integ/matrix-client-syncing.spec.js index b6013f84a6a..e9257ad6724 100644 --- a/spec/integ/matrix-client-syncing.spec.js +++ b/spec/integ/matrix-client-syncing.spec.js @@ -18,7 +18,7 @@ describe("MatrixClient syncing", function() { var roomTwo = "!bar:localhost"; beforeEach(function() { - utils.beforeEach(this); + utils.beforeEach(this); // eslint-disable-line no-invalid-this httpBackend = new HttpBackend(); sdk.request(httpBackend.requestFn); client = sdk.createClient({ diff --git a/spec/integ/megolm.spec.js b/spec/integ/megolm.spec.js index 9defe881730..c8eb07ac8fe 100644 --- a/spec/integ/megolm.spec.js +++ b/spec/integ/megolm.spec.js @@ -61,7 +61,7 @@ function TestClient(userId, deviceId, accessToken) { /** * start the client, and wait for it to initialise. * - * @param {object?} deviceQueryResponse the list of our existing devices to return from + * @param {object?} existingDevices the list of our existing devices to return from * the /query request. Defaults to empty device list * @return {Promise} */ @@ -313,6 +313,9 @@ describe("megolm", function() { /** * Get the device keys for testOlmAccount in a format suitable for a * response to /keys/query + * + * @param {string} userId The user ID to query for + * @returns {Object} The fake query response */ function getTestKeysQueryResponse(userId) { var testE2eKeys = JSON.parse(testOlmAccount.identity_keys()); @@ -346,6 +349,9 @@ describe("megolm", function() { /** * Get a one-time key for testOlmAccount in a format suitable for a * response to /keys/claim + + * @param {string} userId The user ID to query for + * @returns {Object} The fake key claim response */ function getTestKeysClaimResponse(userId) { testOlmAccount.generate_one_time_keys(1); @@ -374,7 +380,7 @@ describe("megolm", function() { } beforeEach(function() { - test_utils.beforeEach(this); + test_utils.beforeEach(this); // eslint-disable-line no-invalid-this aliceTestClient = new TestClient( "@alice:localhost", "xzcvb", "akjgkrgjs" diff --git a/spec/test-utils.js b/spec/test-utils.js index e03cf66c474..78deb564224 100644 --- a/spec/test-utils.js +++ b/spec/test-utils.js @@ -28,7 +28,7 @@ module.exports.mock = function(constr, name) { result.jasmineToString = function() { return "mock" + (name ? " of " + name : ""); }; - for (var key in constr.prototype) { // jshint ignore:line + for (var key in constr.prototype) { // eslint-disable-line guard-for-in try { if (constr.prototype[key] instanceof Function) { result[key] = jasmine.createSpy((name || "mock") + '.' + key); diff --git a/spec/unit/content-repo.spec.js b/spec/unit/content-repo.spec.js index 7684d08c58a..0d49b7ee8ba 100644 --- a/spec/unit/content-repo.spec.js +++ b/spec/unit/content-repo.spec.js @@ -6,7 +6,7 @@ describe("ContentRepo", function() { var baseUrl = "https://my.home.server"; beforeEach(function() { - testUtils.beforeEach(this); + testUtils.beforeEach(this); // eslint-disable-line no-invalid-this }); describe("getHttpUriForMxc", function() { diff --git a/spec/unit/event-timeline.spec.js b/spec/unit/event-timeline.spec.js index 8cb2f2e48dc..8868621e9e5 100644 --- a/spec/unit/event-timeline.spec.js +++ b/spec/unit/event-timeline.spec.js @@ -15,7 +15,7 @@ describe("EventTimeline", function() { var timeline; beforeEach(function() { - utils.beforeEach(this); + utils.beforeEach(this); // eslint-disable-line no-invalid-this // XXX: this is a horrid hack; should use sinon or something instead to mock var timelineSet = { room: { roomId: roomId }}; diff --git a/spec/unit/filter.spec.js b/spec/unit/filter.spec.js index e9c62f58874..909d87c2048 100644 --- a/spec/unit/filter.spec.js +++ b/spec/unit/filter.spec.js @@ -9,7 +9,7 @@ describe("Filter", function() { var filter; beforeEach(function() { - utils.beforeEach(this); + utils.beforeEach(this); // eslint-disable-line no-invalid-this filter = new Filter(userId); }); diff --git a/spec/unit/interactive-auth.spec.js b/spec/unit/interactive-auth.spec.js index 049b9eb35c1..103c0bad981 100644 --- a/spec/unit/interactive-auth.spec.js +++ b/spec/unit/interactive-auth.spec.js @@ -24,7 +24,7 @@ var MatrixError = sdk.MatrixError; describe("InteractiveAuth", function() { beforeEach(function() { - utils.beforeEach(this); + utils.beforeEach(this); // eslint-disable-line no-invalid-this }); it("should start an auth stage and complete it", function(done) { diff --git a/spec/unit/matrix-client.spec.js b/spec/unit/matrix-client.spec.js index 41bb5f70501..77bb368bc99 100644 --- a/spec/unit/matrix-client.spec.js +++ b/spec/unit/matrix-client.spec.js @@ -117,7 +117,7 @@ describe("MatrixClient", function() { } beforeEach(function() { - utils.beforeEach(this); + utils.beforeEach(this); // eslint-disable-line no-invalid-this jasmine.Clock.useMock(); scheduler = jasmine.createSpyObj("scheduler", [ "getQueueForEvent", "queueEvent", "removeEventFromQueue", diff --git a/spec/unit/realtime-callbacks.spec.js b/spec/unit/realtime-callbacks.spec.js index 0cf770acea9..bec63bf0be9 100644 --- a/spec/unit/realtime-callbacks.spec.js +++ b/spec/unit/realtime-callbacks.spec.js @@ -14,7 +14,7 @@ describe("realtime-callbacks", function() { } beforeEach(function() { - test_utils.beforeEach(this); + test_utils.beforeEach(this); // eslint-disable-line no-invalid-this clock.useMock(); fakeDate = Date.now(); callbacks.setNow(function() { return fakeDate; }); @@ -54,8 +54,8 @@ describe("realtime-callbacks", function() { it("should set 'this' to the global object", function() { var callback = jasmine.createSpy(); callback.andCallFake(function() { - expect(this).toBe(global); - expect(this.console).toBeDefined(); + expect(this).toBe(global); // eslint-disable-line no-invalid-this + expect(this.console).toBeDefined(); // eslint-disable-line no-invalid-this }); callbacks.setTimeout(callback); tick(0); diff --git a/spec/unit/room-member.spec.js b/spec/unit/room-member.spec.js index d11cd38225c..36a38932c99 100644 --- a/spec/unit/room-member.spec.js +++ b/spec/unit/room-member.spec.js @@ -11,7 +11,7 @@ describe("RoomMember", function() { var member; beforeEach(function() { - utils.beforeEach(this); + utils.beforeEach(this); // eslint-disable-line no-invalid-this member = new RoomMember(roomId, userA); }); diff --git a/spec/unit/room-state.spec.js b/spec/unit/room-state.spec.js index b9dfe6583b6..57c99b2081e 100644 --- a/spec/unit/room-state.spec.js +++ b/spec/unit/room-state.spec.js @@ -11,7 +11,7 @@ describe("RoomState", function() { var state; beforeEach(function() { - utils.beforeEach(this); + utils.beforeEach(this); // eslint-disable-line no-invalid-this state = new RoomState(roomId); state.setStateEvents([ utils.mkMembership({ // userA joined diff --git a/spec/unit/room.spec.js b/spec/unit/room.spec.js index 0a878b41e4a..74882a08224 100644 --- a/spec/unit/room.spec.js +++ b/spec/unit/room.spec.js @@ -16,7 +16,7 @@ describe("Room", function() { var room; beforeEach(function() { - utils.beforeEach(this); + utils.beforeEach(this); // eslint-disable-line no-invalid-this room = new Room(roomId); // mock RoomStates room.oldState = room.getLiveTimeline()._startState = @@ -1110,7 +1110,7 @@ describe("Room", function() { describe("tags", function() { function mkTags(roomId, tags) { - var content = { "tags" : tags }; + var content = { "tags": tags }; return new MatrixEvent({ content: content, room_id: roomId, diff --git a/spec/unit/scheduler.spec.js b/spec/unit/scheduler.spec.js index 71114dd872e..68fb4581eeb 100644 --- a/spec/unit/scheduler.spec.js +++ b/spec/unit/scheduler.spec.js @@ -1,4 +1,6 @@ -"use strict"; +// This file had a function whose name is all caps, which displeases eslint +/* eslint new-cap: "off" */ + var q = require("q"); var sdk = require("../.."); var MatrixScheduler = sdk.MatrixScheduler; @@ -18,7 +20,7 @@ describe("MatrixScheduler", function() { }); beforeEach(function() { - utils.beforeEach(this); + utils.beforeEach(this); // eslint-disable-line no-invalid-this jasmine.Clock.useMock(); scheduler = new MatrixScheduler(function(ev, attempts, err) { if (retryFn) { diff --git a/spec/unit/timeline-window.spec.js b/spec/unit/timeline-window.spec.js index d04f6b5859f..ecdb2eaaed4 100644 --- a/spec/unit/timeline-window.spec.js +++ b/spec/unit/timeline-window.spec.js @@ -60,7 +60,7 @@ function createLinkedTimelines() { describe("TimelineIndex", function() { beforeEach(function() { - utils.beforeEach(this); + utils.beforeEach(this); // eslint-disable-line no-invalid-this }); describe("minIndex", function() { @@ -153,7 +153,7 @@ describe("TimelineWindow", function() { } beforeEach(function() { - utils.beforeEach(this); + utils.beforeEach(this); // eslint-disable-line no-invalid-this }); describe("load", function() { diff --git a/spec/unit/user.spec.js b/spec/unit/user.spec.js index b2dd6e30c2f..e4df82010b1 100644 --- a/spec/unit/user.spec.js +++ b/spec/unit/user.spec.js @@ -8,7 +8,7 @@ describe("User", function() { var user; beforeEach(function() { - utils.beforeEach(this); + utils.beforeEach(this); // eslint-disable-line no-invalid-this user = new User(userId); }); diff --git a/spec/unit/utils.spec.js b/spec/unit/utils.spec.js index fe9cdeee13c..49324c18a2c 100644 --- a/spec/unit/utils.spec.js +++ b/spec/unit/utils.spec.js @@ -4,7 +4,7 @@ var testUtils = require("../test-utils"); describe("utils", function() { beforeEach(function() { - testUtils.beforeEach(this); + testUtils.beforeEach(this); // eslint-disable-line no-invalid-this }); describe("encodeParams", function() { diff --git a/spec/unit/webstorage.spec.js b/spec/unit/webstorage.spec.js index 25a613e0c75..8454f324eb5 100644 --- a/spec/unit/webstorage.spec.js +++ b/spec/unit/webstorage.spec.js @@ -33,7 +33,7 @@ describe("WebStorageStore", function() { ); beforeEach(function() { - utils.beforeEach(this); + utils.beforeEach(this); // eslint-disable-line no-invalid-this mockStorageApi = new MockStorageApi(); store = new WebStorageStore(mockStorageApi, batchNum); room = new Room(roomId); diff --git a/src/base-apis.js b/src/base-apis.js index 36ef33aefea..47c831c835c 100644 --- a/src/base-apis.js +++ b/src/base-apis.js @@ -439,6 +439,7 @@ MatrixBaseApis.prototype.roomInitialSync = function(roomId, limit, callback) { // ========================= /** + * @param {Object} options Options for this request * @param {string} options.server The remote server to query for the room list. * Optional. If unspecified, get the local home * server's public room list. @@ -1022,7 +1023,7 @@ MatrixBaseApis.prototype.downloadKeysForUsers = function(userIds, callback) { /** * Claim one-time keys * - * @param {string[][]} devices a list of [userId, deviceId] pairs + * @param {string[]} devices a list of [userId, deviceId] pairs * * @param {string} [key_algorithm = signed_curve25519] desired key type * diff --git a/src/client.js b/src/client.js index 254bc0aa8e1..c6a92d09b6f 100644 --- a/src/client.js +++ b/src/client.js @@ -357,8 +357,6 @@ MatrixClient.prototype.getStoredDevicesForUser = function(userId) { return this._crypto.getStoredDevicesForUser(userId) || []; }; - - /** * Mark the given device as verified * @@ -377,7 +375,6 @@ MatrixClient.prototype.setDeviceVerified = function(userId, deviceId, verified) _setDeviceVerification(this, userId, deviceId, verified, null); }; - /** * Mark the given device as blocked/unblocked * @@ -542,7 +539,7 @@ MatrixClient.prototype.getUsers = function() { /** * Set account data event for the current user. * @param {string} eventType The event type - * @param {Object} content the contents object for the event + * @param {Object} contents the contents object for the event * @param {module:client.callback} callback Optional. * @return {module:client.Promise} Resolves: TODO * @return {module:http-api.MatrixError} Rejects: with an error response. @@ -1500,7 +1497,7 @@ MatrixClient.prototype.getPresenceList = function(callback) { * @return {module:http-api.MatrixError} Rejects: with an error response. */ MatrixClient.prototype.inviteToPresenceList = function(callback, userIds) { - var opts = {"invite" : userIds}; + var opts = {"invite": userIds}; return _presenceList(callback, this, opts, "POST"); }; @@ -1512,7 +1509,7 @@ MatrixClient.prototype.inviteToPresenceList = function(callback, userIds) { * @return {module:http-api.MatrixError} Rejects: with an error response. **/ MatrixClient.prototype.dropFromPresenceList = function(callback, userIds) { - var opts = {"drop" : userIds}; + var opts = {"drop": userIds}; return _presenceList(callback, this, opts, "POST"); }; diff --git a/src/crypto/OlmDevice.js b/src/crypto/OlmDevice.js index bfda869f050..42fd117f891 100644 --- a/src/crypto/OlmDevice.js +++ b/src/crypto/OlmDevice.js @@ -467,7 +467,6 @@ OlmDevice.prototype.matchesSession = function( }; - // Outbound group session // ====================== diff --git a/src/crypto/algorithms/base.js b/src/crypto/algorithms/base.js index afdc555b8e3..4374fde8ff0 100644 --- a/src/crypto/algorithms/base.js +++ b/src/crypto/algorithms/base.js @@ -130,7 +130,7 @@ module.exports.DecryptionAlgorithm = DecryptionAlgorithm; * * @method module:crypto/algorithms/base.DecryptionAlgorithm#onRoomKeyEvent * - * @param {module:models/event.MatrixEvent} event key event + * @param {module:models/event.MatrixEvent} params event key event */ DecryptionAlgorithm.prototype.onRoomKeyEvent = function(params) { // ignore by default diff --git a/src/crypto/algorithms/megolm.js b/src/crypto/algorithms/megolm.js index f7a063ca356..0a27162ce1e 100644 --- a/src/crypto/algorithms/megolm.js +++ b/src/crypto/algorithms/megolm.js @@ -150,7 +150,7 @@ utils.inherits(MegolmEncryption, base.EncryptionAlgorithm); /** * @private * - * @param {module:models/room} room + * @param {Object} devicesInRoom The devices in this room, indexed by user ID * * @return {module:client.Promise} Promise which resolves to the * OutboundSessionInfo when setup is complete. @@ -378,7 +378,7 @@ MegolmEncryption.prototype._shareKeyWithDevices = function(session, devicesByUse * * @param {module:models/room} room * @param {string} eventType - * @param {object} plaintext event content + * @param {object} content plaintext event content * * @return {module:client.Promise} Promise which resolves to the new event body */ @@ -475,9 +475,6 @@ utils.inherits(MegolmDecryption, base.DecryptionAlgorithm); * * @param {MatrixEvent} event * - * @return {null} The event referred to an unknown megolm session - * @return {module:crypto.DecryptionResult} decryption result - * * @throws {module:crypto/algorithms/base.DecryptionError} if there is a * problem decrypting the event */ diff --git a/src/crypto/algorithms/olm.js b/src/crypto/algorithms/olm.js index 5852aa82ca5..dc42d5b4c38 100644 --- a/src/crypto/algorithms/olm.js +++ b/src/crypto/algorithms/olm.js @@ -79,7 +79,7 @@ OlmEncryption.prototype._ensureSession = function(roomMembers) { * * @param {module:models/room} room * @param {string} eventType - * @param {object} plaintext event content + * @param {object} content plaintext event content * * @return {module:client.Promise} Promise which resolves to the new event body */ diff --git a/src/crypto/index.js b/src/crypto/index.js index 300e8c56e43..fd189d29073 100644 --- a/src/crypto/index.js +++ b/src/crypto/index.js @@ -348,7 +348,7 @@ Crypto.prototype._getDevicesFromStore = function(userIds) { /** * @param {string[]} downloadUsers list of userIds * - * @return {Object a map from userId to a promise for a result for that user + * @return {Object} a map from userId to a promise for a result for that user */ Crypto.prototype._doKeyDownloadForUsers = function(downloadUsers) { var self = this; @@ -546,7 +546,7 @@ function _storeDeviceKeys(_olmDevice, userStore, deviceResult) { * * @param {string} userId the user to list keys for. * - * @return {module:crypto/deviceinfo[]?} list of devices, or null if we haven't + * @return {module:crypto/deviceinfo[]|null} list of devices, or null if we haven't * managed to get a list of devices for this user yet. */ Crypto.prototype.getStoredDevicesForUser = function(userId) { diff --git a/src/filter-component.js b/src/filter-component.js index 98f8fd7d74e..47fd298da6d 100644 --- a/src/filter-component.js +++ b/src/filter-component.js @@ -44,7 +44,7 @@ function _matches_wildcard(actual_value, filter_value) { * 'Filters' are referred to as 'FilterCollections'. * * @constructor - * @param {Object} the definition of this filter JSON, e.g. { 'contains_url': true } + * @param {Object} filter_json the definition of this filter JSON, e.g. { 'contains_url': true } */ function FilterComponent(filter_json) { this.filter_json = filter_json; diff --git a/src/interactive-auth.js b/src/interactive-auth.js index 8ba89516bbd..8b6395e236e 100644 --- a/src/interactive-auth.js +++ b/src/interactive-auth.js @@ -89,8 +89,8 @@ InteractiveAuth.prototype = { /** * get the server params for a given stage * - * @param {string} login type for the stage - * @return {object?} any parameters from the server for this stage + * @param {string} loginType login type for the stage + * @return {object?} any parameters from the server for this stage */ getStageParams: function(loginType) { var params = {}; diff --git a/src/models/event-timeline-set.js b/src/models/event-timeline-set.js index 1f4bc4739b6..6b827db73b9 100644 --- a/src/models/event-timeline-set.js +++ b/src/models/event-timeline-set.js @@ -24,11 +24,12 @@ var EventTimeline = require("./event-timeline"); // var DEBUG = false; var DEBUG = true; +var debuglog; if (DEBUG) { // using bind means that we get to keep useful line numbers in the console - var debuglog = console.log.bind(console); + debuglog = console.log.bind(console); } else { - var debuglog = function() {}; + debuglog = function() {}; } /** diff --git a/src/models/event.js b/src/models/event.js index b4ced278dd1..c4917654487 100644 --- a/src/models/event.js +++ b/src/models/event.js @@ -438,8 +438,6 @@ var _REDACT_KEEP_CONTENT_MAP = { }; - - /** * Fires when an event is decrypted * diff --git a/src/models/room-state.js b/src/models/room-state.js index 32b3a924e03..799dbbe93ca 100644 --- a/src/models/room-state.js +++ b/src/models/room-state.js @@ -253,7 +253,7 @@ RoomState.prototype.maySendMessage = function(userId) { /** * Returns true if the given user ID has permission to send a normal * event of type `eventType` into this room. - * @param {string} type The type of event to test + * @param {string} eventType The type of event to test * @param {string} userId The user ID of the user to test permission for * @return {boolean} true if the given user ID should be permitted to send * the given type of event into this room, @@ -267,8 +267,8 @@ RoomState.prototype.maySendEvent = function(eventType, userId) { /** * Returns true if the given MatrixClient has permission to send a state * event of type `stateEventType` into this room. - * @param {string} type The type of state events to test - * @param {MatrixClient} The client to test permission for + * @param {string} stateEventType The type of state events to test + * @param {MatrixClient} cli The client to test permission for * @return {boolean} true if the given client should be permitted to send * the given type of state event into this room, * according to the room's state. @@ -283,7 +283,7 @@ RoomState.prototype.mayClientSendStateEvent = function(stateEventType, cli) { /** * Returns true if the given user ID has permission to send a state * event of type `stateEventType` into this room. - * @param {string} type The type of state events to test + * @param {string} stateEventType The type of state events to test * @param {string} userId The user ID of the user to test permission for * @return {boolean} true if the given user ID should be permitted to send * the given type of state event into this room, @@ -296,7 +296,7 @@ RoomState.prototype.maySendStateEvent = function(stateEventType, userId) { /** * Returns true if the given user ID has permission to send a normal or state * event of type `eventType` into this room. - * @param {string} type The type of event to test + * @param {string} eventType The type of event to test * @param {string} userId The user ID of the user to test permission for * @param {boolean} state If true, tests if the user may send a state event of this type. Otherwise tests whether @@ -314,18 +314,12 @@ RoomState.prototype._maySendEventOfType = function(eventType, userId, state) { var power_levels; var events_levels = {}; - var default_user_level = 0; - var user_levels = []; - var state_default = 0; var events_default = 0; if (power_levels_event) { power_levels = power_levels_event.getContent(); events_levels = power_levels.events || {}; - default_user_level = parseInt(power_levels.users_default || 0); - user_levels = power_levels.users || {}; - if (power_levels.state_default !== undefined) { state_default = power_levels.state_default; } else { diff --git a/src/models/room.js b/src/models/room.js index db742d6fe7c..4c84147a4d3 100644 --- a/src/models/room.js +++ b/src/models/room.js @@ -906,8 +906,6 @@ Room.prototype.recalculate = function(userId) { }); } - - var oldName = this.name; this.name = calculateRoomName(this, userId); this.summary = new RoomSummary(this.roomId, { diff --git a/src/store/session/webstorage.js b/src/store/session/webstorage.js index 3296f5d16a6..9903f9f3c4b 100644 --- a/src/store/session/webstorage.js +++ b/src/store/session/webstorage.js @@ -92,7 +92,7 @@ WebStorageSessionStore.prototype = { * @param {string} userId The user's ID. * @return {object} A map from device ID to keys for the device. */ - getEndToEndDevicesForUser: function(userId) { + getEndToEndDevicesForUser: function(userId) { return getJsonItem(this.store, keyEndToEndDevicesForUser(userId)); }, diff --git a/src/sync.js b/src/sync.js index 160a8b26dd7..cb3c9b1e271 100644 --- a/src/sync.js +++ b/src/sync.js @@ -1016,7 +1016,7 @@ SyncApi.prototype._resolveInvites = function(room) { * @param {Room} room * @param {MatrixEvent[]} stateEventList A list of state events. This is the state * at the *START* of the timeline list if it is supplied. - * @param {?MatrixEvent[]} timelineEventList A list of timeline events. Lower index + * @param {MatrixEvent[]} [timelineEventList] A list of timeline events. Lower index * is earlier in time. Higher index is later. */ SyncApi.prototype._processRoomEvents = function(room, stateEventList, diff --git a/src/utils.js b/src/utils.js index 8a1c094046f..2f3fe28b06d 100644 --- a/src/utils.js +++ b/src/utils.js @@ -348,16 +348,12 @@ var deepCompare = module.exports.deepCompare = function(x, y) { */ module.exports.extend = function() { var target = arguments[0] || {}; - // disable jshint "The body of a for in should be wrapped in an if - // statement" - /* jshint -W089 */ for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; - for (var propName in source) { + for (var propName in source) { // eslint-disable-line guard-for-in target[propName] = source[propName]; } } - /* jshint +W089 */ return target; }; diff --git a/src/webrtc/call.js b/src/webrtc/call.js index ab8a1d13d92..772472407b9 100644 --- a/src/webrtc/call.js +++ b/src/webrtc/call.js @@ -153,7 +153,7 @@ MatrixCall.prototype.placeScreenSharingCall = /** * Play the given HTMLMediaElement, serialising the operation into a chain * of promises to avoid racing access to the element - * @param {Element} HTMLMediaElement element to play + * @param {Element} element HTMLMediaElement element to play * @param {string} queueId Arbitrary ID to track the chain of promises to be used */ MatrixCall.prototype.playElement = function(element, queueId) { @@ -183,7 +183,7 @@ MatrixCall.prototype.playElement = function(element, queueId) { /** * Pause the given HTMLMediaElement, serialising the operation into a chain * of promises to avoid racing access to the element - * @param {Element} HTMLMediaElement element to pause + * @param {Element} element HTMLMediaElement element to pause * @param {string} queueId Arbitrary ID to track the chain of promises to be used */ MatrixCall.prototype.pauseElement = function(element, queueId) { @@ -209,7 +209,7 @@ MatrixCall.prototype.pauseElement = function(element, queueId) { * Assign the given HTMLMediaElement by setting the .src attribute on it, * serialising the operation into a chain of promises to avoid racing access * to the element - * @param {Element} HTMLMediaElement element to pause + * @param {Element} element HTMLMediaElement element to pause * @param {string} src the src attribute value to assign to the element * @param {string} queueId Arbitrary ID to track the chain of promises to be used */