Просмотр исходного кода

fix(eslint): Add guard-for-in rule

master
hristoterezov 8 лет назад
Родитель
Сommit
99d121e906

+ 1
- 0
.eslintrc.js Просмотреть файл

@@ -76,6 +76,7 @@ module.exports = {
76 76
         'default-case': 0,
77 77
         'dot-location': [ 'error', 'property' ],
78 78
         'dot-notation': 2,
79
+        'guard-for-in': 2,
79 80
         'no-caller': 2,
80 81
         'no-case-declarations': 2,
81 82
         'no-div-regex': 0,

+ 6
- 8
JitsiConferenceEventManager.js Просмотреть файл

@@ -69,20 +69,18 @@ JitsiConferenceEventManager.prototype.setupChatRoomListeners = function() {
69 69
     // send some analytics events
70 70
     chatRoom.addListener(XMPPEvents.MUC_JOINED,
71 71
         () => {
72
-            let key, value;
73
-
74 72
             this.conference.connectionIsInterrupted = false;
75 73
 
76
-            for (key in chatRoom.connectionTimes) {
77
-                value = chatRoom.connectionTimes[key];
74
+            Object.keys(chatRoom.connectionTimes).forEach(key => {
75
+                const value = chatRoom.connectionTimes[key];
78 76
                 Statistics.analytics.sendEvent('conference.' + key,
79 77
                     {value});
80
-            }
81
-            for (key in chatRoom.xmpp.connectionTimes) {
82
-                value = chatRoom.xmpp.connectionTimes[key];
78
+            });
79
+            Object.keys(chatRoom.xmpp.connectionTimes).forEach(key => {
80
+                const value = chatRoom.xmpp.connectionTimes[key];
83 81
                 Statistics.analytics.sendEvent('xmpp.' + key,
84 82
                     {value});
85
-            }
83
+            });
86 84
         });
87 85
 
88 86
     this.chatRoomForwarder.forward(XMPPEvents.ROOM_JOIN_ERROR,

+ 6
- 6
JitsiMeetJS.js Просмотреть файл

@@ -37,13 +37,13 @@ function getLowerResolution(resolution) {
37 37
     var order = Resolutions[resolution].order;
38 38
     var res = null;
39 39
     var resName = null;
40
-    for(const i in Resolutions) {
41
-        var tmp = Resolutions[i];
42
-        if (!res || (res.order < tmp.order && tmp.order < order)) {
43
-            resName = i;
44
-            res = tmp;
40
+    Object.keys(Resolutions).forEach(resolution => {
41
+        const value = Resolutions[resolution];
42
+        if (!res || (res.order < value.order && value.order < order)) {
43
+            resName = resolution;
44
+            res = value;
45 45
         }
46
-    }
46
+    });
47 47
     return resName;
48 48
 }
49 49
 

+ 7
- 1
modules/statistics/RTPStatsCollector.js Просмотреть файл

@@ -392,6 +392,9 @@ StatsCollector.prototype.processStatsReport = function() {
392 392
     var byteSentStats = {};
393 393
 
394 394
     for (var idx in this.currentStatsReport) {
395
+        if(!this.currentStatsReport.hasOwnProperty(idx)) {
396
+            continue;
397
+        }
395 398
         var now = this.currentStatsReport[idx];
396 399
         try {
397 400
             var receiveBandwidth = getStatValue(now, 'receiveBandwidth');
@@ -605,7 +608,10 @@ StatsCollector.prototype.processAudioLevelReport = function() {
605 608
 
606 609
     var getStatValue = this._getStatValue;
607 610
 
608
-    for (var idx in this.currentAudioLevelsReport) {
611
+    for(var idx in this.currentAudioLevelsReport) {
612
+        if(!this.currentAudioLevelsReport.hasOwnProperty(idx)) {
613
+            continue;
614
+        }
609 615
         var now = this.currentAudioLevelsReport[idx];
610 616
 
611 617
         if (now.type != 'ssrc') {

+ 3
- 3
modules/xmpp/Caps.js Просмотреть файл

@@ -47,9 +47,9 @@ export default class Caps extends Listenable {
47 47
             room => this._addChatRoom(room));
48 48
         emuc.addListener(XMPPEvents.EMUC_ROOM_REMOVED,
49 49
             room => this._removeChatRoom(room));
50
-        for(const jid in emuc.rooms) {
51
-            this._addChatRoom(this.emuc.rooms[jid]);
52
-        }
50
+        Object.keys(emuc.rooms).forEach(jid => {
51
+            this._addChatRoom(emuc.rooms[jid]);
52
+        });
53 53
 
54 54
         Strophe.addNamespace('CAPS', 'http://jabber.org/protocol/caps');
55 55
         this.disco.addFeature(Strophe.NS.CAPS);

+ 7
- 7
modules/xmpp/ChatRoom.js Просмотреть файл

@@ -507,19 +507,19 @@ export default class ChatRoom extends Listenable {
507 507
         var isKick = $(pres).find(
508 508
                 '>x[xmlns="http://jabber.org/protocol/muc#user"]>status[code="307"]'
509 509
             ).length !== 0;
510
-
510
+        const membersKeys = Object.keys(this.members);
511 511
         if (!isSelfPresence) {
512 512
             delete this.members[from];
513 513
             this.onParticipantLeft(from, false);
514
-        } else if (Object.keys(this.members).length > 0) {
514
+        } else if (membersKeys.length > 0) {
515 515
             // If the status code is 110 this means we're leaving and we would
516 516
             // like to remove everyone else from our view, so we trigger the
517 517
             // event.
518
-            for (const i in this.members) {
519
-                const member = this.members[i];
520
-                delete this.members[i];
521
-                this.onParticipantLeft(i, member.isFocus);
522
-            }
518
+            membersKeys.forEach(jid => {
519
+                const member = this.members[jid];
520
+                delete this.members[jid];
521
+                this.onParticipantLeft(jid, member.isFocus);
522
+            });
523 523
             this.connection.emuc.doLeave(this.roomjid);
524 524
 
525 525
             // we fire muc_left only if this is not a kick,

Загрузка…
Отмена
Сохранить