Skip to content
This repository was archived by the owner on Aug 25, 2020. It is now read-only.

Commit 36a461e

Browse files
committed
fix: lint
1 parent f9aaeb0 commit 36a461e

22 files changed

+163
-163
lines changed

angular.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
"builder": "@angular-devkit/build-angular:tslint",
2929
"options": {
3030
"tsConfig": [
31-
"projects/ngx-forms/tsconfig.lib.json",
32-
"projects/ngx-forms/tsconfig.spec.json"
31+
"projects/ngx-forms/tsconfig.lib.json"
3332
],
3433
"exclude": [
3534
"**/node_modules/**"

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"build": "ng build",
88
"test": "ng test --watch=false",
99
"lint": "ng lint",
10+
"lint:fix": "tslint --fix -p tsconfig.json -c tslint.json",
1011
"e2e": "ng e2e"
1112
},
1213
"dependencies": {

projects/ngx-forms/src/lib/common/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface FieldConfig {
2424
export interface Field {
2525
field: FieldConfig;
2626
group: FormGroup;
27-
model?: Object;
27+
model?: object;
2828
}
2929

3030
export type Type<T> = new (...args: any[]) => T;
@@ -53,4 +53,4 @@ export interface FormsExtensions {
5353
layoutDictionary?: LayoutDictionary;
5454
}
5555

56-
export const DEFAULT_LAYOUT = "default";
56+
export const DEFAULT_LAYOUT = 'default';

projects/ngx-forms/src/lib/dynamic-field/dynamic-field.directive.spec.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { CommonModule } from '@angular/common';
33
import { Component } from '@angular/core';
44
import { FormsModule, ReactiveFormsModule, FormGroup, FormBuilder, FormControl, ValidationErrors } from '@angular/forms';
55
import { ComponentFixture, TestBed } from '@angular/core/testing';
6-
import { DynamicFieldDirective } from "./dynamic-field.directive"
6+
import { DynamicFieldDirective } from './dynamic-field.directive';
77
import { By } from '@angular/platform-browser';
8-
import { FieldConfig, FieldDictionary, FIELD_DICT_TOKEN, Field } from "../common/types";
8+
import { FieldConfig, FieldDictionary, FIELD_DICT_TOKEN, Field } from '../common/types';
99

1010
@Component({
1111
selector: 'form-input',
@@ -18,7 +18,7 @@ export class FormInputComponent implements Field {
1818

1919
const defaultInputs: FieldDictionary = {
2020
text: FormInputComponent,
21-
}
21+
};
2222

2323
@Component({
2424
template: `<form [formGroup]="form"><div dynamicField [field]="field" [group]="form"></div></form>`
@@ -53,7 +53,7 @@ describe('DynamicFieldDirective', () => {
5353

5454
fixture = TestBed.createComponent(TestComponent);
5555
component = fixture.componentInstance;
56-
component.field = { "type": "text", "label": "Title", "name": "publicationTitle", "placeholder": "Please enter", "required": true };
56+
component.field = { type: 'text', label: 'Title', name: 'publicationTitle', placeholder: 'Please enter', required: true };
5757
component.form = formBuilder.group({
5858
publicationTitle: new FormControl('test')
5959
});
@@ -70,14 +70,14 @@ describe('DynamicFieldDirective', () => {
7070
it('throws error when put incorrect type', () => {
7171
fixtureError = TestBed.createComponent(TestComponent);
7272
componentError = fixtureError.componentInstance;
73-
componentError.field = { "type": "text2", "label": "Title", "name": "publicationTitle", "placeholder": "Please enter", "required": true };
73+
componentError.field = { type: 'text2', label: 'Title', name: 'publicationTitle', placeholder: 'Please enter', required: true };
7474
componentError.form = formBuilder.group({
7575
publicationTitle: new FormControl('test')
7676
});
7777

7878
expect(() => {
7979
fixtureError.detectChanges();
80-
}).toThrowError()
80+
}).toThrowError();
8181

8282
});
8383

@@ -90,12 +90,12 @@ describe('DynamicFieldDirective', () => {
9090
dir = directiveEl.injector.get(DynamicFieldDirective);
9191
});
9292

93-
let cfg = { name: 'test', type: 'text', disabled: true, required: true, minLength: 5, maxLength: 10, email: true, min: 1, max: 10, pattern: new RegExp('\d'), nullValidator: true, value: 5 };
93+
const cfg = { name: 'test', type: 'text', disabled: true, required: true, minLength: 5, maxLength: 10, email: true, min: 1, max: 10, pattern: new RegExp('\d'), nullValidator: true, value: 5 };
9494

9595
it('should test', () => {
96-
dir.model = { "publicationTitle": "123"}
96+
dir.model = { publicationTitle: '123'};
9797
dir.ngOnInit();
98-
expect(dir.group.value['publicationTitle']).toEqual("123");
98+
expect(dir.group.value.publicationTitle).toEqual('123');
9999
});
100100

101101
it('shoulld test constructor', () => {
@@ -112,58 +112,58 @@ describe('DynamicFieldDirective', () => {
112112
});
113113

114114
it('should set pattern validator', () => {
115-
let control = dir.createControl({ name: 'test', type: 'text', pattern: new RegExp('\d'), value: 5 });
115+
const control = dir.createControl({ name: 'test', type: 'text', pattern: new RegExp('\d'), value: 5 });
116116
const vals = control.validator(control);
117117
expect(vals.pattern).toBeTruthy();
118118
});
119119

120120
it('should set email validator', () => {
121-
let control = dir.createControl({ name: 'test', type: 'text', email: true, value: 5 });
121+
const control = dir.createControl({ name: 'test', type: 'text', email: true, value: 5 });
122122
const vals = control.validator(control);
123123
expect(vals.email).toBeTruthy();
124124
});
125125

126126
it('should set min length validator', () => {
127-
let control = dir.createControl({ name: 'test', type: 'text', minLength: 5, maxLength: 10, value: 'test' });
127+
const control = dir.createControl({ name: 'test', type: 'text', minLength: 5, maxLength: 10, value: 'test' });
128128
const vals = control.validator(control);
129129
expect(vals.minlength).toBeTruthy();
130130
});
131131

132132
it('should set max length validator', () => {
133-
let control = dir.createControl({ name: 'test', type: 'text', maxLength: 2, value: 'test' });
133+
const control = dir.createControl({ name: 'test', type: 'text', maxLength: 2, value: 'test' });
134134
const vals = control.validator(control);
135135
expect(vals.maxlength).toBeTruthy();
136136
});
137137

138138
it('should set required validator', () => {
139-
let control = dir.createControl({ name: 'test', type: 'text', required: true, value: '' });
139+
const control = dir.createControl({ name: 'test', type: 'text', required: true, value: '' });
140140
const vals = control.validator(control);
141141
expect(vals.required).toBeTruthy();
142142
});
143143

144144
it('should set min value validator', () => {
145-
let control = dir.createControl({ name: 'test', type: 'text', min: 2, value: 1 });
145+
const control = dir.createControl({ name: 'test', type: 'text', min: 2, value: 1 });
146146
const vals = control.validator(control);
147147
expect(vals.min).toBeTruthy();
148148
});
149149

150150
it('should set max value validator', () => {
151-
let control = dir.createControl({ name: 'test', type: 'text', max: 2, value: 22 });
151+
const control = dir.createControl({ name: 'test', type: 'text', max: 2, value: 22 });
152152
const vals = control.validator(control);
153153
expect(vals.max).toBeTruthy();
154154
});
155155

156156
it('should set max value validator', () => {
157-
let control = dir.createControl({ name: 'test', type: 'text', max: 2, requiredTrue: true });
157+
const control = dir.createControl({ name: 'test', type: 'text', max: 2, requiredTrue: true });
158158
const vals: ValidationErrors = control.validator(control);
159159
expect(vals.required).toBeTruthy();
160160
});
161-
161+
162162
it('should set value', () => {
163-
let control = dir.createControl(cfg);
163+
const control = dir.createControl(cfg);
164164
expect(control.value).toEqual(cfg.value);
165165
});
166-
166+
167167

168168
});
169169
});
@@ -181,12 +181,12 @@ describe('TestNoGroup', () => {
181181
});
182182

183183
it('should throw error', () => {
184-
expect(() => { fixtureError.detectChanges(); }).toThrowError()
184+
expect(() => { fixtureError.detectChanges(); }).toThrowError();
185185
});
186186
});
187187

188188
describe('TestNoInput', () => {
189-
@Component({ template: `<div dynamicField [group]="form"></div>` }) class TestNoInput { form: any };
189+
@Component({ template: `<div dynamicField [group]="form"></div>` }) class TestNoInput { form: any; }
190190
let fixtureError: ComponentFixture<TestNoInput>;
191191
let component: TestNoInput;
192192
let fixture: ComponentFixture<TestNoInput>;
@@ -206,7 +206,7 @@ describe('TestNoInput', () => {
206206
});
207207

208208
it('should throw error', () => {
209-
expect(() => { fixtureError.detectChanges(); }).toThrowError("Cannot read property 'detectChanges' of undefined")
209+
expect(() => { fixtureError.detectChanges(); }).toThrowError('Cannot read property \'detectChanges\' of undefined');
210210
});
211211

212-
});
212+
});

projects/ngx-forms/src/lib/dynamic-form/dynamic-form.component.spec.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
2-
import { Component, NgModule } from "@angular/core";
3-
import { DynamicFormDirective } from "./dynamic-form.component";
2+
import { Component, NgModule } from '@angular/core';
3+
import { DynamicFormDirective } from './dynamic-form.component';
44
import { ReactiveFormsModule, FormsModule, FormGroup } from '@angular/forms';
55
import { CommonModule } from '@angular/common';
66
import { FieldDictionary, FIELD_DICT_TOKEN, FieldConfig, Field, LAYOUTS_TOKEN, DEFAULT_LAYOUT } from '../common/types';
@@ -21,15 +21,15 @@ export class FormInputComponent implements Field {
2121
group: FormGroup;
2222
}
2323

24-
const defaultInputs: FieldDictionary = { text: FormInputComponent }
25-
const layouts = { test: LayoutComponent, default: LayoutComponent }
24+
const defaultInputs: FieldDictionary = { text: FormInputComponent };
25+
const layouts = { test: LayoutComponent, default: LayoutComponent };
2626

2727
@Component({ template: `<dynamic-form [formConfig]="formConfig" #form="dynamicForm" [model]="data" ></dynamic-form>` })
2828
class TestComponent {
29-
formConfig
29+
formConfig;
3030
data: {};
3131
dynamicForm: {};
32-
model: any
32+
model: any;
3333
}
3434

3535
@NgModule({
@@ -42,7 +42,7 @@ class TestModule { }
4242
describe('DynamicFormDirective', () => {
4343
let component: TestComponent;
4444
let fixture: ComponentFixture<TestComponent>;
45-
let model = { test: 'test', title: 'title' };
45+
const model = { test: 'test', title: 'title' };
4646

4747
beforeEach(() => {
4848
TestBed.configureTestingModule({
@@ -114,11 +114,11 @@ describe('DynamicFormDirective', () => {
114114
});
115115

116116
it('sets ReadOnly mode to true', () => {
117-
dir.readOnly = true
117+
dir.readOnly = true;
118118
dir.ngAfterViewInit();
119119
expect(dir.group.disabled).toBeTruthy();
120120
});
121-
121+
122122
});
123123

124124
});
@@ -136,7 +136,7 @@ describe('DynamicFormDirective', () => {
136136
it('should not throw error', () => {
137137
expect(() => {
138138
fixture.detectChanges();
139-
}).toThrowError()
139+
}).toThrowError();
140140
});
141141
});
142142
});

projects/ngx-forms/src/lib/dynamic-form/dynamic-form.component.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { Input, OnInit, ComponentFactoryResolver, ViewContainerRef, Directive, Inject, AfterViewInit } from '@angular/core';
1+
import { Input, OnInit, ComponentFactoryResolver, ViewContainerRef, Directive, Inject, AfterViewInit, OnChanges } from '@angular/core';
22
import { FormGroup } from '@angular/forms';
33
import { FormConfig, LayoutDictionary, LAYOUTS_TOKEN, Layout, DEFAULT_LAYOUT } from '../common/types';
44

55
@Directive({
66
exportAs: 'dynamicForm',
77
selector: 'dynamic-form'
88
})
9-
export class DynamicFormDirective implements OnInit, AfterViewInit {
9+
export class DynamicFormDirective implements OnInit, AfterViewInit, OnChanges {
1010
@Input() formConfig: FormConfig;
1111
@Input() model: any;
1212
@Input() readOnly: boolean;
@@ -27,8 +27,8 @@ export class DynamicFormDirective implements OnInit, AfterViewInit {
2727
}
2828

2929
public ngOnInit(): void {
30-
if (this.container.length) { return }
31-
if (!this.formConfig.layout) { this.formConfig.layout = DEFAULT_LAYOUT }
30+
if (this.container.length) { return; }
31+
if (!this.formConfig.layout) { this.formConfig.layout = DEFAULT_LAYOUT; }
3232
if (!this.layouts[this.formConfig.layout]) { throw new Error(`Layout with name "${this.formConfig.layout}" was not found`); }
3333

3434
const componentReference = this.layouts[this.formConfig.layout];
@@ -37,7 +37,7 @@ export class DynamicFormDirective implements OnInit, AfterViewInit {
3737
component.instance.group = this.group;
3838
component.instance.formConfig = this.formConfig;
3939
component.instance.model = this.model;
40-
this.comp= component;
40+
this.comp = component;
4141
}
4242

4343
ngAfterViewInit() {

projects/ngx-forms/src/lib/fields/checkbox/checkbox.component.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe('FormCheckboxComponent', () => {
88
let component: Type;
99
let fixture: ComponentFixture<Type>;
1010
let directiveEl;
11-
let value = true;
11+
const value = true;
1212

1313
beforeEach(async(() => {
1414
TestBed.configureTestingModule({
@@ -25,7 +25,7 @@ describe('FormCheckboxComponent', () => {
2525
fixture = TestBed.createComponent(Type);
2626
component = fixture.componentInstance;
2727

28-
component.field = { type: "text", name: "test", required: true };
28+
component.field = { type: 'text', name: 'test', required: true };
2929
component.group = new FormGroup({
3030
test: new FormControl('')
3131
});
@@ -42,7 +42,7 @@ describe('FormCheckboxComponent', () => {
4242
});
4343

4444
it('ensures component is rendered', () => {
45-
let inputs = fixture.debugElement.queryAll(By.css('input'));
45+
const inputs = fixture.debugElement.queryAll(By.css('input'));
4646
expect(inputs.length).toBeGreaterThan(0);
4747
});
4848

projects/ngx-forms/src/lib/fields/hidden/hidden.component.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('FormInputHiddenComponent', () => {
99
let fixture: ComponentFixture<InputHiddenComponent>;
1010
const formBuilder: FormBuilder = new FormBuilder();
1111
let directiveEl;
12-
let value = "Some Test Value";
12+
const value = 'Some Test Value';
1313

1414
beforeEach(async(() => {
1515
TestBed.configureTestingModule({
@@ -26,7 +26,7 @@ describe('FormInputHiddenComponent', () => {
2626
fixture = TestBed.createComponent(InputHiddenComponent);
2727
component = fixture.componentInstance;
2828

29-
component.field = { type: "hidden", name: "test" };
29+
component.field = { type: 'hidden', name: 'test' };
3030
component.group = new FormGroup({
3131
test: new FormControl('')
3232
});
@@ -45,7 +45,7 @@ describe('FormInputHiddenComponent', () => {
4545

4646
it('ensures component is rendered', () => {
4747
directiveEl = fixture.debugElement.query(By.css('input[type=hidden]'));
48-
expect(directiveEl.nativeElement.value).toEqual(value)
48+
expect(directiveEl.nativeElement.value).toEqual(value);
4949
});
5050

5151
});

projects/ngx-forms/src/lib/fields/index.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ import { LabelComponent } from './label/label.component';
1010
import { FieldDictionary } from '../common/types';
1111

1212
export const DefaultFields: FieldDictionary = {
13-
text: InputComponent,
14-
select: SelectComponent,
15-
multicheckbox: MultiCheckboxComponent,
16-
textarea: TextareaComponent,
17-
hidden: InputHiddenComponent,
18-
radio: RadioComponent,
19-
checkbox: CheckboxComponent,
20-
label: LabelComponent,
21-
json: JsonComponent
13+
text: InputComponent,
14+
select: SelectComponent,
15+
multicheckbox: MultiCheckboxComponent,
16+
textarea: TextareaComponent,
17+
hidden: InputHiddenComponent,
18+
radio: RadioComponent,
19+
checkbox: CheckboxComponent,
20+
label: LabelComponent,
21+
json: JsonComponent
2222
};
2323

2424
export const FieldComponents = [
25-
InputComponent,
26-
SelectComponent,
27-
MultiCheckboxComponent,
28-
TextareaComponent,
29-
InputHiddenComponent,
30-
RadioComponent,
31-
CheckboxComponent,
32-
LabelComponent,
33-
JsonComponent
34-
];
25+
InputComponent,
26+
SelectComponent,
27+
MultiCheckboxComponent,
28+
TextareaComponent,
29+
InputHiddenComponent,
30+
RadioComponent,
31+
CheckboxComponent,
32+
LabelComponent,
33+
JsonComponent
34+
];

0 commit comments

Comments
 (0)