From 0c7ff11f332616b7063b5be99e6b235b18ad95b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Monda?= Date: Fri, 25 Mar 2016 18:33:51 +0100 Subject: [PATCH] Add tslint.json and fix coding style accordingly for the most part. --- model/UhkBuffer.ts | 12 ++--- model/serializeConfig.ts | 26 +++++------ model/tslint.json | 96 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+), 19 deletions(-) create mode 100644 model/tslint.json diff --git a/model/UhkBuffer.ts b/model/UhkBuffer.ts index e8d48db1..2569f2d5 100644 --- a/model/UhkBuffer.ts +++ b/model/UhkBuffer.ts @@ -1,11 +1,11 @@ class UhkBuffer { - buffer: Buffer; - offset: number; - private static maxStringByteLength = 0xFFFF; private static longStringPrefix = 0xFF; - private static stringEncoding = "utf8"; + private static stringEncoding = 'utf8'; + + buffer: Buffer; + offset: number; constructor(buffer: Buffer) { this.offset = 0; @@ -94,8 +94,8 @@ class UhkBuffer { let stringByteLength = Buffer.byteLength(str, UhkBuffer.stringEncoding); if (stringByteLength > UhkBuffer.maxStringByteLength) { - throw "Cannot serialize string: ${stringByteLength} bytes is larger " + - "than the maximum allowed length of ${UhkBuffer.maxStringByteLength} bytes"; + throw 'Cannot serialize string: ${stringByteLength} bytes is larger ' + + 'than the maximum allowed length of ${UhkBuffer.maxStringByteLength} bytes'; } if (stringByteLength >= UhkBuffer.longStringPrefix) { diff --git a/model/serializeConfig.ts b/model/serializeConfig.ts index 2202f674..c44524e2 100644 --- a/model/serializeConfig.ts +++ b/model/serializeConfig.ts @@ -1,12 +1,12 @@ /// /// -let fs = require("fs"); +let fs = require('fs'); let buffer: Buffer = new Buffer(1000); buffer.fill(0); let writer = new UhkBuffer(buffer); -let uhkConfig = JSON.parse(fs.readFileSync("uhk-config.json")); +let uhkConfig = JSON.parse(fs.readFileSync('uhk-config.json')); let keyActions = uhkConfig.keymaps[0].layers[0].modules[0].keyActions; let ARRAY_LAST_ELEMENT_ID = 0; @@ -51,8 +51,8 @@ let MOUSE_ACTION_ID_SCROLL_RIGHT = 10; let MOUSE_ACTION_ID_ACCELERATE = 11; let MOUSE_ACTION_ID_DECELERATE = 12; -function serializeKeyActions(keyActions) { - keyActions.forEach(function(keyAction) { +function serializeKeyActions(keyActionsParam) { + keyActionsParam.forEach(function(keyAction) { serializeKeyAction(keyAction); }); writer.writeUInt8(ARRAY_LAST_ELEMENT_ID); @@ -60,29 +60,29 @@ function serializeKeyActions(keyActions) { function serializeKeyAction(keyAction) { switch (keyAction.actionType) { - case "none": + case 'none': serializeNoneAction(); break; - case "keystroke": + case 'keystroke': serializeKeystrokeAction(keyAction); break; - case "dualRoleKeystroke": + case 'dualRoleKeystroke': serializeDualRoleKeyAction(keyAction); break; - case "mouse": + case 'mouse': serializeMouseAction(keyAction); break; - case "playMacro": + case 'playMacro': serializeMacroAction(keyAction); break; - case "switchKeymap": + case 'switchKeymap': serializeSwitchKeymapAction(keyAction); break; - case "switchLayer": + case 'switchLayer': serializeSwitchLayerAction(keyAction); break; default: - throw "KeyAction doesn't have a valid actionType property: " + keyAction.actionType; + throw 'KeyAction doesn\'t have a valid actionType property: ' + keyAction.actionType; } } @@ -153,4 +153,4 @@ function serializeSwitchLayerAction(switchLayerAction) { new KeystrokeAction(); serializeKeyActions(keyActions); -fs.writeFileSync("uhk-config.bin", buffer); +fs.writeFileSync('uhk-config.bin', buffer); diff --git a/model/tslint.json b/model/tslint.json new file mode 100644 index 00000000..71d6cd15 --- /dev/null +++ b/model/tslint.json @@ -0,0 +1,96 @@ +{ + "rules": { + "member-ordering": [ + true, + "public-before-private", + "static-before-instance", + "variables-before-functions" + ], + "no-inferrable-types": true, + "no-internal-module": true, + "curly": true, + "no-construct": true, + "no-duplicate-key": true, + "no-duplicate-variable": true, + "no-eval": true, + "no-null-keyword": true, + "no-shadowed-variable": true, + "no-string-literal": true, + "no-switch-case-fall-through": true, + "no-unreachable": true, + "no-unused-expression": true, + "no-unused-variable": [ + true, + "check-parameters" + ], + "no-use-before-declare": true, + "no-var-keyword": true, + "radix": true, + "switch-default": true, + "triple-equals": true, + "eofline": true, + "indent": [ + true, + "spaces" + ], + "max-line-length": [true, 100], + "no-trailing-whitespace": true, + "trailing-comma": [ + true, { + "multiline": "never", + "singleline": "never" + } + ], + "align": [ + true, + "parameters", + "arguments", + "statements" + ], + "comment-format": [ + true, + "check-space", + "check-uppercase" + ], + "no-consecutive-blank-lines": true, + "one-line": [ + true, + "check-open-brace", + "check-whitespace" + ], + + "quotemark": [ + true, + "single" + ], + "semicolon": [ + true, + "always" + ], + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + } + ], + "variable-name": [ + true, + "ban-keywords", + "check-format" + ], + "whitespace": [ + true, + "check-branch", + "check-decl", + "check-operator", + "check-module", + "check-separator", + "check-type", + "check-typecast" + ] + } +} \ No newline at end of file