Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update build process for ES6 #320

Merged
merged 10 commits into from
Jan 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -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"],
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we enable http://eslint.org/docs/rules/require-jsdoc and http://eslint.org/docs/rules/valid-jsdoc? It would be a shame if we started slipping into bad habits with the jsdoc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly, turning these on produces 537 warnings, so presumably it's somewhat stricter than jshint :/

Should we turn them on and aspire to fix the warnings?

}
11 changes: 0 additions & 11 deletions .jshint

This file was deleted.

9 changes: 2 additions & 7 deletions jenkins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions spec/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
env: {
jasmine: true,
},
}
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 @@ -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();
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 @@ -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({
Expand Down
7 changes: 3 additions & 4 deletions spec/integ/matrix-client-event-timeline.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -415,15 +415,14 @@ 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);
tl0 = tl;
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);
Expand Down
4 changes: 2 additions & 2 deletions spec/integ/matrix-client-methods.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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" },
});
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 @@ -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();
});

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 @@ -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();
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 @@ -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({
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 @@ -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({
Expand Down
10 changes: 8 additions & 2 deletions spec/integ/megolm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion spec/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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 @@ -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() {
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 @@ -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 }};
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 @@ -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);
});

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 @@ -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) {
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 @@ -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",
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 @@ -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; });
Expand Down Expand Up @@ -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);
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 @@ -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);
});

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 @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/room.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions spec/unit/scheduler.spec.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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) {
Expand Down
Loading