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

@@ -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;