Skip to content

Commit

Permalink
Merge pull request #3456 from matrix-org/t3chguy/delint
Browse files Browse the repository at this point in the history
Some delinting
  • Loading branch information
t3chguy committed Sep 18, 2019
2 parents 58c333f + e502558 commit 020f15c
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 69 deletions.
25 changes: 1 addition & 24 deletions .eslintignore.errorfiles
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# autogenerated file: run scripts/generate-eslint-error-ignore-file to update.

src/component-index.js
src/components/structures/BottomLeftMenu.js
src/components/structures/CreateRoom.js
src/components/structures/RoomDirectory.js
src/components/structures/RoomStatusBar.js
src/components/structures/RoomView.js
Expand All @@ -18,70 +16,49 @@ src/components/views/dialogs/UnknownDeviceDialog.js
src/components/views/elements/AddressSelector.js
src/components/views/elements/DirectorySearchBox.js
src/components/views/elements/MemberEventListSummary.js
src/components/views/elements/TintableSvg.js
src/components/views/elements/UserSelector.js
src/components/views/globals/MatrixToolbar.js
src/components/views/globals/NewVersionBar.js
src/components/views/globals/UpdateCheckBar.js
src/components/views/messages/MFileBody.js
src/components/views/messages/RoomAvatarEvent.js
src/components/views/messages/TextualBody.js
src/components/views/room_settings/ColorSettings.js
src/components/views/rooms/Autocomplete.js
src/components/views/rooms/AuxPanel.js
src/components/views/rooms/EntityTile.js
src/components/views/rooms/LinkPreviewWidget.js
src/components/views/rooms/MemberDeviceInfo.js
src/components/views/rooms/MemberInfo.js
src/components/views/rooms/MemberList.js
src/components/views/rooms/SlateMessageComposer.js
src/components/views/rooms/PinnedEventTile.js
src/components/views/rooms/RoomList.js
src/components/views/rooms/RoomPreviewBar.js
src/components/views/rooms/SearchableEntityList.js
src/components/views/rooms/SearchBar.js
src/components/views/rooms/SearchResultTile.js
src/components/views/rooms/TopUnreadMessagesBar.js
src/components/views/rooms/UserTile.js
src/components/views/rooms/SlateMessageComposer.js
src/components/views/settings/ChangeAvatar.js
src/components/views/settings/ChangePassword.js
src/components/views/settings/DevicesPanel.js
src/components/views/settings/Notifications.js
src/GroupAddressPicker.js
src/HtmlUtils.js
src/ImageUtils.js
src/linkify-matrix.js
src/Markdown.js
src/MatrixClientPeg.js
src/notifications/ContentRules.js
src/notifications/PushRuleVectorState.js
src/notifications/VectorPushRulesDefinitions.js
src/Notifier.js
src/PlatformPeg.js
src/Presence.js
src/rageshake/rageshake.js
src/rageshake/submit-rageshake.js
src/ratelimitedfunc.js
src/Roles.js
src/Rooms.js
src/UiEffects.js
src/Unread.js
src/utils/DecryptFile.js
src/utils/DirectoryUtils.js
src/utils/DMRoomMap.js
src/utils/FormattingUtils.js
src/utils/MultiInviter.js
src/utils/Receipt.js
src/VectorConferenceHandler.js
src/Velociraptor.js
src/WhoIsTyping.js
src/wrappers/withMatrixClient.js
test/components/structures/MessagePanel-test.js
test/components/structures/ScrollPanel-test.js
test/components/structures/TimelinePanel-test.js
test/components/views/dialogs/InteractiveAuthDialog-test.js
test/components/views/rooms/MessageComposerInput-test.js
test/components/views/rooms/RoomSettings-test.js
test/mock-clock.js
test/notifications/ContentRules-test.js
test/notifications/PushRuleVectorState-test.js
Expand Down
15 changes: 6 additions & 9 deletions src/MatrixClientPeg.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

'use strict';

import Matrix from 'matrix-js-sdk';
import {MatrixClient, MemoryStore} from 'matrix-js-sdk';

import utils from 'matrix-js-sdk/lib/utils';
import EventTimeline from 'matrix-js-sdk/lib/models/event-timeline';
Expand All @@ -27,7 +25,6 @@ import sdk from './index';
import createMatrixClient from './utils/createMatrixClient';
import SettingsStore from './settings/SettingsStore';
import MatrixActionCreators from './actions/MatrixActionCreators';
import {phasedRollOutExpiredForUser} from "./PhasedRollOut";
import Modal from './Modal';
import {verificationMethods} from 'matrix-js-sdk/lib/crypto';
import MatrixClientBackedSettingsHandler from "./settings/handlers/MatrixClientBackedSettingsHandler";
Expand Down Expand Up @@ -87,7 +84,7 @@ class MatrixClientPeg {
MatrixActionCreators.stop();
}

/*
/**
* If we've registered a user ID we set this to the ID of the
* user we've just registered. If they then go & log in, we
* can send them to the welcome user (obviously this doesn't
Expand All @@ -99,7 +96,7 @@ class MatrixClientPeg {
this._justRegisteredUserId = uid;
}

/*
/**
* Returns true if the current user has just been registered by this
* client as determined by setJustRegisteredUserId()
*
Expand All @@ -112,7 +109,7 @@ class MatrixClientPeg {
);
}

/**
/*
* Replace this MatrixClientPeg's client with a client instance that has
* homeserver / identity server URLs and active credentials
*/
Expand All @@ -131,7 +128,7 @@ class MatrixClientPeg {
} catch (err) {
if (dbType === 'indexeddb') {
console.error('Error starting matrixclient store - falling back to memory store', err);
this.matrixClient.store = new Matrix.MemoryStore({
this.matrixClient.store = new MemoryStore({
localStorage: global.localStorage,
});
} else {
Expand Down Expand Up @@ -195,7 +192,7 @@ class MatrixClientPeg {
};
}

/**
/*
* Return the server name of the user's homeserver
* Throws an error if unable to deduce the homeserver name
* (eg. if the user is not logged in)
Expand Down
5 changes: 3 additions & 2 deletions src/Notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const Notifier = {
console.warn(`${roomId} has custom notification sound event, but no url key`);
return null;
}

if (!content.url.startsWith("mxc://")) {
console.warn(`${roomId} has custom notification sound event, but url is not a mxc url`);
return null;
Expand Down Expand Up @@ -203,7 +203,8 @@ const Notifier = {
// The permission request was dismissed or denied
// TODO: Support alternative branding in messaging
const description = result === 'denied'
? _t('Riot does not have permission to send you notifications - please check your browser settings')
? _t('Riot does not have permission to send you notifications - ' +
'please check your browser settings')
: _t('Riot was not given permission to send notifications - please try again');
const ErrorDialog = sdk.getComponent('dialogs.ErrorDialog');
Modal.createTrackedDialog('Unable to enable Notifications', result, ErrorDialog, {
Expand Down
13 changes: 6 additions & 7 deletions src/Presence.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

const MatrixClientPeg = require("./MatrixClientPeg");
const dis = require("./dispatcher");
import MatrixClientPeg from "./MatrixClientPeg";
import dis from "./dispatcher";
import Timer from './utils/Timer';

// Time in ms after that a user is considered as unavailable/away
const UNAVAILABLE_TIME_MS = 3 * 60 * 1000; // 3 mins
const PRESENCE_STATES = ["online", "offline", "unavailable"];

class Presence {

constructor() {
this._activitySignal = null;
this._unavailableTimer = null;
Expand All @@ -43,7 +42,7 @@ class Presence {
try {
await this._unavailableTimer.finished();
this.setState("unavailable");
} catch(e) { /* aborted, stop got called */ }
} catch (e) { /* aborted, stop got called */ }
}
}

Expand Down Expand Up @@ -88,7 +87,7 @@ class Presence {
if (PRESENCE_STATES.indexOf(newState) === -1) {
throw new Error("Bad presence state: " + newState);
}
const old_state = this.state;
const oldState = this.state;
this.state = newState;

if (MatrixClientPeg.get().isGuest()) {
Expand All @@ -98,9 +97,9 @@ class Presence {
try {
await MatrixClientPeg.get().setPresence(this.state);
console.log("Presence: %s", newState);
} catch(err) {
} catch (err) {
console.error("Failed to set presence: %s", err);
this.state = old_state;
this.state = oldState;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function levelRoleMap(usersDefault) {
}

export function textualPowerLevel(level, usersDefault) {
const LEVEL_ROLE_MAP = this.levelRoleMap(usersDefault);
const LEVEL_ROLE_MAP = levelRoleMap(usersDefault);
if (LEVEL_ROLE_MAP[level]) {
return LEVEL_ROLE_MAP[level] + (level !== undefined ? ` (${level})` : ` (${usersDefault})`);
} else {
Expand Down
12 changes: 5 additions & 7 deletions src/VectorConferenceHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

"use strict";

import Promise from 'bluebird';
const Matrix = require("matrix-js-sdk");
const Room = Matrix.Room;
const CallHandler = require('./CallHandler');
import {createNewMatrixCall, Room} from "matrix-js-sdk";
import CallHandler from './CallHandler';
import MatrixClientPeg from "./MatrixClientPeg";

// FIXME: this is Riot (Vector) specific code, but will be removed shortly when
// we switch over to jitsi entirely for video conferencing.
Expand All @@ -45,7 +43,7 @@ ConferenceCall.prototype.setup = function() {
// return a call for *this* room to be placed. We also tack on
// confUserId to speed up lookups (else we'd need to loop every room
// looking for a 1:1 room with this conf user ID!)
const call = Matrix.createNewMatrixCall(self.client, room.roomId);
const call = createNewMatrixCall(self.client, room.roomId);
call.confUserId = self.confUserId;
call.groupRoomId = self.groupRoomId;
return call;
Expand Down Expand Up @@ -84,7 +82,7 @@ ConferenceCall.prototype._getConferenceUserRoom = function() {
preset: "private_chat",
invite: [this.confUserId],
}).then(function(res) {
return new Room(res.room_id, null, client.getUserId());
return new Room(res.room_id, null, MatrixClientPeg.get().getUserId());
});
};

Expand Down
16 changes: 11 additions & 5 deletions src/WhoIsTyping.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

const MatrixClientPeg = require("./MatrixClientPeg");
import MatrixClientPeg from "./MatrixClientPeg";
import { _t } from './languageHandler';

module.exports = {
Expand All @@ -33,6 +33,9 @@ module.exports = {
/**
* Given a Room object and, optionally, a list of userID strings
* to exclude, return a list of user objects who are typing.
* @param {Room} room: room object to get users from.
* @param {string[]} exclude: list of user mxids to exclude.
* @returns {string[]} list of user objects who are typing.
*/
usersTyping: function(room, exclude) {
const whoIsTyping = [];
Expand All @@ -46,7 +49,7 @@ module.exports = {
const userId = memberKeys[i];

if (room.currentState.members[userId].typing) {
if (exclude.indexOf(userId) == -1) {
if (exclude.indexOf(userId) === -1) {
whoIsTyping.push(room.currentState.members[userId]);
}
}
Expand All @@ -60,16 +63,19 @@ module.exports = {
if (whoIsTyping.length > limit) {
othersCount = whoIsTyping.length - limit + 1;
}
if (whoIsTyping.length == 0) {
if (whoIsTyping.length === 0) {
return '';
} else if (whoIsTyping.length == 1) {
} else if (whoIsTyping.length === 1) {
return _t('%(displayName)s is typing …', {displayName: whoIsTyping[0].name});
}
const names = whoIsTyping.map(function(m) {
return m.name;
});
if (othersCount>=1) {
return _t('%(names)s and %(count)s others are typing …', {names: names.slice(0, limit - 1).join(', '), count: othersCount});
return _t('%(names)s and %(count)s others are typing …', {
names: names.slice(0, limit - 1).join(', '),
count: othersCount,
});
} else {
const lastPerson = names.pop();
return _t('%(names)s and %(lastPerson)s are typing …', {names: names.join(', '), lastPerson: lastPerson});
Expand Down
28 changes: 14 additions & 14 deletions src/linkify-matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function matrixLinkify(linkify) {
const S_ROOMALIAS_COLON = new linkify.parser.State();
const S_ROOMALIAS_COLON_NUM = new linkify.parser.State(ROOMALIAS);

const roomname_tokens = [
const roomnameTokens = [
TT.DOT,
TT.PLUS,
TT.NUM,
Expand All @@ -58,8 +58,8 @@ function matrixLinkify(linkify) {
TT.LOCALHOST,
];

S_HASH.on(roomname_tokens, S_HASH_NAME);
S_HASH_NAME.on(roomname_tokens, S_HASH_NAME);
S_HASH.on(roomnameTokens, S_HASH_NAME);
S_HASH_NAME.on(roomnameTokens, S_HASH_NAME);
S_HASH_NAME.on(TT.DOMAIN, S_HASH_NAME);

S_HASH_NAME.on(TT.COLON, S_HASH_NAME_COLON);
Expand Down Expand Up @@ -92,20 +92,20 @@ function matrixLinkify(linkify) {
const S_USERID_COLON = new linkify.parser.State();
const S_USERID_COLON_NUM = new linkify.parser.State(USERID);

const username_tokens = [
const usernameTokens = [
TT.DOT,
TT.UNDERSCORE,
TT.PLUS,
TT.NUM,
TT.DOMAIN,
TT.TLD,

// as in roomname_tokens
// as in roomnameTokens
TT.LOCALHOST,
];

S_AT.on(username_tokens, S_AT_NAME);
S_AT_NAME.on(username_tokens, S_AT_NAME);
S_AT.on(usernameTokens, S_AT_NAME);
S_AT_NAME.on(usernameTokens, S_AT_NAME);
S_AT_NAME.on(TT.DOMAIN, S_AT_NAME);

S_AT_NAME.on(TT.COLON, S_AT_NAME_COLON);
Expand Down Expand Up @@ -138,20 +138,20 @@ function matrixLinkify(linkify) {
const S_GROUPID_COLON = new linkify.parser.State();
const S_GROUPID_COLON_NUM = new linkify.parser.State(GROUPID);

const groupid_tokens = [
const groupIdTokens = [
TT.DOT,
TT.UNDERSCORE,
TT.PLUS,
TT.NUM,
TT.DOMAIN,
TT.TLD,

// as in roomname_tokens
// as in roomnameTokens
TT.LOCALHOST,
];

S_PLUS.on(groupid_tokens, S_PLUS_NAME);
S_PLUS_NAME.on(groupid_tokens, S_PLUS_NAME);
S_PLUS.on(groupIdTokens, S_PLUS_NAME);
S_PLUS_NAME.on(groupIdTokens, S_PLUS_NAME);
S_PLUS_NAME.on(TT.DOMAIN, S_PLUS_NAME);

S_PLUS_NAME.on(TT.COLON, S_PLUS_NAME_COLON);
Expand Down Expand Up @@ -179,14 +179,14 @@ const escapeRegExp = function(string) {

// Recognise URLs from both our local vector and official vector as vector.
// anyone else really should be using matrix.to.
matrixLinkify.VECTOR_URL_PATTERN = "^(?:https?:\/\/)?(?:"
matrixLinkify.VECTOR_URL_PATTERN = "^(?:https?://)?(?:"
+ escapeRegExp(window.location.host + window.location.pathname) + "|"
+ "(?:www\\.)?(?:riot|vector)\\.im/(?:app|beta|staging|develop)/"
+ ")(#.*)";

matrixLinkify.MATRIXTO_URL_PATTERN = "^(?:https?:\/\/)?(?:www\\.)?matrix\\.to/#/(([#@!+]).*)";
matrixLinkify.MATRIXTO_URL_PATTERN = "^(?:https?://)?(?:www\\.)?matrix\\.to/#/(([#@!+]).*)";
matrixLinkify.MATRIXTO_MD_LINK_PATTERN =
'\\[([^\\]]*)\\]\\((?:https?:\/\/)?(?:www\\.)?matrix\\.to/#/([#@!+][^\\)]*)\\)';
'\\[([^\\]]*)\\]\\((?:https?://)?(?:www\\.)?matrix\\.to/#/([#@!+][^\\)]*)\\)';
matrixLinkify.MATRIXTO_BASE_URL= baseUrl;

const matrixToEntityMap = {
Expand Down

0 comments on commit 020f15c

Please sign in to comment.