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

Commit 5b77d4c

Browse files
committed
feat: add eslint
1 parent 912e52d commit 5b77d4c

42 files changed

Lines changed: 933 additions & 324 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.editorconfig

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
# Editor configuration, see https://editorconfig.org
1+
# Editor configuration, see http://editorconfig.org
22
root = true
33

44
[*]
55
charset = utf-8
6+
indent_size = 4
7+
end_of_line = lf
68
indent_style = space
7-
indent_size = 2
9+
max_line_length = 120
810
insert_final_newline = true
911
trim_trailing_whitespace = true
10-
11-
[*.md]
12-
max_line_length = off
13-
trim_trailing_whitespace = false

.eslintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "@angular-ru/eslint-config"
3+
}

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ node_js:
66
install:
77
- npm install
88
script:
9+
- npm run lint
910
- npm test
1011
- npm run build
1112
after_success:

helpers/console-fake.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable */
12
import { ObjectKeyMap } from '../projects/logger/src/lib/interfaces/logger.internal';
23

34
export enum TestLoggerLineType {

helpers/custom-colors.enum.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// eslint-disable-next-line @typescript-eslint/naming-convention,no-restricted-syntax
12
export enum CUSTOM_COLORS {
23
TRACE = 'BlueViolet',
34
DEBUG = 'CornflowerBlue',
@@ -6,6 +7,7 @@ export enum CUSTOM_COLORS {
67
ERROR = 'Crimson'
78
}
89

10+
// eslint-disable-next-line no-restricted-syntax,@typescript-eslint/naming-convention
911
export enum CUSTOM_LABELS {
1012
TRACE = 'trace:',
1113
DEBUG = 'debug:',

helpers/test.component.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import { Component, OnInit } from '@angular/core';
2-
import { LoggerService } from '../projects/logger/src/lib/logger.service';
3-
import { Logger } from '../projects/logger/src/lib/decorators/logger.decorator';
2+
43
import { DebugLog } from '../projects/logger/src/lib/decorators/debug.decorator';
5-
import { TraceLog } from '../projects/logger/src/lib/decorators/trace.decorator';
6-
import { InfoLog } from '../projects/logger/src/lib/decorators/info.decorator';
74
import { ErrorLog } from '../projects/logger/src/lib/decorators/error.decorator';
8-
import { WarnLog } from '../projects/logger/src/lib/decorators/warn.decorator';
9-
import { Log } from '../projects/logger/src/lib/decorators/log.decorator';
10-
import { Group } from '../projects/logger/src/lib/decorators/groups/group.decorator';
115
import { GroupCollapsed } from '../projects/logger/src/lib/decorators/groups/group-collapsed.decorator';
6+
import { Group } from '../projects/logger/src/lib/decorators/groups/group.decorator';
7+
import { InfoLog } from '../projects/logger/src/lib/decorators/info.decorator';
8+
import { Log } from '../projects/logger/src/lib/decorators/log.decorator';
9+
import { Logger } from '../projects/logger/src/lib/decorators/logger.decorator';
1210
import { TimerLog } from '../projects/logger/src/lib/decorators/timer.decorator';
11+
import { TraceLog } from '../projects/logger/src/lib/decorators/trace.decorator';
12+
import { WarnLog } from '../projects/logger/src/lib/decorators/warn.decorator';
1313
import { LogFn, LoggerLevel, TimerInfo } from '../projects/logger/src/lib/interfaces/logger.external';
1414
import { Fn } from '../projects/logger/src/lib/interfaces/logger.internal';
15+
import { LoggerService } from '../projects/logger/src/lib/logger.service';
1516

1617
interface HttpDebugInterface {
1718
method: string;
@@ -38,6 +39,11 @@ export class MyTestComponent implements OnInit {
3839
public doneHeavy: boolean = false;
3940
public name: string = 'MockLoggerComponent';
4041

42+
public static getUrlInfo({ method, url, queryParams }: Partial<HttpDebugInterface>): string {
43+
const params: string = queryParams ? `?${queryParams}` : '';
44+
return `[${method}] - ${url}${params}`;
45+
}
46+
4147
@Group('Test group')
4248
public print(val: string): string {
4349
this.logger.log(val);
@@ -73,23 +79,18 @@ export class MyTestComponent implements OnInit {
7379
this.count++;
7480
}
7581

76-
@Group((name: string) => `Test group with ${name}`)
82+
@Group((name: string): string => `Test group with ${name}`)
7783
public method(name: string): string {
7884
this.logger.log('group is worked');
7985
return name;
8086
}
8187

82-
@Group((options: Partial<HttpDebugInterface>) => MyTestComponent.getUrlInfo(options))
88+
@Group((options: Partial<HttpDebugInterface>): string => MyTestComponent.getUrlInfo(options))
8389
public hello(name: string): string {
8490
this.logger.log('group is worked');
8591
return name;
8692
}
8793

88-
public static getUrlInfo({ method, url, queryParams }: Partial<HttpDebugInterface>): string {
89-
const params: string = queryParams ? `?${queryParams}` : '';
90-
return `[${method}] - ${url}${params}`;
91-
}
92-
9394
@TimerLog('mock:ngOnInit')
9495
public ngOnInit(): void {
9596
this.hook = 'ngOnInit';
@@ -112,6 +113,7 @@ export class MyTestComponent implements OnInit {
112113
}
113114

114115
private extracted(seconds: number, done: Fn): void {
116+
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
115117
const e: number = new Date().getTime() + seconds * 1000;
116118
while (new Date().getTime() <= e) {
117119
this.doneHeavy = true;

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"build:app": "ng build",
1111
"build.meta": "echo 'prebuild'",
1212
"test": "jest --config ./jest.app.config.js --coverage",
13-
"lint": "ng lint",
13+
"lint": "eslint --fix \"**/*.ts\"",
1414
"format": "prettier --write \"**/*.{ts,html,css,scss,md,js,json}\"",
1515
"coverage": "jest --config ./jest.app.config.js --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
1616
},
@@ -38,6 +38,7 @@
3838
"zone.js": "~0.10.3"
3939
},
4040
"devDependencies": {
41+
"@angular-ru/eslint-config": "12.20.1",
4142
"@angular-ru/prettier-config": "^12.19.1",
4243
"@angular-ru/tsconfig": "^12.19.1",
4344
"@angular-devkit/build-angular": "^0.803.27",

projects/logger/src/lib/decorators/autobind.decorator.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@ function autoBindClass(target: ObjectKeyMap): Any {
2929
function getOwnPropertyDescriptors(target: ObjectKeyMap): ObjectKeyMap {
3030
const descriptors: ObjectKeyMap = {};
3131

32-
getOwnKeys(target).forEach((key: string) => (descriptors[key] = getOwnPropertyDescriptor(target, key)));
32+
getOwnKeys(target).forEach((key: string): void => {
33+
descriptors[key] = getOwnPropertyDescriptor(target, key);
34+
});
3335

3436
return descriptors;
3537
}
3638

39+
// eslint-disable-next-line max-lines-per-function
3740
function autoBindMethod(
3841
target: ObjectKeyMap,
3942
key: string,
@@ -68,6 +71,7 @@ function handle(args: Any[]): Any {
6871
if (args.length === 1) {
6972
return autoBindClass(args[0]);
7073
} else {
74+
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
7175
// @ts-ignore
7276
return autoBindMethod(...args);
7377
}
@@ -84,7 +88,7 @@ export function autoBind(...args: Any[]): Any {
8488
}
8589

8690
function createDefaultSetter(key: Any): Fn {
87-
return function set(this: any, newValue: unknown): unknown {
91+
return function set(this: Any, newValue: unknown): unknown {
8892
Object.defineProperty(this, key, {
8993
configurable: true,
9094
writable: true,

projects/logger/src/lib/decorators/debug.decorator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { LogFn } from '../interfaces/logger.external';
12
import { LoggerInjector } from '../logger.injector';
23
import { LoggerService } from '../logger.service';
3-
import { LogFn } from '../interfaces/logger.external';
44

55
export function DebugLog(): PropertyDecorator {
66
return (target: unknown, propertyName: string | symbol): void => {

projects/logger/src/lib/decorators/error.decorator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { LogFn } from '../interfaces/logger.external';
12
import { LoggerInjector } from '../logger.injector';
23
import { LoggerService } from '../logger.service';
3-
import { LogFn } from '../interfaces/logger.external';
44

55
export function ErrorLog(): PropertyDecorator {
66
return (target: unknown, propertyName: string | symbol): void => {

0 commit comments

Comments
 (0)