Add tslint to devDependencies and clean up the codebase according to tslint suggestions.

This commit is contained in:
László Monda
2016-03-25 02:02:20 +01:00
parent 468606481c
commit 82f181d184
4 changed files with 78 additions and 77 deletions

View File

@@ -1,7 +1,7 @@
/// <reference path="Serializable.ts" /> /// <reference path="Serializable.ts" />
class KeystrokeAction implements Serializable { class KeystrokeAction implements Serializable {
scancode: number; scancode: number;
modifierMask: number; modifierMask: number;
fromJsObject(jsObject: any) { fromJsObject(jsObject: any) {
@@ -22,5 +22,5 @@ class KeystrokeAction implements Serializable {
toBinary(buffer: UhkBuffer) { toBinary(buffer: UhkBuffer) {
buffer.writeUInt8(this.scancode); buffer.writeUInt8(this.scancode);
buffer.writeUInt8(this.modifierMask); buffer.writeUInt8(this.modifierMask);
} }
} }

View File

@@ -5,97 +5,97 @@ class UhkBuffer {
private static maxStringByteLength = 0xFFFF; private static maxStringByteLength = 0xFFFF;
private static longStringPrefix = 0xFF; private static longStringPrefix = 0xFF;
private static stringEncoding = 'utf8'; private static stringEncoding = "utf8";
constructor(buffer:Buffer) { constructor(buffer: Buffer) {
this.offset = 0; this.offset = 0;
this.buffer = buffer; this.buffer = buffer;
} }
readInt8():number { readInt8(): number {
let value = this.buffer.readInt8(this.offset); let value = this.buffer.readInt8(this.offset);
this.offset += 1; this.offset += 1;
return value; return value;
} }
writeInt8(value:number):void { writeInt8(value: number): void {
this.buffer.writeInt8(value, this.offset); this.buffer.writeInt8(value, this.offset);
this.offset += 1; this.offset += 1;
} }
readUInt8():number { readUInt8(): number {
let value = this.buffer.readUInt8(this.offset); let value = this.buffer.readUInt8(this.offset);
this.offset += 1; this.offset += 1;
return value; return value;
} }
writeUInt8(value:number):void { writeUInt8(value: number): void {
this.buffer.writeUInt8(value, this.offset); this.buffer.writeUInt8(value, this.offset);
this.offset += 1; this.offset += 1;
} }
readInt16():number { readInt16(): number {
let value = this.buffer.readInt16LE(this.offset); let value = this.buffer.readInt16LE(this.offset);
this.offset += 2; this.offset += 2;
return value; return value;
} }
writeInt16(value:number):void { writeInt16(value: number): void {
this.buffer.writeInt16LE(value, this.offset); this.buffer.writeInt16LE(value, this.offset);
this.offset += 2; this.offset += 2;
} }
readUInt16():number { readUInt16(): number {
let value = this.buffer.readUInt16LE(this.offset); let value = this.buffer.readUInt16LE(this.offset);
this.offset += 2; this.offset += 2;
return value; return value;
} }
writeUInt16(value:number):void { writeUInt16(value: number): void {
this.buffer.writeUInt16LE(value, this.offset); this.buffer.writeUInt16LE(value, this.offset);
this.offset += 2; this.offset += 2;
} }
readInt32():number { readInt32(): number {
let value = this.buffer.readInt32LE(this.offset); let value = this.buffer.readInt32LE(this.offset);
this.offset += 4; this.offset += 4;
return value; return value;
} }
writeInt32(value:number):void { writeInt32(value: number): void {
this.buffer.writeInt32LE(value, this.offset); this.buffer.writeInt32LE(value, this.offset);
this.offset += 4; this.offset += 4;
} }
readUInt32():number { readUInt32(): number {
let value = this.buffer.readUInt32LE(this.offset); let value = this.buffer.readUInt32LE(this.offset);
this.offset += 4; this.offset += 4;
return value; return value;
} }
writeUInt32(value:number):void { writeUInt32(value: number): void {
this.buffer.writeUInt32LE(value, this.offset); this.buffer.writeUInt32LE(value, this.offset);
this.offset += 4; this.offset += 4;
} }
readString():string { readString(): string {
let stringByteLength = this.readUInt8(); let stringByteLength = this.readUInt8();
if (stringByteLength == UhkBuffer.longStringPrefix) { if (stringByteLength === UhkBuffer.longStringPrefix) {
stringByteLength += this.readUInt8() << 8; stringByteLength += this.readUInt8() << 8;
} }
let string = this.buffer.toString(UhkBuffer.stringEncoding, this.offset, stringByteLength); let str = this.buffer.toString(UhkBuffer.stringEncoding, this.offset, stringByteLength);
this.offset += stringByteLength; this.offset += stringByteLength;
return string; return str;
} }
writeString(string:string):void { writeString(str: string): void {
let stringByteLength = Buffer.byteLength(string, UhkBuffer.stringEncoding); let stringByteLength = Buffer.byteLength(str, UhkBuffer.stringEncoding);
if (stringByteLength > UhkBuffer.maxStringByteLength) { if (stringByteLength > UhkBuffer.maxStringByteLength) {
throw 'Cannot serialize string: ${stringByteLength} bytes is larger ' + throw "Cannot serialize string: ${stringByteLength} bytes is larger " +
'than the maximum allowed length of ${UhkBuffer.maxStringByteLength} bytes'; "than the maximum allowed length of ${UhkBuffer.maxStringByteLength} bytes";
} }
if (stringByteLength >= UhkBuffer.longStringPrefix) { if (stringByteLength >= UhkBuffer.longStringPrefix) {
@@ -105,7 +105,7 @@ class UhkBuffer {
this.writeUInt8(stringByteLength); this.writeUInt8(stringByteLength);
} }
this.buffer.write(string, this.offset, stringByteLength, UhkBuffer.stringEncoding); this.buffer.write(str, this.offset, stringByteLength, UhkBuffer.stringEncoding);
this.offset += stringByteLength; this.offset += stringByteLength;
} }
} }

View File

@@ -1,55 +1,55 @@
/// <reference path="UhkBuffer.ts" /> /// <reference path="UhkBuffer.ts" />
/// <reference path="KeystrokeAction.ts" /> /// <reference path="KeystrokeAction.ts" />
var fs = require('fs'); let fs = require("fs");
var buffer:Buffer = new Buffer(1000); let buffer: Buffer = new Buffer(1000);
buffer.fill(0); buffer.fill(0);
var writer = new UhkBuffer(buffer); let writer = new UhkBuffer(buffer);
var uhkConfig = JSON.parse(fs.readFileSync('uhk-config.json')); let uhkConfig = JSON.parse(fs.readFileSync("uhk-config.json"));
var keyActions = uhkConfig.keymaps[0].layers[0].modules[0].keyActions; let keyActions = uhkConfig.keymaps[0].layers[0].modules[0].keyActions;
var ARRAY_LAST_ELEMENT_ID = 0; let ARRAY_LAST_ELEMENT_ID = 0;
var KEY_ACTION_ID_KEYSTROKE_SCANCODE_FIRST = 1; let KEY_ACTION_ID_KEYSTROKE_SCANCODE_FIRST = 1;
var KEY_ACTION_ID_KEYSTROKE_SCANCODE_LAST = 231; let KEY_ACTION_ID_KEYSTROKE_SCANCODE_LAST = 231;
var KEY_ACTION_ID_SWITCH_LAYER = 232; let KEY_ACTION_ID_SWITCH_LAYER = 232;
var KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_MOD = 233; let KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_MOD = 233;
var KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_FN = 234; let KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_FN = 234;
var KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_MOUSE = 235; let KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_MOUSE = 235;
var KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_LEFT_CTRL = 236; let KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_LEFT_CTRL = 236;
var KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_LEFT_SHIFT = 237; let KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_LEFT_SHIFT = 237;
var KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_LEFT_ALT = 238; let KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_LEFT_ALT = 238;
var KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_LEFT_SUPER = 239; let KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_LEFT_SUPER = 239;
var KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_RIGHT_CTRL = 240; let KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_RIGHT_CTRL = 240;
var KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_RIGHT_SHIFT = 241; let KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_RIGHT_SHIFT = 241;
var KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_RIGHT_ALT = 242; let KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_RIGHT_ALT = 242;
var KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_RIGHT_SUPER = 243; let KEY_ACTION_ID_DUAL_ROLE_KEYSTROKE_RIGHT_SUPER = 243;
var KEY_ACTION_ID_MOUSE = 244; let KEY_ACTION_ID_MOUSE = 244;
var KEY_ACTION_ID_PLAY_MACRO = 245; let KEY_ACTION_ID_PLAY_MACRO = 245;
var KEY_ACTION_ID_SWITCH_KEYMAP = 246; let KEY_ACTION_ID_SWITCH_KEYMAP = 246;
var KEY_ACTION_ID_NONE = 255; let KEY_ACTION_ID_NONE = 255;
var SWITCH_LAYER_MOD = 0; let SWITCH_LAYER_MOD = 0;
var SWITCH_LAYER_FN = 1; let SWITCH_LAYER_FN = 1;
var SWITCH_LAYER_MOUSE = 2; let SWITCH_LAYER_MOUSE = 2;
var SWITCH_LAYER_TOGGLE = 0x80; let SWITCH_LAYER_TOGGLE = 0x80;
var NONE_ACTION_PADDING = 0; let NONE_ACTION_PADDING = 0;
var MOUSE_ACTION_ID_LEFT_CLICK = 0; let MOUSE_ACTION_ID_LEFT_CLICK = 0;
var MOUSE_ACTION_ID_MIDDLE_CLICK = 1; let MOUSE_ACTION_ID_MIDDLE_CLICK = 1;
var MOUSE_ACTION_ID_RIGHT_CLICK = 2; let MOUSE_ACTION_ID_RIGHT_CLICK = 2;
var MOUSE_ACTION_ID_MOVE_UP = 3; let MOUSE_ACTION_ID_MOVE_UP = 3;
var MOUSE_ACTION_ID_MOVE_DOWN = 4; let MOUSE_ACTION_ID_MOVE_DOWN = 4;
var MOUSE_ACTION_ID_MOVE_LEFT = 5; let MOUSE_ACTION_ID_MOVE_LEFT = 5;
var MOUSE_ACTION_ID_MOVE_RIGHT = 6; let MOUSE_ACTION_ID_MOVE_RIGHT = 6;
var MOUSE_ACTION_ID_SCROLL_UP = 7; let MOUSE_ACTION_ID_SCROLL_UP = 7;
var MOUSE_ACTION_ID_SCROLL_DOWN = 8; let MOUSE_ACTION_ID_SCROLL_DOWN = 8;
var MOUSE_ACTION_ID_SCROLL_LEFT = 9; let MOUSE_ACTION_ID_SCROLL_LEFT = 9;
var MOUSE_ACTION_ID_SCROLL_RIGHT = 10; let MOUSE_ACTION_ID_SCROLL_RIGHT = 10;
var MOUSE_ACTION_ID_ACCELERATE = 11; let MOUSE_ACTION_ID_ACCELERATE = 11;
var MOUSE_ACTION_ID_DECELERATE = 12; let MOUSE_ACTION_ID_DECELERATE = 12;
function serializeKeyActions(keyActions) { function serializeKeyActions(keyActions) {
keyActions.forEach(function(keyAction) { keyActions.forEach(function(keyAction) {
@@ -60,25 +60,25 @@ function serializeKeyActions(keyActions) {
function serializeKeyAction(keyAction) { function serializeKeyAction(keyAction) {
switch (keyAction.actionType) { switch (keyAction.actionType) {
case 'none': case "none":
serializeNoneAction(); serializeNoneAction();
break; break;
case 'keystroke': case "keystroke":
serializeKeystrokeAction(keyAction); serializeKeystrokeAction(keyAction);
break; break;
case 'dualRoleKeystroke': case "dualRoleKeystroke":
serializeDualRoleKeyAction(keyAction); serializeDualRoleKeyAction(keyAction);
break; break;
case 'mouse': case "mouse":
serializeMouseAction(keyAction); serializeMouseAction(keyAction);
break; break;
case 'playMacro': case "playMacro":
serializeMacroAction(keyAction); serializeMacroAction(keyAction);
break; break;
case 'switchKeymap': case "switchKeymap":
serializeSwitchKeymapAction(keyAction); serializeSwitchKeymapAction(keyAction);
break; break;
case 'switchLayer': case "switchLayer":
serializeSwitchLayerAction(keyAction); serializeSwitchLayerAction(keyAction);
break; break;
default: default:
@@ -153,4 +153,4 @@ function serializeSwitchLayerAction(switchLayerAction) {
new KeystrokeAction(); new KeystrokeAction();
serializeKeyActions(keyActions); serializeKeyActions(keyActions);
fs.writeFileSync('uhk-config.bin', buffer); fs.writeFileSync("uhk-config.bin", buffer);

View File

@@ -13,6 +13,7 @@
"gulp-if": "^2.0.0", "gulp-if": "^2.0.0",
"gulp-sass": "^2.2.0", "gulp-sass": "^2.2.0",
"gulp-sourcemaps": "^1.6.0", "gulp-sourcemaps": "^1.6.0",
"tslint": "^3.6.0",
"yargs": "^4.2.0" "yargs": "^4.2.0"
}, },
"dependencies": { "dependencies": {