Skip to content

Commit

Permalink
Add support for class properties
Browse files Browse the repository at this point in the history
This enables compiler and linting features to allow class properties like we do
in the React SDK.
  • Loading branch information
jryans committed May 10, 2019
1 parent d6abd63 commit e0f9f62
Show file tree
Hide file tree
Showing 36 changed files with 74 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"presets": ["es2015"],
"plugins": [
"transform-class-properties",
// this transforms async functions into generator functions, which
// are then made to use the regenerator module by babel's
// transform-regnerator plugin (which is enabled by es2015).
"transform-async-to-bluebird",

// This makes sure that the regenerator runtime is available to
// the transpiled code.
"transform-runtime",
Expand Down
8 changes: 8 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ module.exports = {
es6: true,
},
extends: ["eslint:recommended", "google"],
plugins: [
"babel",
],
rules: {
// rules we've always adhered to or now do
"max-len": ["error", {
Expand Down Expand Up @@ -73,5 +76,10 @@ module.exports = {
"asyncArrow": "always",
}],
"arrow-parens": "off",

// eslint's built in no-invalid-this rule breaks with class properties
"no-invalid-this": "off",
// so we replace it with a version that is class property aware
"babel/no-invalid-this": "error",
}
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@
"babel-cli": "^6.18.0",
"babel-eslint": "^10.0.1",
"babel-plugin-transform-async-to-bluebird": "^1.1.1",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-es2015": "^6.18.0",
"browserify": "^16.2.3",
"browserify-shim": "^3.8.13",
"eslint": "^5.12.0",
"eslint-config-google": "^0.7.1",
"eslint-plugin-babel": "^5.3.0",
"exorcist": "^0.4.0",
"expect": "^1.20.2",
"istanbul": "^0.4.5",
Expand Down
2 changes: 1 addition & 1 deletion spec/integ/devicelist-integ-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe("DeviceList management:", function() {
}

beforeEach(async function() {
testUtils.beforeEach(this); // eslint-disable-line no-invalid-this
testUtils.beforeEach(this); // eslint-disable-line babel/no-invalid-this

// we create our own sessionStoreBackend so that we can use it for
// another TestClient.
Expand Down
2 changes: 1 addition & 1 deletion spec/integ/matrix-client-crypto.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ describe("MatrixClient crypto", function() {
}

beforeEach(async function() {
testUtils.beforeEach(this); // eslint-disable-line no-invalid-this
testUtils.beforeEach(this); // eslint-disable-line babel/no-invalid-this

aliTestClient = new TestClient(aliUserId, aliDeviceId, aliAccessToken);
await aliTestClient.client.initCrypto();
Expand Down
2 changes: 1 addition & 1 deletion spec/integ/matrix-client-event-emitter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("MatrixClient events", function() {
const selfAccessToken = "aseukfgwef";

beforeEach(function() {
utils.beforeEach(this); // eslint-disable-line no-invalid-this
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
httpBackend = new HttpBackend();
sdk.request(httpBackend.requestFn);
client = sdk.createClient({
Expand Down
4 changes: 2 additions & 2 deletions spec/integ/matrix-client-event-timeline.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe("getEventTimeline support", function() {
let client;

beforeEach(function() {
utils.beforeEach(this); // eslint-disable-line no-invalid-this
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
httpBackend = new HttpBackend();
sdk.request(httpBackend.requestFn);
});
Expand Down Expand Up @@ -227,7 +227,7 @@ describe("MatrixClient event timelines", function() {
let httpBackend = null;

beforeEach(function() {
utils.beforeEach(this); // eslint-disable-line no-invalid-this
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
httpBackend = new HttpBackend();
sdk.request(httpBackend.requestFn);

Expand Down
2 changes: 1 addition & 1 deletion spec/integ/matrix-client-methods.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("MatrixClient", function() {
const accessToken = "aseukfgwef";

beforeEach(function() {
utils.beforeEach(this); // eslint-disable-line no-invalid-this
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
httpBackend = new HttpBackend();
store = new MemoryStore();

Expand Down
2 changes: 1 addition & 1 deletion spec/integ/matrix-client-opts.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe("MatrixClient opts", function() {
};

beforeEach(function() {
utils.beforeEach(this); // eslint-disable-line no-invalid-this
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
httpBackend = new HttpBackend();
});

Expand Down
2 changes: 1 addition & 1 deletion spec/integ/matrix-client-retrying.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe("MatrixClient retrying", function() {
let room;

beforeEach(function() {
utils.beforeEach(this); // eslint-disable-line no-invalid-this
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
httpBackend = new HttpBackend();
sdk.request(httpBackend.requestFn);
scheduler = new sdk.MatrixScheduler();
Expand Down
2 changes: 1 addition & 1 deletion spec/integ/matrix-client-room-timeline.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe("MatrixClient room timelines", function() {
}

beforeEach(function(done) {
utils.beforeEach(this); // eslint-disable-line no-invalid-this
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
httpBackend = new HttpBackend();
sdk.request(httpBackend.requestFn);
client = sdk.createClient({
Expand Down
2 changes: 1 addition & 1 deletion spec/integ/matrix-client-syncing.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe("MatrixClient syncing", function() {
const roomTwo = "!bar:localhost";

beforeEach(function() {
utils.beforeEach(this); // eslint-disable-line no-invalid-this
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
httpBackend = new HttpBackend();
sdk.request(httpBackend.requestFn);
client = sdk.createClient({
Expand Down
2 changes: 1 addition & 1 deletion spec/integ/megolm-integ.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ describe("megolm", function() {
}

beforeEach(async function() {
testUtils.beforeEach(this); // eslint-disable-line no-invalid-this
testUtils.beforeEach(this); // eslint-disable-line babel/no-invalid-this

aliceTestClient = new TestClient(
"@alice:localhost", "xzcvb", "akjgkrgjs",
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/autodiscovery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe("AutoDiscovery", function() {
let httpBackend = null;

beforeEach(function() {
utils.beforeEach(this); // eslint-disable-line no-invalid-this
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
httpBackend = new MockHttpBackend();
sdk.request(httpBackend.requestFn);
});
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/content-repo.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("ContentRepo", function() {
const baseUrl = "https://my.home.server";

beforeEach(function() {
testUtils.beforeEach(this); // eslint-disable-line no-invalid-this
testUtils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
});

describe("getHttpUriForMxc", function() {
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/crypto/DeviceList.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('DeviceList', function() {
let deviceLists = [];

beforeEach(function() {
testUtils.beforeEach(this); // eslint-disable-line no-invalid-this
testUtils.beforeEach(this); // eslint-disable-line babel/no-invalid-this

deviceLists = [];

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/crypto/algorithms/megolm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe("MegolmDecryption", function() {
let mockBaseApis;

beforeEach(async function() {
testUtils.beforeEach(this); // eslint-disable-line no-invalid-this
testUtils.beforeEach(this); // eslint-disable-line babel/no-invalid-this

await Olm.init();

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/crypto/algorithms/olm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe("OlmDecryption", function() {
let bobOlmDevice;

beforeEach(async function() {
testUtils.beforeEach(this); // eslint-disable-line no-invalid-this
testUtils.beforeEach(this); // eslint-disable-line babel/no-invalid-this

await global.Olm.init();

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/crypto/backup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ describe("MegolmBackup", function() {
let megolmDecryption;
beforeEach(async function() {
await Olm.init();
testUtils.beforeEach(this); // eslint-disable-line no-invalid-this
testUtils.beforeEach(this); // eslint-disable-line babel/no-invalid-this

mockCrypto = testUtils.mock(Crypto, 'Crypto');
mockCrypto.backupKey = new Olm.PkEncryption();
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/crypto/verification/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function makeTestClients(userInfos, options) {
for (const [deviceId, msg] of Object.entries(devMap)) {
if (deviceId in clientMap[userId]) {
const event = new MatrixEvent({
sender: this.getUserId(), // eslint-disable-line no-invalid-this
sender: this.getUserId(), // eslint-disable-line babel/no-invalid-this
type: type,
content: msg,
});
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/event-timeline.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe("EventTimeline", function() {
let timeline;

beforeEach(function() {
utils.beforeEach(this); // eslint-disable-line no-invalid-this
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this

// XXX: this is a horrid hack; should use sinon or something instead to mock
const timelineSet = { room: { roomId: roomId }};
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/event.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Promise from 'bluebird';

describe("MatrixEvent", () => {
beforeEach(function() {
testUtils.beforeEach(this); // eslint-disable-line no-invalid-this
testUtils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
});

describe(".attemptDecryption", () => {
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/filter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("Filter", function() {
let filter;

beforeEach(function() {
utils.beforeEach(this); // eslint-disable-line no-invalid-this
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
filter = new Filter(userId);
});

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/interactive-auth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class FakeClient {

describe("InteractiveAuth", function() {
beforeEach(function() {
utils.beforeEach(this); // eslint-disable-line no-invalid-this
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
});

it("should start an auth stage and complete it", function(done) {
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/matrix-client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ describe("MatrixClient", function() {
}

beforeEach(function() {
utils.beforeEach(this); // eslint-disable-line no-invalid-this
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
clock = lolex.install();
scheduler = [
"getQueueForEvent", "queueEvent", "removeEventFromQueue",
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/realtime-callbacks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("realtime-callbacks", function() {
}

beforeEach(function() {
testUtils.beforeEach(this); // eslint-disable-line no-invalid-this
testUtils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
clock = lolex.install();
const fakeDate = clock.Date;
callbacks.setNow(fakeDate.now.bind(fakeDate));
Expand Down Expand Up @@ -56,8 +56,8 @@ describe("realtime-callbacks", function() {
it("should set 'this' to the global object", function() {
let passed = false;
const callback = function() {
expect(this).toBe(global); // eslint-disable-line no-invalid-this
expect(this.console).toBeTruthy(); // eslint-disable-line no-invalid-this
expect(this).toBe(global); // eslint-disable-line babel/no-invalid-this
expect(this.console).toBeTruthy(); // eslint-disable-line babel/no-invalid-this
passed = true;
};
callbacks.setTimeout(callback);
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/room-member.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe("RoomMember", function() {
let member;

beforeEach(function() {
utils.beforeEach(this); // eslint-disable-line no-invalid-this
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
member = new RoomMember(roomId, userA);
});

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/room-state.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("RoomState", function() {
let state;

beforeEach(function() {
utils.beforeEach(this); // eslint-disable-line no-invalid-this
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
state = new RoomState(roomId);
state.setStateEvents([
utils.mkMembership({ // userA joined
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/room.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("Room", function() {
let room;

beforeEach(function() {
utils.beforeEach(this); // eslint-disable-line no-invalid-this
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
room = new Room(roomId);
// mock RoomStates
room.oldState = room.getLiveTimeline()._startState =
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/scheduler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("MatrixScheduler", function() {
});

beforeEach(function() {
utils.beforeEach(this); // eslint-disable-line no-invalid-this
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
clock = lolex.install();
scheduler = new MatrixScheduler(function(ev, attempts, err) {
if (retryFn) {
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/sync-accumulator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe("SyncAccumulator", function() {
let sa;

beforeEach(function() {
utils.beforeEach(this); // eslint-disable-line no-invalid-this
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
sa = new SyncAccumulator({
maxTimelineEntries: 10,
});
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/timeline-window.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function createLinkedTimelines() {

describe("TimelineIndex", function() {
beforeEach(function() {
utils.beforeEach(this); // eslint-disable-line no-invalid-this
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
});

describe("minIndex", function() {
Expand Down Expand Up @@ -164,7 +164,7 @@ describe("TimelineWindow", function() {
}

beforeEach(function() {
utils.beforeEach(this); // eslint-disable-line no-invalid-this
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
});

describe("load", function() {
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/user.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("User", function() {
let user;

beforeEach(function() {
utils.beforeEach(this); // eslint-disable-line no-invalid-this
utils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
user = new User(userId);
});

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import expect from 'expect';

describe("utils", function() {
beforeEach(function() {
testUtils.beforeEach(this); // eslint-disable-line no-invalid-this
testUtils.beforeEach(this); // eslint-disable-line babel/no-invalid-this
});

describe("encodeParams", function() {
Expand Down
2 changes: 1 addition & 1 deletion src/store/indexeddb.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

/* eslint-disable no-invalid-this */
/* eslint-disable babel/no-invalid-this */

import Promise from 'bluebird';
import {MemoryStore} from "./memory";
Expand Down
Loading

0 comments on commit e0f9f62

Please sign in to comment.