Enforce line max length of 100

This commit is contained in:
Juanjo Diaz 2018-07-14 01:27:29 +02:00
parent 14e900c4ae
commit b527d65c14
8 changed files with 77 additions and 33 deletions

View File

@ -213,13 +213,13 @@
// specify the maximum length of a line in your program // specify the maximum length of a line in your program
// https://eslint.org/docs/rules/max-len // https://eslint.org/docs/rules/max-len
// "max-len": ["error", 100, 2, { "max-len": ["error", 100, 2, {
// ignoreUrls: true, ignoreUrls: true,
// ignoreComments: false, ignoreComments: false,
// ignoreRegExpLiterals: true, ignoreRegExpLiterals: true,
// ignoreStrings: true, ignoreStrings: true,
// ignoreTemplateLiterals: true, ignoreTemplateLiterals: true,
// }], }],
// specify the max number of lines in a file // specify the max number of lines in a file
// https://eslint.org/docs/rules/max-lines // https://eslint.org/docs/rules/max-lines

View File

@ -576,7 +576,11 @@ export default class Display {
// NB(directxman12): arr must be an Type Array view // NB(directxman12): arr must be an Type Array view
let img; let img;
if (SUPPORTS_IMAGEDATA_CONSTRUCTOR) { if (SUPPORTS_IMAGEDATA_CONSTRUCTOR) {
img = new ImageData(new Uint8ClampedArray(arr.buffer, arr.byteOffset, width * height * 4), width, height); img = new ImageData(
new Uint8ClampedArray(arr.buffer, arr.byteOffset, width * height * 4),
width,
height
);
} else { } else {
img = this._drawCtx.createImageData(width, height); img = this._drawCtx.createImageData(width, height);
img.data.set(new Uint8ClampedArray(arr.buffer, arr.byteOffset, width * height * 4)); img.data.set(new Uint8ClampedArray(arr.buffer, arr.byteOffset, width * height * 4));

View File

@ -36,7 +36,7 @@ export default class Mouse {
// ===== PROPERTIES ===== // ===== PROPERTIES =====
this.touchButton = 1; // Button mask (1, 2, 4) for touch devices (0 means ignore clicks) this.touchButton = 1; // Button mask (1, 2, 4) for touch devices (0 means ignore clicks)
// ===== EVENT HANDLERS ===== // ===== EVENT HANDLERS =====

View File

@ -4,6 +4,7 @@
* To re-generate, run: * To re-generate, run:
* keymap-gen --lang=js code-map keymaps.csv html atset1 * keymap-gen --lang=js code-map keymaps.csv html atset1
*/ */
/* eslint-disable max-len */
export default { export default {
Again: 0xe005, /* html:Again (Again) -> linux:129 (KEY_AGAIN) -> atset1:57349 */ Again: 0xe005, /* html:Again (Again) -> linux:129 (KEY_AGAIN) -> atset1:57349 */
AltLeft: 0x38, /* html:AltLeft (AltLeft) -> linux:56 (KEY_LEFTALT) -> atset1:56 */ AltLeft: 0x38, /* html:AltLeft (AltLeft) -> linux:56 (KEY_LEFTALT) -> atset1:56 */

View File

@ -168,6 +168,7 @@ export default class RFB extends EventTargetMixin {
this._cursor = new Cursor(); this._cursor = new Cursor();
// populate encHandlers with bound versions // populate encHandlers with bound versions
/* eslint-disable max-len */
this._encHandlers[encodings.encodingRaw] = RFB.encodingHandlers.RAW.bind(this); this._encHandlers[encodings.encodingRaw] = RFB.encodingHandlers.RAW.bind(this);
this._encHandlers[encodings.encodingCopyRect] = RFB.encodingHandlers.COPYRECT.bind(this); this._encHandlers[encodings.encodingCopyRect] = RFB.encodingHandlers.COPYRECT.bind(this);
this._encHandlers[encodings.encodingRRE] = RFB.encodingHandlers.RRE.bind(this); this._encHandlers[encodings.encodingRRE] = RFB.encodingHandlers.RRE.bind(this);
@ -180,6 +181,7 @@ export default class RFB extends EventTargetMixin {
this._encHandlers[encodings.pseudoEncodingCursor] = RFB.encodingHandlers.Cursor.bind(this); this._encHandlers[encodings.pseudoEncodingCursor] = RFB.encodingHandlers.Cursor.bind(this);
this._encHandlers[encodings.pseudoEncodingQEMUExtendedKeyEvent] = RFB.encodingHandlers.QEMUExtendedKeyEvent.bind(this); this._encHandlers[encodings.pseudoEncodingQEMUExtendedKeyEvent] = RFB.encodingHandlers.QEMUExtendedKeyEvent.bind(this);
this._encHandlers[encodings.pseudoEncodingExtendedDesktopSize] = RFB.encodingHandlers.ExtendedDesktopSize.bind(this); this._encHandlers[encodings.pseudoEncodingExtendedDesktopSize] = RFB.encodingHandlers.ExtendedDesktopSize.bind(this);
/* eslint-enable max-len */
// NB: nothing that needs explicit teardown should be done // NB: nothing that needs explicit teardown should be done
// before this point, since this can throw an exception // before this point, since this can throw an exception
@ -787,7 +789,12 @@ export default class RFB extends EventTargetMixin {
if (this._viewOnly) { return; } // View only, skip mouse events if (this._viewOnly) { return; } // View only, skip mouse events
if (this._rfb_connection_state !== 'connected') { return; } if (this._rfb_connection_state !== 'connected') { return; }
RFB.messages.pointerEvent(this._sock, this._display.absX(x), this._display.absY(y), this._mouse_buttonMask); RFB.messages.pointerEvent(
this._sock,
this._display.absX(x),
this._display.absY(y),
this._mouse_buttonMask
);
} }
_handleMouseMove(x, y) { _handleMouseMove(x, y) {
@ -814,7 +821,12 @@ export default class RFB extends EventTargetMixin {
if (this._viewOnly) { return; } // View only, skip mouse events if (this._viewOnly) { return; } // View only, skip mouse events
if (this._rfb_connection_state !== 'connected') { return; } if (this._rfb_connection_state !== 'connected') { return; }
RFB.messages.pointerEvent(this._sock, this._display.absX(x), this._display.absY(y), this._mouse_buttonMask); RFB.messages.pointerEvent(
this._sock,
this._display.absX(x),
this._display.absY(y),
this._mouse_buttonMask
);
} }
// Message Handlers // Message Handlers
@ -1039,7 +1051,7 @@ export default class RFB extends EventTargetMixin {
// choose the notunnel type // choose the notunnel type
if (serverSupportedTunnelTypes[0]) { if (serverSupportedTunnelTypes[0]) {
if (serverSupportedTunnelTypes[0].vendor != clientSupportedTunnelTypes[0].vendor if (serverSupportedTunnelTypes[0].vendor != clientSupportedTunnelTypes[0].vendor
|| serverSupportedTunnelTypes[0].signature != clientSupportedTunnelTypes[0].signature) { || serverSupportedTunnelTypes[0].signature != clientSupportedTunnelTypes[0].signature) {
return this._fail("Client's tunnel type had the incorrect " return this._fail("Client's tunnel type had the incorrect "
+ 'vendor or signature'); + 'vendor or signature');
} }
@ -2308,7 +2320,11 @@ RFB.encodingHandlers = {
rgbx = indexedToRGBX(data, this._paletteBuff, this._FBU.width, this._FBU.height); rgbx = indexedToRGBX(data, this._paletteBuff, this._FBU.width, this._FBU.height);
} }
this._display.blitRgbxImage(this._FBU.x, this._FBU.y, this._FBU.width, this._FBU.height, rgbx, 0, false); this._display.blitRgbxImage(
this._FBU.x, this._FBU.y,
this._FBU.width, this._FBU.height,
rgbx, 0, false
);
return true; return true;
@ -2349,7 +2365,11 @@ RFB.encodingHandlers = {
data = decompress(this._sock.rQshiftBytes(cl_data), uncompressedSize); data = decompress(this._sock.rQshiftBytes(cl_data), uncompressedSize);
} }
this._display.blitRgbImage(this._FBU.x, this._FBU.y, this._FBU.width, this._FBU.height, data, 0, false); this._display.blitRgbImage(
this._FBU.x, this._FBU.y,
this._FBU.width, this._FBU.height,
data, 0, false
);
return true; return true;
}; };
@ -2404,7 +2424,11 @@ RFB.encodingHandlers = {
switch (cmode) { switch (cmode) {
case 'fill': case 'fill':
// skip ctl byte // skip ctl byte
this._display.fillRect(this._FBU.x, this._FBU.y, this._FBU.width, this._FBU.height, [rQ[rQi + 3], rQ[rQi + 2], rQ[rQi + 1]], false); this._display.fillRect(
this._FBU.x, this._FBU.y,
this._FBU.width, this._FBU.height,
[rQ[rQi + 3], rQ[rQi + 2], rQ[rQi + 1]], false
);
this._sock.rQskipBytes(4); this._sock.rQskipBytes(4);
break; break;
case 'png': case 'png':

View File

@ -13,7 +13,9 @@ describe('Display/Canvas Helper', function () {
0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255 0x00, 0xff, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0x00, 0x00, 0xff, 255
]); ]);
const basic_data = new Uint8Array([0xff, 0x00, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0xff, 0xff, 0xff, 255]); const basic_data = new Uint8Array([
0xff, 0x00, 0x00, 255, 0x00, 0xff, 0x00, 255, 0x00, 0x00, 0xff, 255, 0xff, 0xff, 0xff, 255
]);
function make_image_canvas(input_data) { function make_image_canvas(input_data) {
const canvas = document.createElement('canvas'); const canvas = document.createElement('canvas');
@ -261,8 +263,8 @@ describe('Display/Canvas Helper', function () {
}); });
describe('drawing', function () { describe('drawing', function () {
// TODO(directxman12): improve the tests for each of the drawing functions to cover more than just the // TODO(directxman12): improve the tests for each of the drawing functions to cover
// basic cases // more than just the basic cases
let display; let display;
beforeEach(function () { beforeEach(function () {
display = new Display(document.createElement('canvas')); display = new Display(document.createElement('canvas'));

View File

@ -1025,7 +1025,8 @@ describe('Remote Frame Buffer Protocol Client', function () {
expect(client._rfb_version).to.equal(0); expect(client._rfb_version).to.equal(0);
const sent_data = client._sock._websocket._get_sent_data(); const sent_data = client._sock._websocket._get_sent_data();
expect(new Uint8Array(sent_data.buffer, 0, 9)).to.array.equal(new Uint8Array([73, 68, 58, 49, 50, 51, 52, 53, 0])); expect(new Uint8Array(sent_data.buffer, 0, 9))
.to.array.equal(new Uint8Array([73, 68, 58, 49, 50, 51, 52, 53, 0]));
expect(sent_data).to.have.length(250); expect(sent_data).to.have.length(250);
}); });
@ -1557,10 +1558,13 @@ describe('Remote Frame Buffer Protocol Client', function () {
expect(RFB.messages.pixelFormat).to.have.been.calledWith(client._sock, 24, true); expect(RFB.messages.pixelFormat).to.have.been.calledWith(client._sock, 24, true);
expect(RFB.messages.pixelFormat).to.have.been.calledBefore(RFB.messages.clientEncodings); expect(RFB.messages.pixelFormat).to.have.been.calledBefore(RFB.messages.clientEncodings);
expect(RFB.messages.clientEncodings).to.have.been.calledOnce; expect(RFB.messages.clientEncodings).to.have.been.calledOnce;
expect(RFB.messages.clientEncodings.getCall(0).args[1]).to.include(encodings.encodingTight); expect(RFB.messages.clientEncodings.getCall(0).args[1])
expect(RFB.messages.clientEncodings).to.have.been.calledBefore(RFB.messages.fbUpdateRequest); .to.include(encodings.encodingTight);
expect(RFB.messages.clientEncodings)
.to.have.been.calledBefore(RFB.messages.fbUpdateRequest);
expect(RFB.messages.fbUpdateRequest).to.have.been.calledOnce; expect(RFB.messages.fbUpdateRequest).to.have.been.calledOnce;
expect(RFB.messages.fbUpdateRequest).to.have.been.calledWith(client._sock, false, 0, 0, 27, 32); expect(RFB.messages.fbUpdateRequest)
.to.have.been.calledWith(client._sock, false, 0, 0, 27, 32);
}); });
it('should reply with restricted settings for Intel AMT servers', function () { it('should reply with restricted settings for Intel AMT servers', function () {
@ -1570,11 +1574,15 @@ describe('Remote Frame Buffer Protocol Client', function () {
expect(RFB.messages.pixelFormat).to.have.been.calledWith(client._sock, 8, true); expect(RFB.messages.pixelFormat).to.have.been.calledWith(client._sock, 8, true);
expect(RFB.messages.pixelFormat).to.have.been.calledBefore(RFB.messages.clientEncodings); expect(RFB.messages.pixelFormat).to.have.been.calledBefore(RFB.messages.clientEncodings);
expect(RFB.messages.clientEncodings).to.have.been.calledOnce; expect(RFB.messages.clientEncodings).to.have.been.calledOnce;
expect(RFB.messages.clientEncodings.getCall(0).args[1]).to.not.include(encodings.encodingTight); expect(RFB.messages.clientEncodings.getCall(0).args[1])
expect(RFB.messages.clientEncodings.getCall(0).args[1]).to.not.include(encodings.encodingHextile); .to.not.include(encodings.encodingTight);
expect(RFB.messages.clientEncodings).to.have.been.calledBefore(RFB.messages.fbUpdateRequest); expect(RFB.messages.clientEncodings.getCall(0).args[1])
.to.not.include(encodings.encodingHextile);
expect(RFB.messages.clientEncodings)
.to.have.been.calledBefore(RFB.messages.fbUpdateRequest);
expect(RFB.messages.fbUpdateRequest).to.have.been.calledOnce; expect(RFB.messages.fbUpdateRequest).to.have.been.calledOnce;
expect(RFB.messages.fbUpdateRequest).to.have.been.calledWith(client._sock, false, 0, 0, 27, 32); expect(RFB.messages.fbUpdateRequest)
.to.have.been.calledWith(client._sock, false, 0, 0, 27, 32);
}); });
}); });
@ -1665,7 +1673,8 @@ describe('Remote Frame Buffer Protocol Client', function () {
client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 3])); client._sock._websocket._receive_data(new Uint8Array([0, 0, 0, 3]));
expect(client._sock._websocket._get_sent_data()).to.have.length(0); expect(client._sock._websocket._get_sent_data()).to.have.length(0);
client._framebufferUpdate = function () { this._sock.rQskip8(); return true; }; // we magically have enough data // we magically have enough data
client._framebufferUpdate = function () { this._sock.rQskip8(); return true; };
// 247 should *not* be used as the message type here // 247 should *not* be used as the message type here
client._sock._websocket._receive_data(new Uint8Array([247])); client._sock._websocket._receive_data(new Uint8Array([247]));
expect(client._sock).to.have.sent(expected_msg._sQ); expect(client._sock).to.have.sent(expected_msg._sQ);
@ -1693,7 +1702,8 @@ describe('Remote Frame Buffer Protocol Client', function () {
client._fb_width = 4; client._fb_width = 4;
client._fb_height = 4; client._fb_height = 4;
client._display.resize(4, 4); client._display.resize(4, 4);
client._display.blitRgbxImage(0, 0, 4, 2, new Uint8Array(target_data_check_arr.slice(0, 32)), 0); client._display.blitRgbxImage(0, 0, 4, 2,
new Uint8Array(target_data_check_arr.slice(0, 32)), 0);
const info = [{ const info = [{
x: 0, y: 2, width: 2, height: 2, encoding: 0x01 x: 0, y: 2, width: 2, height: 2, encoding: 0x01
@ -1765,7 +1775,8 @@ describe('Remote Frame Buffer Protocol Client', function () {
it('should handle the COPYRECT encoding', function () { it('should handle the COPYRECT encoding', function () {
// seed some initial data to copy // seed some initial data to copy
client._display.blitRgbxImage(0, 0, 4, 2, new Uint8Array(target_data_check_arr.slice(0, 32)), 0); client._display.blitRgbxImage(0, 0, 4, 2,
new Uint8Array(target_data_check_arr.slice(0, 32)), 0);
const info = [{ const info = [{
x: 0, y: 2, width: 2, height: 2, encoding: 0x01 x: 0, y: 2, width: 2, height: 2, encoding: 0x01
@ -1882,8 +1893,8 @@ describe('Remote Frame Buffer Protocol Client', function () {
send_fbu_msg(info, [rect], client); send_fbu_msg(info, [rect], client);
const expected = []; const expected = [];
for (let i = 0; i < 16; i++) { push32(expected, 0xff00ff); } // rect 1: solid for (let i = 0; i < 16; i++) { push32(expected, 0xff00ff); } // rect 1: solid
for (let i = 0; i < 16; i++) { push32(expected, 0xff00ff); } // rect 2: same bkground color for (let i = 0; i < 16; i++) { push32(expected, 0xff00ff); } // rect 2: same bg color
expect(client._display).to.have.displayed(new Uint8Array(expected)); expect(client._display).to.have.displayed(new Uint8Array(expected));
}); });

View File

@ -78,7 +78,8 @@ describe('Websock', function () {
const bef_rQi = sock.get_rQi(); const bef_rQi = sock.get_rQi();
const shifted = sock.rQshiftStr(3); const shifted = sock.rQshiftStr(3);
expect(shifted).to.be.a('string'); expect(shifted).to.be.a('string');
expect(shifted).to.equal(String.fromCharCode.apply(null, Array.prototype.slice.call(new Uint8Array(RQ_TEMPLATE.buffer, bef_rQi, 3)))); expect(shifted).to.equal(String.fromCharCode.apply(null,
Array.prototype.slice.call(new Uint8Array(RQ_TEMPLATE.buffer, bef_rQi, 3))));
expect(sock.rQlen()).to.equal(bef_len - 3); expect(sock.rQlen()).to.equal(bef_len - 3);
}); });
@ -225,7 +226,8 @@ describe('Websock', function () {
it('should add to the send queue', function () { it('should add to the send queue', function () {
sock.send([1, 2, 3]); sock.send([1, 2, 3]);
const sq = sock.get_sQ(); const sq = sock.get_sQ();
expect(new Uint8Array(sq.buffer, sock._sQlen - 3, 3)).to.array.equal(new Uint8Array([1, 2, 3])); const sendQueue = new Uint8Array(sq.buffer, sock._sQlen - 3, 3);
expect(sendQueue).to.array.equal(new Uint8Array([1, 2, 3]));
}); });
it('should call flush', function () { it('should call flush', function () {