Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

Commit e902b72

Browse files
committed
Add linting on the lib
1 parent 2eda333 commit e902b72

33 files changed

+388
-199
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ src/**/*.d.ts
1010
.vscode
1111
coverage
1212
package-lock.json
13-
yarn.lock
13+
yarn.lock
14+
.npmrc
15+
.nvmrc
16+
.yvmrc

.travis.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ services:
99
- xvfb
1010

1111
cache:
12-
yarn: true
12+
npm: true
1313
directories:
1414
- node_modules
1515

16+
script:
17+
- npm run lint
18+
- npm run build
19+
- npm run test
20+
1621
after_success: npm run cover

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 10.1.0
2+
3+
- Add linting [#98](https://github.com/fknop/angular-pipes/pull/98)
4+
15
# 10.0.0
26

37
- Added a module for each pipe [#97](https://github.com/fknop/angular-pipes/pull/97)

package.json

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
{
2+
"$schema": "./node_modules/ng-packagr/package.schema.json",
23
"name": "angular-pipes",
3-
"version": "10.0.0",
4+
"version": "10.1.0",
45
"description": "Angular pipes library",
56
"scripts": {
67
"cover": "cat ./coverage/*/lcovonly | ./node_modules/.bin/coveralls",
78
"karma": "node_modules/.bin/karma start karma.conf.js",
8-
"pretty": "prettier --check '**/*.{ts,scss,js,json,yml,md,html}'",
9-
"pretty:write": "yarn pretty --write",
10-
"packagr": "ng-packagr -p package.json",
9+
"build": "ng-packagr -p package.json",
1110
"publish-dist": "npm publish dist",
12-
"test": "npm run karma"
11+
"test": "yarn karma",
12+
"lint": "run-p lint:*",
13+
"lint:ts": "tslint --project tsconfig.json --config tslint.json --format stylish",
14+
"lint:pretty": "prettier --check '**/*.{ts,scss,js,json,yml,md,html}'"
1315
},
1416
"author": "Florian Knop",
1517
"repository": {
@@ -27,16 +29,18 @@
2729
"library"
2830
],
2931
"license": "MIT",
32+
"dependencies": {},
3033
"devDependencies": {
31-
"@angular/animations": "^8.1.3",
32-
"@angular/common": "^8.1.3",
33-
"@angular/compiler": "^8.1.3",
34-
"@angular/compiler-cli": "^8.1.3",
35-
"@angular/core": "^8.1.3",
36-
"@angular/platform-browser": "^8.1.3",
37-
"@angular/platform-browser-dynamic": "^8.1.3",
38-
"@angular/platform-server": "^8.1.3",
39-
"@types/jasmine": "^3.3.16",
34+
"@angular/animations": "^8.2.10",
35+
"@angular/common": "^8.2.10",
36+
"@angular/compiler": "^8.2.10",
37+
"@angular/compiler-cli": "^8.2.10",
38+
"@angular/core": "^8.2.10",
39+
"@angular/platform-browser": "^8.2.10",
40+
"@angular/platform-browser-dynamic": "^8.2.10",
41+
"@angular/platform-server": "^8.2.10",
42+
"@types/jasmine": "^3.4.0",
43+
"codelyzer": "^5.1.2",
4044
"core-js": "^3.1.4",
4145
"coveralls": "^3.0.5",
4246
"jasmine-core": "^3.4.0",
@@ -45,22 +49,24 @@
4549
"karma-jasmine": "^2.0.1",
4650
"karma-spec-reporter": "0.0.32",
4751
"karma-typescript": "^4.1.1",
48-
"ng-packagr": "^5.4.3",
52+
"ng-packagr": "^5.6.1",
53+
"npm-run-all": "^4.1.5",
4954
"prettier": "^1.18.2",
5055
"reflect-metadata": "^0.1.13",
5156
"rxjs": "^6.5.2",
52-
"tsickle": "^0.36.0",
57+
"tsickle": "^0.37.0",
5358
"tslib": "^1.10.0",
59+
"tslint": "^5.20.0",
60+
"tslint-microsoft-contrib": "^6.2.0",
61+
"tslint-sonarts": "^1.9.0",
5462
"typescript": "3.5.3",
5563
"zone.js": "~0.9.1"
5664
},
57-
"dependencies": {},
5865
"prettier": {
5966
"printWidth": 120,
6067
"singleQuote": true,
6168
"trailingComma": "es5"
6269
},
63-
"$schema": "./node_modules/ng-packagr/package.schema.json",
6470
"ngPackage": {
6571
"lib": {
6672
"entryFile": "src/public_api.ts"

src/aggregate/group-by.pipe.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import { getProperty, isArray, isUndefined } from '../utils/utils';
55
name: 'groupBy',
66
})
77
export class GroupByPipe implements PipeTransform {
8-
transform(input: any, prop: string): Array<any> {
8+
transform(input: any, prop: string): any[] {
99
if (!isArray(input)) {
1010
return input;
1111
}
1212

13-
const arr: { [key: string]: Array<any> } = {};
13+
const arr: { [key: string]: any[] } = {};
1414

1515
for (const value of input) {
1616
const field: any = getProperty(value, prop);

src/array/chunk.pipe.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { isArray } from '../utils/utils';
55
name: 'chunk',
66
})
77
export class ChunkPipe implements PipeTransform {
8-
transform(input: any, size: number = 1): any {
8+
transform(input: any, size = 1): any {
99
if (!isArray(input)) {
1010
return input;
1111
}

src/array/first-or-default.pipe.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class FirstOrDefaultPipe implements PipeTransform {
1818
result = input[i];
1919
}
2020

21-
if (typeof result === 'undefined' && typeof defaultValue !== 'undefined') {
21+
if (result == undefined && defaultValue != undefined) {
2222
result = defaultValue;
2323
}
2424

@@ -31,15 +31,17 @@ export class FirstOrDefaultPipe implements PipeTransform {
3131
}
3232

3333
if (isFunction(predicate)) {
34-
return FirstOrDefaultPipe.find(input, <CollectionPredicate>predicate, defaultValue);
35-
} else if (isArray(predicate)) {
36-
const [key, value] = <string[]>predicate;
34+
return FirstOrDefaultPipe.find(input, predicate as CollectionPredicate, defaultValue);
35+
}
36+
if (isArray(predicate)) {
37+
const [key, value] = predicate as string[];
3738
return FirstOrDefaultPipe.find(input, (item: any) => getProperty(item, key) === value, defaultValue);
38-
} else if (predicate) {
39-
return FirstOrDefaultPipe.find(input, item => item === <any>predicate, defaultValue);
40-
} else {
41-
return input;
4239
}
40+
if (predicate) {
41+
return FirstOrDefaultPipe.find(input, item => item === predicate, defaultValue);
42+
}
43+
44+
return input;
4345
}
4446
}
4547

src/array/join.pipe.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { isArray } from '../utils/utils';
55
name: 'join',
66
})
77
export class JoinPipe implements PipeTransform {
8-
transform(input: any, character: string = ''): any {
8+
transform(input: any, character = ''): any {
99
if (!isArray(input)) {
1010
return input;
1111
}

src/array/order-by.pipe.ts

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// tslint:disable:cognitive-complexity
12
import { Pipe, PipeTransform, NgModule } from '@angular/core';
23
import { isArray } from '../utils/utils';
34

@@ -41,35 +42,35 @@ export class OrderByPipe implements PipeTransform {
4142
const comparator = OrderByPipe._orderBy(a, b);
4243
return desc ? -comparator : comparator;
4344
});
44-
} else {
45-
// If contains + or -, substring the property
46-
const property = first === '+' || desc ? propertyToCheck.substr(1) : propertyToCheck;
47-
48-
return [...input].sort((a: any, b: any) => {
49-
const comparator = OrderByPipe._orderBy(a[property], b[property]);
50-
return desc ? -comparator : comparator;
51-
});
5245
}
53-
} else {
54-
// Config is an array of property
46+
47+
// If contains + or -, substring the property
48+
const property = first === '+' || desc ? propertyToCheck.substr(1) : propertyToCheck;
5549

5650
return [...input].sort((a: any, b: any) => {
57-
for (let i: number = 0; i < config.length; ++i) {
58-
const first = config[i].substr(0, 1);
59-
const desc = first === '-';
60-
const property = first === '+' || desc ? config[i].substr(1) : config[i];
51+
const comparator = OrderByPipe._orderBy(a[property], b[property]);
52+
return desc ? -comparator : comparator;
53+
});
54+
}
55+
56+
// Config is an array of property
57+
58+
return [...input].sort((a: any, b: any) => {
59+
for (const conf of config) {
60+
const first = conf.substr(0, 1);
61+
const desc = first === '-';
62+
const property = first === '+' || desc ? conf.substr(1) : conf;
6163

62-
const comparator = OrderByPipe._orderBy(a[property], b[property]);
63-
const comparison = desc ? -comparator : comparator;
64+
const comparator = OrderByPipe._orderBy(a[property], b[property]);
65+
const comparison = desc ? -comparator : comparator;
6466

65-
if (comparison !== 0) {
66-
return comparison;
67-
}
67+
if (comparison !== 0) {
68+
return comparison;
6869
}
70+
}
6971

70-
return 0;
71-
});
72-
}
72+
return 0;
73+
});
7374
}
7475
}
7576

src/array/range.pipe.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import { Pipe, PipeTransform, NgModule } from '@angular/core';
44
name: 'range',
55
})
66
export class RangePipe implements PipeTransform {
7-
transform(_input: any, size: number = 0, start: number = 1, step: number = 1): any {
7+
transform(_input: any, size = 0, start = 1, step = 1): any {
88
const range: number[] = [];
9+
let _start = start;
910
for (let length = 0; length < size; ++length) {
10-
range.push(start);
11-
start += step;
11+
range.push(_start);
12+
_start += step;
1213
}
1314

1415
return range;

0 commit comments

Comments
 (0)