Skip to content

Commit 5b27162

Browse files
authored
tslint on CI (#80)
* tslint updated like reyesoft projects * tslint --fix * all ts lint rules applied * minimun coverage and commit hook added * tslint compatibility with prettier * prettier added to CI
1 parent d9ac153 commit 5b27162

35 files changed

+1133
-876
lines changed

.circleci/config.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ jobs:
1111
- restore_cache:
1212
key: *cache_key
1313
- run: yarn
14-
- run: yarn run prettier
14+
- run: yarn prettier-ts:show --list-different
15+
- run: yarn prettier-md:show --list-different
16+
- run: yarn prettier-scss:show --list-different
17+
- run: yarn run ng lint
1518
- save_cache:
1619
key: *cache_key
1720
paths:
@@ -37,8 +40,8 @@ jobs:
3740
# fi
3841
- run: yarn run demo:build
3942
# - run: yarn run demo:test:nowatch
40-
- run: yarn run build
41-
- run: yarn run test
43+
# - run: yarn run build # runned by yarn run demo:build
44+
# - run: yarn run test # runned by yarn run ci
4245

4346
build:
4447
docker:

demo/app/app.module.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { NgModule } from '@angular/core';
22
import { BrowserModule } from '@angular/platform-browser';
33
import { RouterModule, Routes } from '@angular/router';
44
import { HttpClientModule } from '@angular/common/http';
5-
import { environment } from "../environments/environment";
5+
import { environment } from '../environments/environment';
66
import { NgxJsonapiModule } from 'ngx-jsonapi';
77

88
import { AppComponent } from './app.component';

demo/app/authors/authors.service.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { Injectable } from '@angular/core';
2-
import { Service, ISchema, Resource, ICollection } from 'ngx-jsonapi';
2+
import { Autoregister, Service, ISchema, Resource, ICollection } from 'ngx-jsonapi';
33
import { Book } from '../books/books.service';
4-
import { Autoregister } from 'ngx-jsonapi';
54

65
@Injectable()
76
@Autoregister()
87
export class AuthorsService extends Service<Author> {
9-
public resource = Author;
8+
// public resource = Author;
109
public type = 'authors';
1110
public schema: ISchema = {
1211
relationships: {
@@ -37,7 +36,7 @@ export class Author extends Resource {
3736
return <ICollection<Book>>this.relationships.books.data;
3837
}
3938

40-
public photos()/*: ICollection<Photo>*/ {
39+
public photos() /*: ICollection<Photo>*/ {
4140
return <ICollection>this.relationships.photos.data;
4241
}
4342
}

demo/app/authors/components/author.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ <h4>Books</h4>
2929
<tr *ngFor="let book of author.books().$toArray">
3030
<td>{{ book.id }}</td>
3131
<td>
32-
<a>{{ book.attributes.title }}</a>
32+
<a>{{ book.attributes.title }}</a>
3333
</td>
3434
<td>{{ book.attributes.date_published | date }}</td>
3535
</tr>

demo/app/authors/components/author.component.ts

+43-51
Original file line numberDiff line numberDiff line change
@@ -30,60 +30,52 @@ export class AuthorComponent {
3030
this.author = author;
3131
console.info('success author controller', author);
3232
},
33-
error => console.error('Could not load author.'
34-
)
35-
);
36-
});
37-
//
38-
// this.relatedbooks = BooksService.all(
39-
// { beforepath: 'authors/' + $stateParams.authorId },
40-
// () => {
41-
// console.info('Books from authors relationship', this.relatedbooks);
42-
// }
43-
// );
44-
}
45-
46-
/*
47-
Add a new author
48-
*/
49-
public newAuthor() {
50-
let author = this.authorsService.new();
51-
author.attributes.name = prompt('New author name:', 'John Doe');
52-
if (!author.attributes.name) {
53-
return ;
33+
error => console.error('Could not load author.', error)
34+
);
35+
});
5436
}
55-
author.attributes.date_of_birth = '2030-12-10';
56-
console.log('author data for save', author.toObject());
57-
author.save(
58-
/* { include: ['book'] } */
59-
success => {
60-
console.log('author saved', author.toObject());
61-
}
62-
);
63-
}
6437

65-
/*
66-
Update name for actual author
67-
*/
68-
public updateAuthor() {
69-
this.author.attributes.name = prompt('Author name:', this.author.attributes.name);
70-
console.log('author data for save with book include', this.author.toObject({ include: ['books'] }));
71-
console.log('author data for save without any include', this.author.toObject());
72-
this.author.save(
73-
/* { include: ['book'] } */
74-
success => {
75-
console.log('author saved', this.author.toObject());
38+
/*
39+
Add a new author
40+
*/
41+
public newAuthor() {
42+
let author = this.authorsService.new();
43+
author.attributes.name = prompt('New author name:', 'John Doe');
44+
if (!author.attributes.name) {
45+
return ;
7646
}
77-
);
78-
}
47+
author.attributes.date_of_birth = '2030-12-10';
48+
console.log('author data for save', author.toObject());
49+
author.save(
50+
/* { include: ['book'] } */
51+
success => {
52+
console.log('author saved', author.toObject());
53+
}
54+
);
55+
}
7956

80-
public getPhotos(author: Resource): Array<Resource> {
81-
return (<ICollection>author.relationships.photos.data).$toArray;
82-
}
57+
/*
58+
Update name for actual author
59+
*/
60+
public updateAuthor() {
61+
this.author.attributes.name = prompt('Author name:', this.author.attributes.name);
62+
console.log('author data for save with book include', this.author.toObject({ include: ['books'] }));
63+
console.log('author data for save without any include', this.author.toObject());
64+
this.author.save(
65+
/* { include: ['book'] } */
66+
success => {
67+
console.log('author saved', this.author.toObject());
68+
}
69+
);
70+
}
8371

84-
public removeRelationship() {
85-
this.author.removeRelationship('photos', '1');
86-
this.author.save();
87-
console.log('removeRelationship save with photos include', this.author.toObject());
88-
}
72+
public getPhotos(author: Resource): Array<Resource> {
73+
return (<ICollection>author.relationships.photos.data).$toArray;
74+
}
75+
76+
public removeRelationship() {
77+
this.author.removeRelationship('photos', '1');
78+
this.author.save();
79+
console.log('removeRelationship save with photos include', this.author.toObject());
80+
}
8981
}

demo/app/authors/components/authors.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ <h3>Authors</h3>
1212
<tr *ngFor="let author of authors.$toArray">
1313
<td>{{ author.id }}</td>
1414
<td>
15-
<a [routerLink]="['/authors', author.id]">{{ author.attributes.name }}</a>
15+
<a [routerLink]="['/authors', author.id]">{{ author.attributes.name }}</a>
1616
</td>
1717
<td>{{ author.attributes.date_of_birth | date }}</td>
1818
<td>{{ author.attributes.date_of_death | date }}</td>

demo/app/authors/components/authors.component.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2-
import { RouterTestingModule } from "@angular/router/testing";
2+
import { RouterTestingModule } from '@angular/router/testing';
33

44
import { AuthorsService } from '../authors.service';
55
import { AuthorsComponent } from './authors.component';
@@ -26,7 +26,7 @@ describe('AuthorsComponent', () => {
2626
it('should create', () => {
2727
expect(component).toBeTruthy();
2828
});
29-
it('authors should be filled', () =>{
29+
it('authors should be filled', () => {
3030
expect(component.authors).toBeTruthy();
3131
});
3232
});

demo/app/books/books.service.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { Injectable } from '@angular/core';
2-
import { Service, ISchema, Resource, ICollection } from 'ngx-jsonapi';
2+
import { Autoregister, Service, ISchema, Resource, ICollection } from 'ngx-jsonapi';
33
import { Author } from '../authors/authors.service';
44
import { Photo } from '../photos/photos.service';
5-
import { Autoregister } from 'ngx-jsonapi';
65

76
@Injectable()
87
@Autoregister()

demo/app/books/components/book.component.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ export class BookComponent {
3737
console.log('PROMISE success book', this.book);
3838
},
3939
error => console.log('PROMISE error books controll', error)
40-
)
40+
);
4141
});
4242

4343
}
4444

4545
public getAuthorName(book: Resource): string {
4646
let data = <Resource>book.relationships.author.data;
47+
4748
return data.attributes ? data.attributes.name : '';
4849
}
4950
}

demo/app/books/components/books.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ <h3>Books</h3>
2121
<tr *ngFor="let book of books.$toArray">
2222
<td>{{ book.id }}</td>
2323
<td>
24-
<a [routerLink]="['/books', book.id]">{{ book.attributes.title }}</a>
24+
<a [routerLink]="['/books', book.id]">{{ book.attributes.title }}</a>
2525
</td>
2626
<td>{{ book.attributes.date_published | date }}</td>
2727
<td>{{ book.relationships.author.data.attributes.name }} #{{ book.relationships.author.data.id }}</td>

demo/app/books/components/books.component.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export class BooksComponent {
2727
this.books = books;
2828
console.info('success books controll', this.books);
2929
},
30-
error => console.info('error books controll', error)
31-
)
30+
(error): void => console.info('error books controll', error)
31+
);
3232
}
3333

3434
public getAll(remotefilter) {
@@ -76,13 +76,11 @@ export class BooksComponent {
7676
console.log('BookRequest#3 requested');
7777
let book1 = this.booksService.get('1',
7878
success1 => {
79-
console.log('BookRequest#3 received (author data from cache)' //,
80-
//(<Resource>book1.relationships.author.data).attributes
81-
);
79+
console.log('BookRequest#3 received (author data from cache)');
8280
}
8381
);
8482
},
85-
error => console.log('error books controller', error)
83+
error => console.info('error books controller', error)
8684
);
8785
books$.toPromise().then(
8886
success => console.log('books loaded PROMISE')

demo/app/photos/photos.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ <h3>photos</h3>
1010
</thead>
1111
<tr *ngFor="let photo of photos.$toArray">
1212
<td>{{ photo.id }}</td>
13-
<td>{{ photo.attributes.title }}</td>
13+
<td>{{ photo.attributes.title }}</td>
1414
<td>{{ photo.attributes.uri }}</td>
1515
</tr>
1616
</table>

demo/app/photos/photos.service.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import { Service, ISchema, Resource } from 'ngx-jsonapi';
33

44
@Injectable()
55
export class PhotosService extends Service {
6-
public resource = Photo;
6+
// public resource = Photo;
77
public type = 'photos';
88
}
99

1010
export class Photo extends Resource {
1111
public attributes: {
12-
title: string,
13-
uri: string,
14-
imageable_id: string,
15-
created_at: string,
16-
updated_at: string
12+
title: string;
13+
uri: string;
14+
imageable_id: string;
15+
created_at: string;
16+
updated_at: string;
1717
};
1818
}

e2e/app.e2e-spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ExampleAppPage } from './app.po';
22

3-
describe('demo App', function() {
3+
describe('demo App', () => {
44
let page: ExampleAppPage;
55

66
beforeEach(() => {

e2e/app.po.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { browser, element, by } from 'protractor';
22

33
export class ExampleAppPage {
4-
navigateTo() {
4+
public async navigateTo() {
55
return browser.get('/');
66
}
77

8-
getAppDescription() {
8+
public async getAppDescription() {
99
return element(by.css('mat-toolbar-row')).getText();
1010
}
1111
}

package.json

+12-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"build": "ts-node ./build/index.ts",
66
"postbuild": "rimraf **/dist/**/*.ngsummary.json",
77
"deploy:builds": "ts-node ./build/deploy-build.ts",
8+
"lint": "ng lint",
89
"test:unit": "node ./tests.js",
910
"test": "nyc yarn run test:unit",
1011
"clean": "git clean -xdf && yarn && yarn run bootstrap",
@@ -30,7 +31,8 @@
3031
"prettier-md": "yarn prettier-md:show --write",
3132
"prettier-md:show": "prettier --parser markdown --single-quote es5 --tab-width 4 --print-width 140 --single-quote true --prose-wrap never \"**/*.md\"",
3233
"prettier-scss": "yarn prettier-scss:show --write",
33-
"prettier-scss:show": "prettier --parser scss --single-quote es5 --tab-width 4 --print-width 140 --single-quote true \"**/*.scss\""
34+
"prettier-scss:show": "prettier --parser scss --single-quote es5 --tab-width 4 --print-width 140 --single-quote true \"**/*.scss\"",
35+
"precommit": "lint-staged"
3436
},
3537
"lint-staged": {
3638
"*.ts": [
@@ -58,9 +60,8 @@
5860
},
5961
"keywords": [
6062
"jsonapi",
61-
"angular",
62-
"angular2",
63-
"angular4"
63+
"json-api",
64+
"angular"
6465
],
6566
"authors": [
6667
"Pablo Gabriel Reyes"
@@ -71,6 +72,10 @@
7172
"url": "https://github.com/reyesoft/ngx-jsonapi"
7273
},
7374
"nyc": {
75+
"statements": 25,
76+
"branches": 2,
77+
"functions": 15,
78+
"lines": 25,
7479
"extension": [
7580
".ts"
7681
],
@@ -109,7 +114,7 @@
109114
"@types/rimraf": "^0.0.28",
110115
"chokidar": "^1.7.0",
111116
"chokidar-cli": "^1.2.0",
112-
"codelyzer": "^2.1.1",
117+
"codelyzer": "4.2.1",
113118
"conventional-changelog": "^1.1.4",
114119
"core-js": "^2.4.1",
115120
"coveralls": "^2.13.0",
@@ -136,6 +141,7 @@
136141
"ncp": "^2.0.0",
137142
"nyc": "^10.1.2",
138143
"ora": "^1.3.0",
144+
"lint-staged": "7.0.4",
139145
"prettier": "^1.12.0",
140146
"protractor": "~5.1.0",
141147
"reflect-metadata": "^0.1.9",
@@ -144,7 +150,7 @@
144150
"sorcery": "^0.10.0",
145151
"ts-node": "^3.1.0",
146152
"tslib": "1.6.0",
147-
"tslint": "^4.4.2",
153+
"tslint": "5.10.0",
148154
"typescript": "~2.4.0",
149155
"uglify-js": "^3.1.9",
150156
"zone.js": "^0.8.12"

scripts/yarn-install.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"use strict";
2+
3+
const exec = require("child_process").exec;
4+
5+
const runIfYarn = fn => {
6+
exec("yarn -V", error => {
7+
if (error === null) fn();
8+
});
9+
};
10+
runIfYarn(() => {
11+
console.log("`package.json` was changed. Running yarn...🐈");
12+
exec("yarn");
13+
});

0 commit comments

Comments
 (0)