From 01d4dcdcd2e1ce6b8073b9491e722132b307a04e Mon Sep 17 00:00:00 2001 From: Andy Date: Wed, 10 Jan 2018 15:01:26 -0800 Subject: [PATCH] Fix 'no-dynamic-delete' lint failures (#22822) --- .../documentdb-server-tests.ts | 4 +-- types/domurl/domurl-tests.ts | 2 -- types/jsurl/jsurl-tests.ts | 2 -- types/mongoose/v3/mongoose-tests.ts | 4 +-- .../react-virtualized-tests.tsx | 12 +++----- types/screeps/screeps-tests.ts | 2 +- types/sizzle/sizzle-tests.ts | 6 ++-- types/ssh2/ssh2-tests.ts | 10 +++---- types/viewporter/viewporter-tests.ts | 29 ++++++++++--------- 9 files changed, 33 insertions(+), 38 deletions(-) diff --git a/types/documentdb-server/documentdb-server-tests.ts b/types/documentdb-server/documentdb-server-tests.ts index d4e8e7f40c..cc7c97e07c 100644 --- a/types/documentdb-server/documentdb-server-tests.ts +++ b/types/documentdb-server/documentdb-server-tests.ts @@ -614,7 +614,7 @@ function updateSproc(id: string, update: Object) { } else if (document[existingFieldName]) { // If the field exists, set/overwrite the new field name and unset the existing field name. document[newFieldName] = document[existingFieldName]; - delete document[existingFieldName]; + delete document[existingFieldName]; // tslint:disable-line no-dynamic-delete } else { // Otherwise this is a noop. } @@ -641,7 +641,7 @@ function updateSproc(id: string, update: Object) { if (update.$unset) { fields = Object.keys(update.$unset); for (i = 0; i < fields.length; i++) { - delete document[fields[i]]; + delete document[fields[i]]; // tslint:disable-line no-dynamic-delete } } } diff --git a/types/domurl/domurl-tests.ts b/types/domurl/domurl-tests.ts index ff7f3c11c6..2de93bcc20 100644 --- a/types/domurl/domurl-tests.ts +++ b/types/domurl/domurl-tests.ts @@ -38,8 +38,6 @@ else { // if not an array but scalar value here is a way how to convert to array // The way to remove the parameter: delete u.query.a; -// or: -delete u.query["a"]; // If you need to remove all query string params: console.log(u.clearQuery()); diff --git a/types/jsurl/jsurl-tests.ts b/types/jsurl/jsurl-tests.ts index abdbb45851..a8adcfa90c 100644 --- a/types/jsurl/jsurl-tests.ts +++ b/types/jsurl/jsurl-tests.ts @@ -40,8 +40,6 @@ else { // if not an array but scalar value here is a way how to convert to array // The way to remove the parameter: delete u.query.a -// or: -delete u.query["a"] // If you need to remove all query string params: u.query.clear(); diff --git a/types/mongoose/v3/mongoose-tests.ts b/types/mongoose/v3/mongoose-tests.ts index 8a0f4896d4..ee56b9cc1b 100644 --- a/types/mongoose/v3/mongoose-tests.ts +++ b/types/mongoose/v3/mongoose-tests.ts @@ -143,8 +143,8 @@ Model.findOne({ name: 'john' }, (err: any, doc: mongoose.Document) => { doc.toJSON({ getters: true, virtuals: false }); var data: any = doc.toObject(); - delete data['age']; - delete data['weight']; + delete data['age']; // tslint:disable-line no-dynamic-delete + delete data['weight']; // tslint:disable-line no-dynamic-delete data['isAwesome'] = true; }); diff --git a/types/react-virtualized/react-virtualized-tests.tsx b/types/react-virtualized/react-virtualized-tests.tsx index e0bd1d50ed..c5958ab96c 100644 --- a/types/react-virtualized/react-virtualized-tests.tsx +++ b/types/react-virtualized/react-virtualized-tests.tsx @@ -654,13 +654,11 @@ const STATUS_LOADING = 1 const STATUS_LOADED = 2 export class InfiniteLoaderExample extends PureComponent { - _timeoutIdMap: any; + _timeoutIds = new Set(); constructor(props) { super(props) - this._timeoutIdMap = {} - this._clearData = this._clearData.bind(this) this._isRowLoaded = this._isRowLoaded.bind(this) this._loadMoreRows = this._loadMoreRows.bind(this) @@ -668,9 +666,7 @@ export class InfiniteLoaderExample extends PureComponent { } componentWillUnmount() { - Object.keys(this._timeoutIdMap).forEach(timeoutId => { - clearTimeout(timeoutId as any) - }) + this._timeoutIds.forEach(clearTimeout); } render() { @@ -731,7 +727,7 @@ export class InfiniteLoaderExample extends PureComponent { const timeoutId = setTimeout(() => { const { loadedRowCount, loadingRowCount } = this.state - delete this._timeoutIdMap[timeoutId] + this._timeoutIds.delete(timeoutId); for (let i = startIndex; i <= stopIndex; i++) { loadedRowsMap[i] = STATUS_LOADED @@ -745,7 +741,7 @@ export class InfiniteLoaderExample extends PureComponent { promiseResolver() }, 1000 + Math.round(Math.random() * 2000)) - this._timeoutIdMap[timeoutId] = true + this._timeoutIds.add(timeoutId); let promiseResolver diff --git a/types/screeps/screeps-tests.ts b/types/screeps/screeps-tests.ts index a308ebeb0b..5b518c8336 100644 --- a/types/screeps/screeps-tests.ts +++ b/types/screeps/screeps-tests.ts @@ -354,7 +354,7 @@ interface CreepMemory { const interShardData = JSON.parse(RawMemory.interShardSegment); if (interShardData.creeps[creep.name]) { creep.memory = interShardData[creep.name]; - delete interShardData.creeps[creep.name]; + delete interShardData.creeps[creep.name]; // tslint:disable-line no-dynamic-delete } RawMemory.interShardSegment = JSON.stringify(interShardData); diff --git a/types/sizzle/sizzle-tests.ts b/types/sizzle/sizzle-tests.ts index 3c6d17dc64..0662380942 100644 --- a/types/sizzle/sizzle-tests.ts +++ b/types/sizzle/sizzle-tests.ts @@ -47,8 +47,8 @@ function setFilters_0() { } function setFilters_1(oldPOS: RegExp) { - Sizzle.selectors.match['POS'] = new RegExp(oldPOS.source.replace('first', 'uno'), 'gi'); - Sizzle.selectors.setFilters['uno'] = Sizzle.selectors.setFilters['first']; - delete Sizzle.selectors.setFilters['first']; + Sizzle.selectors.match.POS = new RegExp(oldPOS.source.replace('first', 'uno'), 'gi'); + Sizzle.selectors.setFilters.uno = Sizzle.selectors.setFilters.first; + delete Sizzle.selectors.setFilters.first; Sizzle('div:uno'); // ==> [
] } diff --git a/types/ssh2/ssh2-tests.ts b/types/ssh2/ssh2-tests.ts index 1244ccb3fa..e6d03e939f 100644 --- a/types/ssh2/ssh2-tests.ts +++ b/types/ssh2/ssh2-tests.ts @@ -388,7 +388,7 @@ new ssh2.Server({ var session = accept(); session.on('sftp', (accept: any, reject: any) => { console.log('Client SFTP session'); - var openFiles: any = {}; + var openFiles = new Set(); var handleCount = 0; // `sftpStream` is an `SFTPStream` instance in server mode // see: https://github.com/mscdex/ssh2-streams/blob/master/SFTPStream.md @@ -401,12 +401,12 @@ new ssh2.Server({ // be a real file descriptor number for example if actually opening // the file on the disk var handle = new Buffer(4); - openFiles[handleCount] = true; + openFiles.add(handleCount); handle.writeUInt32BE(handleCount++, 0, true); sftpStream.handle(reqid, handle); console.log('Opening file for write') }).on('WRITE', (reqid: any, handle: any, offset: any, data: any) => { - if (handle.length !== 4 || !openFiles[handle.readUInt32BE(0, true)]) + if (handle.length !== 4 || !openFiles.has(handle.readUInt32BE(0, true))) return sftpStream.status(reqid, STATUS_CODE.FAILURE); // fake the write sftpStream.status(reqid, STATUS_CODE.OK); @@ -414,9 +414,9 @@ new ssh2.Server({ console.log('Write to file at offset %d: %s', offset, inspected); }).on('CLOSE', (reqid: any, handle: any) => { var fnum: any; - if (handle.length !== 4 || !openFiles[(fnum = handle.readUInt32BE(0, true))]) + if (handle.length !== 4 || !openFiles.has((fnum = handle.readUInt32BE(0, true)))) return sftpStream.status(reqid, STATUS_CODE.FAILURE); - delete openFiles[fnum]; + openFiles.delete(fnum); sftpStream.status(reqid, STATUS_CODE.OK); console.log('Closing file'); }); diff --git a/types/viewporter/viewporter-tests.ts b/types/viewporter/viewporter-tests.ts index 15997f9425..94df0749fa 100644 --- a/types/viewporter/viewporter-tests.ts +++ b/types/viewporter/viewporter-tests.ts @@ -109,7 +109,7 @@ function test_swipey() { var canvas = $('canvas')[0]; var context = canvas.getContext('2d'); var iOS = (/iphone|ipad/i).test(navigator.userAgent); - var pointers = {}; + var pointers = new Map(); // handle resizing / rotating of the viewport var width, height; $(window).bind(viewporter.ACTIVE ? 'viewportchange' : 'resize', function () { @@ -123,11 +123,12 @@ function test_swipey() { for (var i = 0; i < touches.length; i++) { identifier = touches[i].identifier || 'mouse'; // if no pointer has been created for this finger yet, do it - if (!pointers[identifier]) { - pointers[identifier] = new drawingPointer(context, rainbow(8, Object.keys(pointers).length)); + let pointer = pointers.get(identifier); + if (!pointer) { + pointers.set(identifier, pointer = new drawingPointer(context, rainbow(8, Object.keys(pointers).length))); } - pointers[identifier].start(); - pointers[identifier].addPoint(touches[i].pageX, touches[i].pageY); + pointer.start(); + pointer.addPoint(touches[i].pageX, touches[i].pageY); } }); @@ -136,8 +137,9 @@ function test_swipey() { var identifier; for (var i = 0; i < touches.length; i++) { identifier = touches[i].identifier || 'mouse'; - if (pointers[identifier] && pointers[identifier].painting) { - pointers[identifier].addPoint(touches[i].pageX, touches[i].pageY, true); + const pointer = pointers.get(identifier); + if (pointer && pointer.painting) { + pointer.addPoint(touches[i].pageX, touches[i].pageY, true); } } }); @@ -147,11 +149,12 @@ function test_swipey() { var identifier; for (var i = 0; i < touches.length; i++) { identifier = touches[i].identifier || 'mouse'; - if (pointers[identifier]) { - pointers[identifier].stop(); + const pointer = pointers.get(identifier); + if (pointer) { + pointer.stop(); (function (identifier) { setTimeout(function () { - delete pointers[identifier]; + pointers.delete(identifier); }, 300); })(identifier); } @@ -161,10 +164,10 @@ function test_swipey() { window.setInterval(function () { context.clearRect(0, 0, width, height); var counter = 0, ratio = (window).devicePixelRatio || 1; - for (var identifier in pointers) { - pointers[identifier].redraw(); + pointers.forEach(pointer => { + pointer.redraw(); counter++; - } + }); context.font = (10 * ratio) + 'pt Arial'; context.fillText(counter + ' active pointers', 15 * ratio, 25 * ratio);