Add tslint.json and fix coding style accordingly for the most part.

This commit is contained in:
László Monda
2016-03-25 18:33:51 +01:00
parent 82f181d184
commit 0c7ff11f33
3 changed files with 115 additions and 19 deletions

View File

@@ -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) {

View File

@@ -1,12 +1,12 @@
/// <reference path="UhkBuffer.ts" />
/// <reference path="KeystrokeAction.ts" />
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);

96
model/tslint.json Normal file
View File

@@ -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"
]
}
}