Add new tslint rules and fix rule breaks

This commit is contained in:
József Farkas
2017-03-18 23:43:32 +01:00
parent 0e8165a0b4
commit ca31e5bb4d
44 changed files with 127 additions and 142 deletions

View File

@@ -67,7 +67,7 @@ export class KeymapEditComponent extends SharedKeymapEditComponent {
.do(response => console.log('Sending layer finished', response))
.switchMap(() => this.uhkDevice.applyConfig())
.subscribe(
(response) => console.log('Applying layer finished', response),
response => console.log('Applying layer finished', response),
error => console.error('Error during uploading layer', error),
() => console.log('Layer has been sucessfully uploaded')
);
@@ -85,7 +85,7 @@ export class KeymapEditComponent extends SharedKeymapEditComponent {
.do(response => console.log('Sending keymap finished', response))
.switchMap(() => this.uhkDevice.applyConfig())
.subscribe(
(response) => console.log('Applying keymap finished', response),
response => console.log('Applying keymap finished', response),
error => console.error('Error during uploading keymap', error),
() => console.log('Keymap has been sucessfully uploaded')
);

View File

@@ -24,7 +24,7 @@ function createWindow() {
win.loadURL(`file://${indexPath}`);
win.on('page-title-updated', (event) => {
win.on('page-title-updated', event => {
event.preventDefault();
});

View File

@@ -54,7 +54,7 @@ export class MainAppComponent {
.do(response => console.log('Sending user configuration finished', response))
.switchMap(() => this.uhkDevice.applyConfig())
.subscribe(
(response) => console.log('Applying user configuration finished', response),
response => console.log('Applying user configuration finished', response),
error => console.error('Error during uploading user configuration', error),
() => console.log('User configuration has been sucessfully uploaded')
);

View File

@@ -115,7 +115,7 @@ export class UhkDeviceService implements OnDestroy {
const outSending = this.messageOut$.concatMap(senderPackage => {
return (<Observable<void>>Observable.create((subscriber: Subscriber<void>) => {
console.log('transfering', senderPackage.buffer);
outEndPoint.transfer(senderPackage.buffer, (error) => {
outEndPoint.transfer(senderPackage.buffer, error => {
if (error) {
console.error('transfering errored', error);
subscriber.error(error);

View File

@@ -12,9 +12,9 @@ import { Observable } from 'rxjs/Observable';
}
})
export class AddOnComponent {
private name$: Observable<string>;
name$: Observable<string>;
constructor(private route: ActivatedRoute) {
constructor(route: ActivatedRoute) {
this.name$ = route
.params
.select<string>('name');

View File

@@ -32,7 +32,7 @@ export class KeymapEditComponent {
constructor(
protected store: Store<AppState>,
private route: ActivatedRoute
route: ActivatedRoute
) {
this.keymap$ = route
.params

View File

@@ -29,18 +29,16 @@ export class MacroActionEditorComponent implements OnInit {
@ViewChild('tab') selectedTab: any;
private editableMacroAction: EditableMacroAction;
private activeTab: TabName;
editableMacroAction: EditableMacroAction;
activeTab: TabName;
/* tslint:disable:variable-name: It is an enum type. So it can start with uppercase. */
/* tslint:disable:no-unused-variable: It is used in the template. */
private TabName = TabName;
/* tslint:enable:no-unused-variable */
TabName = TabName;
/* tslint:enable:variable-name */
ngOnInit() {
let macroAction: MacroAction = this.macroAction ? this.macroAction : new TextMacroAction();
const macroAction: MacroAction = this.macroAction ? this.macroAction : new TextMacroAction();
this.editableMacroAction = new EditableMacroAction(macroAction.toJsonObject());
let tab: TabName = this.getTabName(this.editableMacroAction);
const tab: TabName = this.getTabName(this.editableMacroAction);
this.activeTab = tab;
}

View File

@@ -22,10 +22,8 @@ export class MacroDelayTabComponent implements OnInit {
@Input() macroAction: EditableMacroAction;
@ViewChild('macroDelayInput') input: ElementRef;
private delay: number;
/* tslint:disable:no-unused-variable: It is used in the template. */
private presets: number[] = [0.3, 0.5, 0.8, 1, 2, 3, 4, 5];
/* tslint:enable:no-unused-variable */
delay: number;
presets: number[] = [0.3, 0.5, 0.8, 1, 2, 3, 4, 5];
constructor() { }

View File

@@ -25,14 +25,11 @@ export class MacroKeyTabComponent implements OnInit {
@ViewChild('tab') selectedTab: Tab;
@ViewChild('keypressTab') keypressTab: KeypressTabComponent;
private defaultKeyAction: KeyAction;
private activeTab: TabName;
/* tslint:disable:variable-name: It is an enum type. So it can start with uppercase. */
/* tslint:disable:no-unused-variable: It is used in the template. */
private TabName = TabName;
/* tslint:enable:no-unused-variable */
TabName = TabName;
/* tslint:enable:variable-name */
activeTab: TabName;
defaultKeyAction: KeyAction;
ngOnInit() {
this.defaultKeyAction = this.macroAction.toKeystrokeAction();

View File

@@ -24,14 +24,12 @@ export class MacroMouseTabComponent implements OnInit {
@Input() macroAction: EditableMacroAction;
@ViewChild('tab') selectedTab: Tab;
/* tslint:disable:variable-name: It is an enum type. So it can start with uppercase. */
TabName = TabName;
/* tslint:enable:variable-name */
private activeTab: TabName;
private buttonLabels: string[];
private selectedButtons: boolean[];
/* tslint:disable:variable-name: It is an enum type. So it can start with uppercase. */
/* tslint:disable:no-unused-variable: It is used in the template. */
private TabName = TabName;
/* tslint:enable:no-unused-variable */
/* tslint:enable:variable-name */
constructor() {
this.buttonLabels = ['Left', 'Middle', 'Right'];

View File

@@ -106,12 +106,12 @@ export class MacroItemComponent implements OnInit, OnChanges {
} else if (this.macroAction instanceof DelayMacroAction) {
// Delay
this.iconName = 'clock';
let action: DelayMacroAction = this.macroAction as DelayMacroAction;
const action: DelayMacroAction = this.macroAction as DelayMacroAction;
const delay = action.delay > 0 ? action.delay / 1000 : 0;
this.title = `Delay of ${delay}s`;
} else if (this.macroAction instanceof TextMacroAction) {
// Write text
let action: TextMacroAction = this.macroAction as TextMacroAction;
const action: TextMacroAction = this.macroAction as TextMacroAction;
this.iconName = 'font';
this.title = `Write text: ${action.text}`;
} else if (this.macroAction instanceof KeyMacroAction) {

View File

@@ -60,7 +60,7 @@ export class MacroListComponent {
private dragIndex: number;
private showNew: boolean = false;
constructor(private dragulaService: DragulaService) {
constructor(dragulaService: DragulaService) {
/* tslint:disable:no-unused-variable: Used by Dragula. */
dragulaService.setOptions('macroActions', {
moves: function (el: any, container: any, handle: any) {

View File

@@ -90,7 +90,7 @@ export class PopoverComponent implements OnChanges {
private leftPosition: number = 0;
private animationState: string;
constructor(private store: Store<AppState>) {
constructor(store: Store<AppState>) {
this.animationState = 'closed';
this.keymaps$ = store.let(getKeymaps())
.map((keymaps: Keymap[]) =>
@@ -139,7 +139,7 @@ export class PopoverComponent implements OnChanges {
onRemapKey(): void {
if (this.keyActionValid) {
try {
let keyAction = this.selectedTab.toKeyAction();
const keyAction = this.selectedTab.toKeyAction();
this.remap.emit(keyAction);
} catch (e) {
// TODO: show error dialog

View File

@@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core';
import { ChangeDetectionStrategy, Component, Input, OnChanges, OnInit } from '@angular/core';
import { Select2OptionData } from 'ng2-select2/ng2-select2';

View File

@@ -1,4 +1,4 @@
import { Component, Input, EventEmitter, OnChanges, Output } from '@angular/core';
import { Component, Input, OnChanges } from '@angular/core';
import { Select2OptionData, Select2TemplateFunction } from 'ng2-select2';
@@ -86,11 +86,11 @@ export class KeypressTabComponent extends Tab implements OnChanges {
if (!(keyAction instanceof KeystrokeAction)) {
return false;
}
let keystrokeAction: KeystrokeAction = <KeystrokeAction>keyAction;
const keystrokeAction: KeystrokeAction = <KeystrokeAction>keyAction;
// Restore scancode
this.scanCode = keystrokeAction.scancode || 0;
let leftModifiersLength: number = this.leftModifiers.length;
const leftModifiersLength: number = this.leftModifiers.length;
// Restore modifiers
for (let i = 0; i < leftModifiersLength; ++i) {
@@ -98,7 +98,7 @@ export class KeypressTabComponent extends Tab implements OnChanges {
}
for (let i = leftModifiersLength; i < leftModifiersLength + this.rightModifierSelects.length; ++i) {
let index: number = this.mapper.modifierMapper(i) - leftModifiersLength;
const index: number = this.mapper.modifierMapper(i) - leftModifiersLength;
this.rightModifierSelects[index] = ((keystrokeAction.modifierMask >> i) & 1) === 1;
}
@@ -111,11 +111,11 @@ export class KeypressTabComponent extends Tab implements OnChanges {
}
toKeyAction(): KeystrokeAction {
let keystrokeAction: KeystrokeAction = new KeystrokeAction();
const keystrokeAction: KeystrokeAction = new KeystrokeAction();
keystrokeAction.scancode = this.scanCode;
keystrokeAction.modifierMask = 0;
let modifiers = this.leftModifierSelects.concat(this.rightModifierSelects).map(x => x ? 1 : 0);
const modifiers = this.leftModifierSelects.concat(this.rightModifierSelects).map(x => x ? 1 : 0);
for (let i = 0; i < modifiers.length; ++i) {
keystrokeAction.modifierMask |= modifiers[i] << this.mapper.modifierMapper(i);
}
@@ -149,7 +149,7 @@ export class KeypressTabComponent extends Tab implements OnChanges {
}
toggleModifier(right: boolean, index: number) {
let modifierSelects: boolean[] = right ? this.rightModifierSelects : this.leftModifierSelects;
const modifierSelects: boolean[] = right ? this.rightModifierSelects : this.leftModifierSelects;
modifierSelects[index] = !modifierSelects[index];
this.validAction.emit(this.keyActionValid());

View File

@@ -1,4 +1,4 @@
import { Component, EventEmitter, HostBinding, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
import { Component, HostBinding, Input, OnChanges, SimpleChanges } from '@angular/core';
import { KeyAction, LayerName, SwitchLayerAction } from '../../../../config-serializer/config-items/key-action';
@@ -71,14 +71,14 @@ export class LayerTabComponent extends Tab implements OnChanges {
return false;
}
let switchLayerAction: SwitchLayerAction = <SwitchLayerAction>keyAction;
const switchLayerAction: SwitchLayerAction = <SwitchLayerAction>keyAction;
this.toggle = switchLayerAction.isLayerToggleable;
this.layer = switchLayerAction.layer;
return true;
}
toKeyAction(): SwitchLayerAction {
let keyAction = new SwitchLayerAction();
const keyAction = new SwitchLayerAction();
keyAction.isLayerToggleable = this.toggle;
keyAction.layer = this.layer;
if (!this.keyActionValid()) {

View File

@@ -1,4 +1,4 @@
import { Component, EventEmitter, Input, OnChanges, OnDestroy, OnInit, Output } from '@angular/core';
import { Component, Input, OnChanges, OnDestroy, OnInit } from '@angular/core';
import { Store } from '@ngrx/store';
@@ -27,7 +27,7 @@ export class MacroTabComponent extends Tab implements OnInit, OnChanges, OnDestr
private selectedMacroIndex: number;
private subscription: Subscription;
constructor(private store: Store<AppState>) {
constructor(store: Store<AppState>) {
super();
this.subscription = store.let(getMacros())
.subscribe((macros: Macro[]) => this.macros = macros);

View File

@@ -1,4 +1,4 @@
import { Component, EventEmitter, Input, OnChanges, Output } from '@angular/core';
import { Component, Input, OnChanges } from '@angular/core';
import { KeyAction, MouseAction, MouseActionParam } from '../../../../config-serializer/config-items/key-action';
import { Tab } from '../tab';
@@ -11,14 +11,12 @@ import { Tab } from '../tab';
export class MouseTabComponent extends Tab implements OnChanges {
@Input() defaultKeyAction: KeyAction;
private mouseActionParam: MouseActionParam;
private selectedPageIndex: number;
/* tslint:disable:variable-name: It is an enum type. So it can start with uppercase. */
/* tslint:disable:no-unused-variable: It is used in the template. */
private MouseActionParam = MouseActionParam;
/* tslint:enable:no-unused-variable tslint:enable:variable-name */
private pages: string[];
MouseActionParam = MouseActionParam;
/* tslint:enable:variable-name*/
mouseActionParam: MouseActionParam;
selectedPageIndex: number;
pages: string[];
constructor() {
super();
@@ -40,7 +38,7 @@ export class MouseTabComponent extends Tab implements OnChanges {
return false;
}
let mouseAction: MouseAction = <MouseAction>keyAction;
const mouseAction: MouseAction = <MouseAction>keyAction;
this.mouseActionParam = mouseAction.mouseAction;
if (mouseAction.mouseAction === MouseActionParam.moveUp) {
@@ -77,7 +75,7 @@ export class MouseTabComponent extends Tab implements OnChanges {
}
toKeyAction(): MouseAction {
let mouseAction: MouseAction = new MouseAction();
const mouseAction: MouseAction = new MouseAction();
mouseAction.mouseAction = this.mouseActionParam;
return mouseAction;
}

View File

@@ -1,4 +1,4 @@
import { Component, EventEmitter, OnChanges, Output } from '@angular/core';
import { Component, OnChanges } from '@angular/core';
import { Tab } from '../tab';

View File

@@ -56,7 +56,7 @@ export class SideMenuComponent {
}
toggleHide(event: Event, type: string) {
let header: DOMTokenList = (<Element>event.target).classList;
const header: DOMTokenList = (<Element>event.target).classList;
let show = false;
if (header.contains('fa-chevron-down')) {

View File

@@ -55,7 +55,7 @@ export class SvgKeyboardComponent implements OnInit {
}
private getKeyboardSvgAttributes(): { viewBox: string, transform: string, fill: string } {
let svg: any = this.getBaseLayer();
const svg: any = this.getBaseLayer();
return {
viewBox: svg.$.viewBox,
transform: svg.g[0].$.transform,
@@ -64,7 +64,7 @@ export class SvgKeyboardComponent implements OnInit {
}
private getSvgModules(): SvgModule[] {
let modules = this.getBaseLayer().g[0].g.map((obj: any) => new SvgModule(obj));
const modules = this.getBaseLayer().g[0].g.map((obj: any) => new SvgModule(obj));
return [modules[1], modules[0]]; // TODO: remove if the svg will be correct
}

View File

@@ -141,7 +141,7 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges, OnDestroy {
constructor(
private mapper: MapperService,
private store: Store<AppState>,
store: Store<AppState>,
private element: ElementRef,
private captureService: CaptureService,
private renderer: Renderer
@@ -215,11 +215,11 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges, OnDestroy {
this.labelType = LabelTypes.OneLineText;
if (this.keyAction instanceof KeystrokeAction) {
let keyAction: KeystrokeAction = this.keyAction as KeystrokeAction;
const keyAction: KeystrokeAction = this.keyAction as KeystrokeAction;
let newLabelSource: string[];
if (!keyAction.hasActiveModifier() && keyAction.hasScancode()) {
let scancode: number = keyAction.scancode;
const scancode: number = keyAction.scancode;
newLabelSource = this.mapper.scanCodeToText(scancode);
if (this.mapper.hasScancodeIcon(scancode)) {
this.labelSource = this.mapper.scanCodeToSvgImagePath(scancode);
@@ -262,7 +262,7 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges, OnDestroy {
this.labelSource = this.keyAction;
}
} else if (this.keyAction instanceof SwitchLayerAction) {
let keyAction: SwitchLayerAction = this.keyAction as SwitchLayerAction;
const keyAction: SwitchLayerAction = this.keyAction as SwitchLayerAction;
let newLabelSource: string;
switch (keyAction.layer) {
case LayerName.mod:
@@ -289,11 +289,11 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges, OnDestroy {
this.labelSource = newLabelSource;
}
} else if (this.keyAction instanceof SwitchKeymapAction) {
let keyAction: SwitchKeymapAction = this.keyAction as SwitchKeymapAction;
const keyAction: SwitchKeymapAction = this.keyAction as SwitchKeymapAction;
this.labelType = LabelTypes.SwitchKeymap;
this.labelSource = keyAction.keymapAbbreviation;
} else if (this.keyAction instanceof PlayMacroAction) {
let keyAction: PlayMacroAction = this.keyAction as PlayMacroAction;
const keyAction: PlayMacroAction = this.keyAction as PlayMacroAction;
const macro: Macro = this.macros.find((_macro: Macro) => _macro.id === keyAction.macroId);
this.labelType = LabelTypes.IconText;
this.labelSource = {

View File

@@ -20,10 +20,6 @@ class SvgAttributes {
}
}
enum Modifiers {
Shift, Control, Alt, Command
}
@Component({
selector: 'g[svg-keystroke-key]',
templateUrl: './svg-keystroke-key.component.html',
@@ -68,7 +64,7 @@ export class SvgKeystrokeKeyComponent implements OnInit, OnChanges {
this.modifierIconNames.option = this.mapper.getIcon('option');
this.modifierIconNames.command = this.mapper.getIcon('command');
let bottomSideMode: boolean = this.width < this.height * 1.8;
const bottomSideMode: boolean = this.width < this.height * 1.8;
const heightWidthRatio = this.height / this.width;
@@ -76,8 +72,8 @@ export class SvgKeystrokeKeyComponent implements OnInit, OnChanges {
const maxIconWidth = this.width / 4;
const maxIconHeight = this.height;
const iconScalingFactor = 0.8;
let iconWidth = iconScalingFactor * heightWidthRatio * maxIconWidth;
let iconHeight = iconScalingFactor * maxIconHeight;
const iconWidth = iconScalingFactor * heightWidthRatio * maxIconWidth;
const iconHeight = iconScalingFactor * maxIconHeight;
this.modifierContainer.width = this.width;
this.modifierContainer.height = this.height / 5;
this.modifierContainer.y = this.height - this.modifierContainer.height;
@@ -134,7 +130,7 @@ export class SvgKeystrokeKeyComponent implements OnInit, OnChanges {
ngOnChanges() {
let newLabelSource: string[];
if (this.keystrokeAction.hasScancode()) {
let scancode: number = this.keystrokeAction.scancode;
const scancode: number = this.keystrokeAction.scancode;
newLabelSource = this.mapper.scanCodeToText(scancode);
if (newLabelSource) {
if (newLabelSource.length === 1) {

View File

@@ -155,7 +155,7 @@ export class SvgKeyboardWrapComponent implements OnInit, OnChanges {
}
onCapture(moduleId: number, keyId: number, captured: { code: number, left: boolean[], right: boolean[] }): void {
let keystrokeAction: KeystrokeAction = new KeystrokeAction();
const keystrokeAction: KeystrokeAction = new KeystrokeAction();
const modifiers = captured.left.concat(captured.right).map(x => x ? 1 : 0);
keystrokeAction.scancode = captured.code;

View File

@@ -24,7 +24,7 @@ export class UhkBuffer {
}
readInt8(): number {
let value = this.buffer.readInt8(this.offset);
const value = this.buffer.readInt8(this.offset);
this.dump(`i8(${value})`);
this.bytesToBacktrack = 1;
this.offset += this.bytesToBacktrack;
@@ -38,7 +38,7 @@ export class UhkBuffer {
}
readUInt8(): number {
let value = this.buffer.readUInt8(this.offset);
const value = this.buffer.readUInt8(this.offset);
this.dump(`u8(${value})`);
this.bytesToBacktrack = 1;
this.offset += this.bytesToBacktrack;
@@ -52,7 +52,7 @@ export class UhkBuffer {
}
readInt16(): number {
let value = this.buffer.readInt16LE(this.offset);
const value = this.buffer.readInt16LE(this.offset);
this.dump(`i16(${value})`);
this.bytesToBacktrack = 2;
this.offset += this.bytesToBacktrack;
@@ -66,7 +66,7 @@ export class UhkBuffer {
}
readUInt16(): number {
let value = this.buffer.readUInt16LE(this.offset);
const value = this.buffer.readUInt16LE(this.offset);
this.dump(`u16(${value})`);
this.bytesToBacktrack = 2;
this.offset += this.bytesToBacktrack;
@@ -80,7 +80,7 @@ export class UhkBuffer {
}
readInt32(): number {
let value = this.buffer.readInt32LE(this.offset);
const value = this.buffer.readInt32LE(this.offset);
this.dump(`i32(${value})`);
this.bytesToBacktrack = 4;
this.offset += this.bytesToBacktrack;
@@ -94,7 +94,7 @@ export class UhkBuffer {
}
readUInt32(): number {
let value = this.buffer.readUInt32LE(this.offset);
const value = this.buffer.readUInt32LE(this.offset);
this.dump(`u32(${value})`);
this.bytesToBacktrack = 4;
this.offset += this.bytesToBacktrack;
@@ -125,8 +125,8 @@ export class UhkBuffer {
}
readString(): string {
let stringByteLength = this.readCompactLength();
let str = this.buffer.toString(UhkBuffer.stringEncoding, this.offset, this.offset + stringByteLength);
const stringByteLength = this.readCompactLength();
const str = this.buffer.toString(UhkBuffer.stringEncoding, this.offset, this.offset + stringByteLength);
this.dump(`${UhkBuffer.stringEncoding}(${str})`);
this.bytesToBacktrack = stringByteLength;
this.offset += stringByteLength;
@@ -134,7 +134,7 @@ export class UhkBuffer {
}
writeString(str: string): void {
let stringByteLength = Buffer.byteLength(str, UhkBuffer.stringEncoding);
const stringByteLength = Buffer.byteLength(str, UhkBuffer.stringEncoding);
if (stringByteLength > UhkBuffer.maxCompactLength) {
throw `Cannot serialize string: ${stringByteLength} bytes is larger
@@ -156,8 +156,8 @@ export class UhkBuffer {
}
readArray<T>(elementReader: (buffer: UhkBuffer, index?: number) => T): T[] {
let array: T[] = [];
let length = this.readCompactLength();
const array: T[] = [];
const length = this.readCompactLength();
for (let i = 0; i < length; ++i) {
array.push(elementReader(this, i));
}

View File

@@ -1,5 +1,4 @@
import { UhkBuffer } from '../UhkBuffer';
import { Keymap } from './Keymap';
import { Macro } from './Macro';
import { Module } from './Module';

View File

@@ -38,7 +38,7 @@ export class Macro {
this.isLooped = buffer.readBoolean();
this.isPrivate = buffer.readBoolean();
this.name = buffer.readString();
let macroActionsLength: number = buffer.readCompactLength();
const macroActionsLength: number = buffer.readCompactLength();
this.macroActions = [];
for (let i = 0; i < macroActionsLength; ++i) {
this.macroActions.push(MacroActionHelper.createMacroAction(buffer));

View File

@@ -1,7 +1,6 @@
import { assertEnum, assertUInt8 } from '../assert';
import { UhkBuffer } from '../UhkBuffer';
import { Helper as KeyActionHelper, KeyAction, NoneAction } from './key-action';
import { Keymap } from './Keymap';
import { Macro } from './Macro';
import { PlayMacroAction, SwitchLayerAction } from './key-action';
@@ -42,7 +41,7 @@ export class Module {
fromBinary(buffer: UhkBuffer, macros?: Macro[]): Module {
this.id = buffer.readUInt8();
this.pointerRole = buffer.readUInt8();
let keyActionsLength: number = buffer.readCompactLength();
const keyActionsLength: number = buffer.readCompactLength();
this.keyActions = [];
for (let i = 0; i < keyActionsLength; ++i) {
this.keyActions.push(KeyActionHelper.createKeyAction(buffer, macros));

View File

@@ -32,17 +32,17 @@ export let keyActionType = {
export abstract class KeyAction {
assertKeyActionType(jsObject: any): void {
let keyActionClassname: string = this.constructor.name;
let keyActionTypeString: string = keyActionType[keyActionClassname];
const keyActionClassname: string = this.constructor.name;
const keyActionTypeString: string = keyActionType[keyActionClassname];
if (jsObject.keyActionType !== keyActionTypeString) {
throw `Invalid ${keyActionClassname}.keyActionType: ${jsObject.keyActionType}`;
}
}
readAndAssertKeyActionId(buffer: UhkBuffer): KeyActionId {
let classname: string = this.constructor.name;
let readKeyActionId: number = buffer.readUInt8();
let keyActionId: number = KeyActionId[classname];
const classname: string = this.constructor.name;
const readKeyActionId: number = buffer.readUInt8();
const keyActionId: number = KeyActionId[classname];
if (keyActionId === KeyActionId.KeystrokeAction) {
if (readKeyActionId < KeyActionId.KeystrokeAction || readKeyActionId > KeyActionId.LastKeystrokeAction) {
throw `Invalid ${classname} first byte: ${readKeyActionId}`;

View File

@@ -49,8 +49,8 @@ export class KeystrokeAction extends KeyAction {
}
fromBinary(buffer: UhkBuffer): KeystrokeAction {
let keyActionId: KeyActionId = this.readAndAssertKeyActionId(buffer);
let flags: number = keyActionId - KeyActionId.KeystrokeAction;
const keyActionId: KeyActionId = this.readAndAssertKeyActionId(buffer);
const flags: number = keyActionId - KeyActionId.KeystrokeAction;
if (flags & KeystrokeActionFlag.scancode) {
this.scancode = buffer.readUInt8();
}
@@ -64,7 +64,7 @@ export class KeystrokeAction extends KeyAction {
}
toJsonObject(): JsonObjectKeystrokeAction {
let jsonObject: JsonObjectKeystrokeAction = {
const jsonObject: JsonObjectKeystrokeAction = {
keyActionType: keyActionType.KeystrokeAction
};
@@ -85,7 +85,7 @@ export class KeystrokeAction extends KeyAction {
toBinary(buffer: UhkBuffer) {
let flags = 0;
let bufferData: number[] = [];
const bufferData: number[] = [];
if (this.hasScancode()) {
flags |= KeystrokeActionFlag.scancode;
@@ -109,7 +109,7 @@ export class KeystrokeAction extends KeyAction {
}
toString(): string {
let properties: string[] = [];
const properties: string[] = [];
if (this.hasScancode()) {
properties.push(`scancode="${this.scancode}"`);
}
@@ -144,7 +144,7 @@ export class KeystrokeAction extends KeyAction {
}
getModifierList(): string[] {
let modifierList: string[] = [];
const modifierList: string[] = [];
let modifierMask = this.modifierMask;
for (let i = 0; modifierMask !== 0; ++i, modifierMask >>= 1) {
if (modifierMask & 1) {

View File

@@ -10,7 +10,6 @@ import {
keyActionType
} from './index';
import { Keymap } from '../Keymap';
import { Macro } from '../Macro';
export class Helper {
@@ -26,7 +25,7 @@ export class Helper {
}
private static fromUhkBuffer(buffer: UhkBuffer, macros: Macro[]): KeyAction {
let keyActionFirstByte = buffer.readUInt8();
const keyActionFirstByte = buffer.readUInt8();
buffer.backtrack();
if (keyActionFirstByte >= KeyActionId.KeystrokeAction && keyActionFirstByte < KeyActionId.LastKeystrokeAction) {

View File

@@ -93,13 +93,13 @@ export class EditableMacroAction {
}
fromKeyAction(keyAction: KeyAction): void {
let data = keyAction.toJsonObject();
const data = keyAction.toJsonObject();
this.scancode = data.scancode;
this.modifierMask = data.modifierMask;
}
toKeystrokeAction(): KeystrokeAction {
let data = this.toJsObject();
const data = this.toJsObject();
data.keyActionType = keyActionType.KeystrokeAction;
return <KeystrokeAction>(new KeystrokeAction().fromJsonObject(data));
}
@@ -113,7 +113,7 @@ export class EditableMacroAction {
}
getMouseButtons(): boolean[] {
let enabledMouseButtons: boolean[] = [];
const enabledMouseButtons: boolean[] = [];
for (let bitmask = this.mouseButtonsMask; bitmask; bitmask >>>= 1) {
enabledMouseButtons.push(Boolean(bitmask & 1));
}

View File

@@ -42,7 +42,7 @@ export class KeyMacroAction extends MacroAction {
}
fromBinary(buffer: UhkBuffer): KeyMacroAction {
let macroActionId: MacroActionId = this.readAndAssertMacroActionId(buffer);
const macroActionId: MacroActionId = this.readAndAssertMacroActionId(buffer);
let keyMacroType: number = macroActionId - MacroActionId.KeyMacroAction;
this.action = Math.floor(keyMacroType / NUM_OF_COMBINATIONS);
keyMacroType %= NUM_OF_COMBINATIONS;
@@ -56,7 +56,7 @@ export class KeyMacroAction extends MacroAction {
}
toJsonObject(): any {
let jsObject: JsObjectKeyMacroAction = {
const jsObject: JsObjectKeyMacroAction = {
macroActionType: macroActionType.KeyMacroAction,
action: MacroSubAction[this.action]
};

View File

@@ -46,17 +46,17 @@ export let macroActionType = {
export abstract class MacroAction {
assertMacroActionType(jsObject: any) {
let macroActionClassname = this.constructor.name;
let macroActionTypeString = macroActionType[macroActionClassname];
const macroActionClassname = this.constructor.name;
const macroActionTypeString = macroActionType[macroActionClassname];
if (jsObject.macroActionType !== macroActionTypeString) {
throw `Invalid ${macroActionClassname}.macroActionType: ${jsObject.macroActionType}`;
}
}
readAndAssertMacroActionId(buffer: UhkBuffer): MacroActionId {
let classname: string = this.constructor.name;
let readMacroActionId: MacroActionId = buffer.readUInt8();
let macroActionId: MacroActionId = MacroActionId[classname];
const classname: string = this.constructor.name;
const readMacroActionId: MacroActionId = buffer.readUInt8();
const macroActionId: MacroActionId = MacroActionId[classname];
if (macroActionId === MacroActionId.KeyMacroAction) {
if (readMacroActionId < MacroActionId.KeyMacroAction || readMacroActionId > MacroActionId.LastKeyMacroAction) {
throw `Invalid ${classname} first byte: ${readMacroActionId}`;

View File

@@ -38,7 +38,7 @@ export class MouseButtonMacroAction extends MacroAction {
}
fromBinary(buffer: UhkBuffer): MouseButtonMacroAction {
let macroActionId: MacroActionId = this.readAndAssertMacroActionId(buffer);
const macroActionId: MacroActionId = this.readAndAssertMacroActionId(buffer);
this.action = macroActionId - MacroActionId.MouseButtonMacroAction;
this.mouseButtonsMask = buffer.readUInt8();
return this;
@@ -66,7 +66,7 @@ export class MouseButtonMacroAction extends MacroAction {
}
getMouseButtons(): boolean[] {
let enabledMouseButtons: boolean[] = [];
const enabledMouseButtons: boolean[] = [];
for (let bitmask = this.mouseButtonsMask; bitmask; bitmask >>>= 1) {
enabledMouseButtons.push(Boolean(bitmask & 1));
}

View File

@@ -24,7 +24,7 @@ export class Helper {
}
private static fromUhkBuffer(buffer: UhkBuffer): MacroAction {
let macroActionFirstByte = buffer.readUInt8();
const macroActionFirstByte = buffer.readUInt8();
buffer.backtrack();
if (macroActionFirstByte >= MacroActionId.KeyMacroAction && macroActionFirstByte <= MacroActionId.LastKeyMacroAction) {

View File

@@ -27,7 +27,7 @@ export class MapperService {
}
public scanCodeToSvgImagePath(scanCode: number): string {
let fileName: string = this.scanCodeFileName.get(scanCode);
const fileName: string = this.scanCodeFileName.get(scanCode);
if (fileName) {
return 'assets/compiled_sprite.svg#' + fileName;
}

View File

@@ -8,8 +8,6 @@ import 'rxjs/add/operator/do';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/withLatestFrom';
import { Macro } from '../../config-serializer/config-items/Macro';
import { KeymapActions, MacroActions } from '../actions';
import { AppState } from '../index';

View File

@@ -5,7 +5,7 @@ import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/map';
import { Helper as KeyActionHelper, KeyAction, SwitchKeymapAction } from '../../config-serializer/config-items/key-action';
import { Helper as KeyActionHelper, KeyAction } from '../../config-serializer/config-items/key-action';
import { Keymap } from '../../config-serializer/config-items/Keymap';
import { Macro } from '../../config-serializer/config-items/Macro';
import { UserConfiguration } from '../../config-serializer/config-items/UserConfiguration';
@@ -74,7 +74,7 @@ export default function (state = initialState, action: Action): UserConfiguratio
case KeymapActions.REMOVE:
let isDefault: boolean;
let filtered: Keymap[] = state.keymaps.filter((keymap: Keymap) => {
const filtered: Keymap[] = state.keymaps.filter((keymap: Keymap) => {
if (keymap.abbreviation === action.payload) {
isDefault = keymap.isDefault;
return false;
@@ -306,8 +306,8 @@ function generateMacroId(macros: Macro[]) {
}
function checkExistence(layers: Layer[], property: string, value: any) {
let newLayers = layers.map((layer) => {
let newLayer = new Layer(layer);
const newLayers = layers.map(layer => {
const newLayer = new Layer(layer);
newLayer.modules = layer.modules.map((module: Module) => {
module.keyActions.forEach((action: KeyAction, index: number) => {

View File

@@ -3,10 +3,8 @@ import { Injectable } from '@angular/core';
import { Action } from '@ngrx/store';
import { Keymap } from '../../config-serializer/config-items/Keymap';
import { Macro } from '../../config-serializer/config-items/Macro';
import { UserConfiguration } from '../../config-serializer/config-items/UserConfiguration';
import { KeymapActions, MacroActions } from '../actions';
import { AppState } from '../index';
import { Electron } from './electron';
import { Local } from './local';

View File

@@ -5,7 +5,7 @@ export class Local {
constructor(private dataModelVersion: number) { }
getConfig(): UserConfiguration {
let configJsonString = localStorage.getItem('config');
const configJsonString = localStorage.getItem('config');
let config: UserConfiguration;
if (configJsonString) {

View File

@@ -1,27 +1,27 @@
import { UserConfiguration } from '../shared/src/config-serializer/config-items/UserConfiguration';
import { UhkBuffer } from '../shared/src/config-serializer/UhkBuffer';
let assert = require('assert');
let fs = require('fs');
const assert = require('assert');
const fs = require('fs');
let userConfig = JSON.parse(fs.readFileSync('../shared/src/config-serializer/user-config.json'));
const userConfig = JSON.parse(fs.readFileSync('../shared/src/config-serializer/user-config.json'));
let config1Js = userConfig;
let config1Ts: UserConfiguration = new UserConfiguration().fromJsonObject(config1Js);
let config1Buffer = new UhkBuffer();
const config1Js = userConfig;
const config1Ts: UserConfiguration = new UserConfiguration().fromJsonObject(config1Js);
const config1Buffer = new UhkBuffer();
config1Ts.toBinary(config1Buffer);
let config1BufferContent = config1Buffer.getBufferContent();
const config1BufferContent = config1Buffer.getBufferContent();
fs.writeFileSync('user-config.bin', config1BufferContent);
config1Buffer.offset = 0;
console.log();
let config2Ts = new UserConfiguration().fromBinary(config1Buffer);
const config2Ts = new UserConfiguration().fromBinary(config1Buffer);
console.log('\n');
let config2Js = config2Ts.toJsonObject();
let config2Buffer = new UhkBuffer();
const config2Js = config2Ts.toJsonObject();
const config2Buffer = new UhkBuffer();
config2Ts.toBinary(config2Buffer);
fs.writeFileSync('user-config-serialized.json', JSON.stringify(config2Js, undefined, 4));
let config2BufferContent = config1Buffer.getBufferContent();
const config2BufferContent = config1Buffer.getBufferContent();
fs.writeFileSync('user-config-serialized.bin', config2BufferContent);
console.log('\n');

View File

@@ -17,6 +17,13 @@
"no-unused-expression": true,
"no-use-before-declare": true,
"no-var-keyword": true,
"space-before-function-paren": false,
"import-spacing": true,
"prefer-const": true,
"arrow-parens": [
true,
"ban-single-arg-parens"
],
"radix": true,
"switch-default": true,
"triple-equals": true,

View File

@@ -1,5 +1,5 @@
import { ModuleWithProviders } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { RouterModule, Routes } from '@angular/router';
import { addOnRoutes } from '../shared/components/add-on';
import { keymapRoutes } from '../components/keymap';
@@ -13,6 +13,6 @@ const appRoutes: Routes = [
...settingsRoutes
];
export const appRoutingProviders: any[] = [ ];
export const appRoutingProviders: any[] = [];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes, { useHash: true });
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes, { useHash: true });