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

Commit 78e0a41

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

34 files changed

+5617
-199
lines changed

.gitignore

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

.travis.yml

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

11+
before_install: # if "install" is overridden
12+
# Repo for Yarn
13+
- sudo apt-key adv --fetch-keys http://dl.yarnpkg.com/debian/pubkey.gpg
14+
- echo "deb http://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
15+
- sudo apt-get update -qq
16+
- sudo apt-get install -y -qq yarn=1.19.1-1
17+
1118
cache:
1219
yarn: true
1320
directories:
1421
- node_modules
1522

16-
after_success: npm run cover
23+
script:
24+
- yarn lint
25+
- yarn build
26+
- yarn test
27+
28+
after_success: yarn 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;

src/array/where.pipe.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ export class WherePipe implements PipeTransform {
1515

1616
if (isFunction(fn)) {
1717
return input.filter(fn);
18-
} else if (isArray(fn)) {
18+
}
19+
if (isArray(fn)) {
1920
const [key, value] = fn;
2021
return input.filter((item: any) => getProperty(item, key) === value);
21-
} else if (fn) {
22+
}
23+
if (fn) {
2224
return input.filter((item: any) => item === fn);
23-
} else {
24-
return input;
2525
}
26+
27+
return input;
2628
}
2729
}
2830

src/math/bytes.pipe.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,16 @@ export class BytesPipe implements PipeTransform {
1616
TB: { max: Number.MAX_SAFE_INTEGER, prev: 'GB' },
1717
};
1818

19-
transform(input: any, decimal: number = 0, from: ByteUnit = 'B', to?: ByteUnit): any {
19+
static formatResult(result: number, unit: string): string {
20+
return `${result} ${unit}`;
21+
}
22+
23+
static calculateResult(format: { max: number; prev?: ByteUnit }, bytes: number) {
24+
const prev = format.prev ? BytesPipe.formats[format.prev] : undefined;
25+
return prev ? bytes / prev.max : bytes;
26+
}
27+
28+
transform(input: any, decimal = 0, from: ByteUnit = 'B', to?: ByteUnit): any {
2029
if (!(isNumberFinite(input) && isNumberFinite(decimal) && isInteger(decimal) && isPositive(decimal))) {
2130
return input;
2231
}
@@ -25,7 +34,7 @@ export class BytesPipe implements PipeTransform {
2534
let unit = from;
2635
while (unit !== 'B') {
2736
bytes *= 1024;
28-
unit = BytesPipe.formats[unit].prev!;
37+
unit = BytesPipe.formats[unit].prev;
2938
}
3039

3140
if (to) {
@@ -47,15 +56,6 @@ export class BytesPipe implements PipeTransform {
4756
}
4857
}
4958
}
50-
51-
static formatResult(result: number, unit: string): string {
52-
return `${result} ${unit}`;
53-
}
54-
55-
static calculateResult(format: { max: number; prev?: ByteUnit }, bytes: number) {
56-
const prev = format.prev ? BytesPipe.formats[format.prev] : undefined;
57-
return prev ? bytes / prev.max : bytes;
58-
}
5959
}
6060

6161
@NgModule({

src/math/ceil.pipe.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import { createRound, isString } from '../utils/utils';
55
name: 'ceil',
66
})
77
export class CeilPipe implements PipeTransform {
8-
transform(value: any, precision: any = 0): any {
9-
if (isString(precision)) {
10-
precision = parseInt(precision);
8+
transform(value: any, precision: any = 0, radix = 10): any {
9+
let _precision = precision;
10+
if (isString(_precision)) {
11+
_precision = parseInt(_precision, radix);
1112
}
1213

13-
return createRound('ceil')(value, precision);
14+
return createRound('ceil')(value, _precision);
1415
}
1516
}
1617

src/math/floor.pipe.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import { createRound, isString } from '../utils/utils';
55
name: 'floor',
66
})
77
export class FloorPipe implements PipeTransform {
8-
transform(value: any, precision: any = 0): any {
9-
if (isString(precision)) {
10-
precision = parseInt(precision);
8+
transform(value: any, precision: any = 0, radix = 10): any {
9+
let _precision = precision;
10+
if (isString(_precision)) {
11+
_precision = parseInt(_precision, radix);
1112
}
1213

13-
return createRound('floor')(value, precision);
14+
return createRound('floor')(value, _precision);
1415
}
1516
}
1617

src/math/ordinal.pipe.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ export class OrdinalPipe implements PipeTransform {
1111
}
1212

1313
if (this.endsWithTenth(input)) {
14-
return input + 'th';
15-
} else {
16-
const cardinal = input.toString().charAt(input.toString().length - 1);
14+
return `${input}th`;
15+
}
16+
17+
const cardinal = input.toString().charAt(input.toString().length - 1);
1718

18-
switch (cardinal) {
19-
case '1':
20-
return input + 'st';
21-
case '2':
22-
return input + 'nd';
23-
case '3':
24-
return input + 'rd';
25-
default:
26-
return input + 'th';
27-
}
19+
switch (cardinal) {
20+
case '1':
21+
return `${input}st`;
22+
case '2':
23+
return `${input}nd`;
24+
case '3':
25+
return `${input}rd`;
26+
default:
27+
return `${input}th`;
2828
}
2929
}
3030

0 commit comments

Comments
 (0)