Skip to content

Commit

Permalink
chore(common): fixing core's tslint errors (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
Margar1ta authored and pimenovoleg committed Oct 18, 2019
1 parent 4e6ac46 commit 1e2ab10
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 41 deletions.
21 changes: 11 additions & 10 deletions packages/mosaic/autocomplete/autocomplete-trigger.directive.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import { Directionality } from '@angular/cdk/bidi';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
import {
ConnectedPosition,
FlexibleConnectedPositionStrategy,
Overlay,
OverlayConfig,
OverlayRef,
PositionStrategy,
ScrollStrategy
} from '@angular/cdk/overlay';
import { TemplatePortal } from '@angular/cdk/portal';
import { ViewportRuler } from '@angular/cdk/scrolling';
import { DOCUMENT } from '@angular/common';
import {
ChangeDetectorRef,
Expand All @@ -17,16 +28,6 @@ import {
} from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { DOWN_ARROW, ENTER, ESCAPE, TAB, UP_ARROW } from '@ptsecurity/cdk/keycodes';
import {
FlexibleConnectedPositionStrategy,
Overlay,
OverlayConfig,
OverlayRef,
PositionStrategy,
ScrollStrategy, ConnectedPosition
} from '@angular/cdk/overlay';
import { TemplatePortal } from '@angular/cdk/portal';
import { ViewportRuler } from '@angular/cdk/scrolling';
import {
countGroupLabelsBeforeOption,
getOptionScrollPosition,
Expand Down
9 changes: 4 additions & 5 deletions packages/mosaic/autocomplete/autocomplete.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// tslint:disable:no-magic-numbers
// tslint:disable:no-unbound-method
// tslint:disable:mocha-no-side-effect-code
// tslint:disable:max-func-body-length
// tslint:disable:no-inferred-empty-object-type
// tslint:disable:chai-vague-errors
import { Directionality } from '@angular/cdk/bidi';
import { Overlay, OverlayContainer } from '@angular/cdk/overlay';
import { ScrollDispatcher } from '@angular/cdk/scrolling';
import {
ChangeDetectionStrategy,
Component,
Expand All @@ -28,10 +30,7 @@ import {
import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { By } from '@angular/platform-browser';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { Directionality } from '@angular/cdk/bidi';
import { DOWN_ARROW, ENTER, ESCAPE, SPACE, TAB, UP_ARROW } from '@ptsecurity/cdk/keycodes';
import { Overlay, OverlayContainer } from '@angular/cdk/overlay';
import { ScrollDispatcher } from '@angular/cdk/scrolling';
import {
createKeyboardEvent,
dispatchFakeEvent,
Expand Down Expand Up @@ -1643,7 +1642,7 @@ describe('McAutocomplete', () => {
zone.simulateZoneExit();

expect(spy).toHaveBeenCalledWith(jasmine.any(McOptionSelectionChange));
subscription!.unsubscribe();
subscription.unsubscribe();
}));

xit('should reposition the panel when the amount of options changes', fakeAsync(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/mosaic/card/card.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
OnDestroy, EventEmitter,
ViewEncapsulation, HostBinding
} from '@angular/core';

import { FocusMonitor } from '@ptsecurity/cdk/a11y';
import { SPACE } from '@ptsecurity/cdk/keycodes';

Expand Down Expand Up @@ -73,6 +72,7 @@ export class McCard implements OnDestroy {
}

onKeyDown($event: KeyboardEvent) {
// tslint:disable-next-line:deprecation
switch ($event.keyCode) {
case SPACE:
if (!this.readonly) {
Expand Down
6 changes: 4 additions & 2 deletions packages/mosaic/core/common-behaviors/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { ElementRef } from '@angular/core';
import { Constructor } from './constructor';


// tslint:disable-next-line:naming-convention
export interface CanColor {
color: ThemePalette;
}

/** @docs-private */
export type CanColorCtor = Constructor<CanColor>;

// tslint:disable-next-line:naming-convention
export interface HasElementRef {
_elementRef: ElementRef;
}
Expand All @@ -29,8 +31,6 @@ export function mixinColor<T extends Constructor<HasElementRef>>(
): CanColorCtor & T {
return class extends base {

private _color: ThemePalette;

get color(): ThemePalette {
return this._color;
}
Expand All @@ -51,6 +51,8 @@ export function mixinColor<T extends Constructor<HasElementRef>>(
}
}

private _color: ThemePalette;

constructor(...args: any[]) {
super(...args);

Expand Down
26 changes: 14 additions & 12 deletions packages/mosaic/core/common-behaviors/common-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import { NgModule, InjectionToken, Optional, Inject, isDevMode } from '@angular/
// Injection token that configures whether the Mosaic sanity checks are enabled.
export const MC_SANITY_CHECKS = new InjectionToken<boolean>('mc-sanity-checks', {
providedIn: 'root',
factory: MC_SANITY_CHECKS_FACTORY
factory: mcSanityChecksFactory
});

export function MC_SANITY_CHECKS_FACTORY(): boolean {
export function mcSanityChecksFactory(): boolean {
return true;
}

Expand All @@ -24,34 +24,36 @@ export function MC_SANITY_CHECKS_FACTORY(): boolean {
})
export class McCommonModule {
// Whether we've done the global sanity checks (e.g. a theme is loaded, there is a doctype).
private _hasDoneGlobalChecks = false;
private hasDoneGlobalChecks = false;

// Reference to the global `document` object.
// tslint:disable-next-line: orthodox-getter-and-setter
private _document = typeof document === 'object' && document ? document : null;

// Reference to the global 'window' object.
// tslint:disable-next-line: orthodox-getter-and-setter
private _window = typeof window === 'object' && window ? window : null;

constructor(@Optional() @Inject(MC_SANITY_CHECKS) private _sanityChecksEnabled: boolean) {
if (this._areChecksEnabled() && !this._hasDoneGlobalChecks) {
this._checkDoctypeIsDefined();
this._checkThemeIsPresent();
this._hasDoneGlobalChecks = true;
if (this.areChecksEnabled() && !this.hasDoneGlobalChecks) {
this.checkDoctypeIsDefined();
this.checkThemeIsPresent();
this.hasDoneGlobalChecks = true;
}
}

// Whether any sanity checks are enabled
private _areChecksEnabled(): boolean {
return this._sanityChecksEnabled && isDevMode() && !this._isTestEnv();
private areChecksEnabled(): boolean {
return this._sanityChecksEnabled && isDevMode() && !this.isTestEnv();
}

// Whether the code is running in tests.
private _isTestEnv() {
private isTestEnv() {
// tslint:disable-next-line
return this._window && (this._window['__karma__'] || this._window['jasmine']);
}

private _checkDoctypeIsDefined(): void {
private checkDoctypeIsDefined(): void {
if (this._document && !this._document.doctype) {
console.warn(
'Current document does not have a doctype. This may cause ' +
Expand All @@ -60,7 +62,7 @@ export class McCommonModule {
}
}

private _checkThemeIsPresent(): void {
private checkThemeIsPresent(): void {
if (this._document && typeof getComputedStyle === 'function') {
const testElement = this._document.createElement('div');

Expand Down
2 changes: 2 additions & 0 deletions packages/mosaic/core/common-behaviors/error-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Constructor } from './constructor';


/** @docs-private */
// tslint:disable-next-line:naming-convention
export interface CanUpdateErrorState {

readonly stateChanges: Subject<void>;
Expand All @@ -21,6 +22,7 @@ export interface CanUpdateErrorState {
export type CanUpdateErrorStateCtor = Constructor<CanUpdateErrorState>;

/** @docs-private */
// tslint:disable-next-line:naming-convention
export interface HasErrorState {
parentFormGroup: FormGroupDirective;
parentForm: NgForm;
Expand Down
1 change: 1 addition & 0 deletions packages/mosaic/core/common-behaviors/tabindex.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// tslint:disable:no-magic-numbers
import { mixinTabIndex } from './tabindex';


Expand Down
1 change: 1 addition & 0 deletions packages/mosaic/core/common-behaviors/tabindex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Constructor } from './constructor';
import { CanDisable } from './disabled';


// tslint:disable-next-line:naming-convention
export interface HasTabIndex {
tabIndex: number;
}
Expand Down
1 change: 1 addition & 0 deletions packages/mosaic/core/label/label-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const MC_LABEL_GLOBAL_OPTIONS =
export type FloatLabelType = 'always' | 'never' | 'auto';

/** Configurable options for floating labels. */
// tslint:disable-next-line:naming-convention
export interface LabelOptions {
/**
* Whether the label should float `always`, `never`, or `auto` (only when necessary).
Expand Down
22 changes: 11 additions & 11 deletions packages/mosaic/core/line/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,29 @@ export class McLine {}
*/
export class McLineSetter {
constructor(private _lines: QueryList<McLine>, private _element: ElementRef) {
this._setLineClass(this._lines.length);
this.setLineClass(this._lines.length);

this._lines.changes.subscribe(() => {
this._setLineClass(this._lines.length);
this.setLineClass(this._lines.length);
});
}

private _setLineClass(count: number): void {
this._resetClasses();
private setLineClass(count: number): void {
this.resetClasses();
if (count === 2 || count === 3) {
this._setClass(`mc-${count}-line`, true);
this.setClass(`mc-${count}-line`, true);
} else if (count > 3) {
this._setClass(`mc-multi-line`, true);
this.setClass(`mc-multi-line`, true);
}
}

private _resetClasses(): void {
this._setClass('mc-2-line', false);
this._setClass('mc-3-line', false);
this._setClass('mc-multi-line', false);
private resetClasses(): void {
this.setClass('mc-2-line', false);
this.setClass('mc-3-line', false);
this.setClass('mc-multi-line', false);
}

private _setClass(className: string, isAdd: boolean): void {
private setClass(className: string, isAdd: boolean): void {
if (isAdd) {
this._element.nativeElement.classList.add(className);
} else {
Expand Down

0 comments on commit 1e2ab10

Please sign in to comment.