Skip to content

Commit

Permalink
fix: Add summary to the end of lint
Browse files Browse the repository at this point in the history
Close #120
  • Loading branch information
romanrostislavovich committed Nov 13, 2022
1 parent ca8c1ca commit acf5caf
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class Cli {
const resultCliModel: ResultCliModel = validationModel.lint(maxWarning);
const resultModel: ResultModel = resultCliModel.getResultModel();
resultModel.printResult();
resultModel.printSummery();

process.exitCode = resultCliModel.exitCode();

Expand Down
2 changes: 1 addition & 1 deletion src/core/models/results/ResultCliModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class ResultCliModel {

public getResultModel(): ResultModel {
const resultFiles: ResultFileModel[] = this.getResultFiles();
const resultModel: ResultModel = new ResultModel(resultFiles, this.hasErrors(), this.hasWarnings(), logger);
const resultModel: ResultModel = new ResultModel(this, resultFiles, this.hasErrors(), this.hasWarnings(), logger);
return resultModel;
}
}
Expand Down
44 changes: 43 additions & 1 deletion src/core/models/results/ResultModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@ import { isArray } from 'lodash';

import { ResultFileModel } from './ResultFileModel';
import { ResultErrorModel } from './ResultErrorModel';
import { ErrorTypes } from '../../enums';
import { ErrorFlow, ErrorTypes } from '../../enums';
import { ILogger } from '../../interface';
import { StylishLogger } from '../StylishLogger';
import { ResultCliModel } from './ResultCliModel';

class ResultModel extends StylishLogger {
public cli: ResultCliModel;
public files: ResultFileModel[];
public hasError: boolean;
public hasWarning: boolean;
public readonly message: string = `Find missing translation keys in project`;

constructor(
cliModel: ResultCliModel,
files: ResultFileModel[] = [],
hasError: boolean = false,
hasWarning: boolean = false,
logger: ILogger = console,
) {
super(logger, hasError ? ErrorTypes.error : ErrorTypes.warning);
this.cli = cliModel;
this.files = files;
this.hasError = hasError;
this.hasWarning = hasWarning;
Expand All @@ -39,6 +43,44 @@ class ResultModel extends StylishLogger {
});
}
}

public printSummery(): void {
if (this.cli.hasWarnings() || this.cli.hasErrors()) {
const totalErrorType: ErrorTypes = this.cli.isFullOfWarning() || this.cli.hasErrors() ? ErrorTypes.error : ErrorTypes.warning;
const emptyKeys: ResultErrorModel[] = this.cli.errors.filter((x) => x.errorFlow === ErrorFlow.emptyKeys);
const zombieKeys: ResultErrorModel[] = this.cli.errors.filter((x) => x.errorFlow === ErrorFlow.zombieKeys);
const keysOnViews: ResultErrorModel[] = this.cli.errors.filter((x) => x.errorFlow === ErrorFlow.keysOnViews);
const misprintKeys: ResultErrorModel[] = this.cli.errors.filter((x) => x.errorFlow === ErrorFlow.misprintKeys);

this.printMessage(`\nFind following errors:`, totalErrorType);

if (emptyKeys.length !== 0) {
const errorType:ErrorTypes = this.cli.isFullOfWarning() ? ErrorTypes.error : emptyKeys[0].errorType;
this.printMessage(`Empty Keys: \t ${emptyKeys.length}`,errorType);
}

if (zombieKeys.length !== 0) {
const errorType:ErrorTypes = this.cli.isFullOfWarning() ? ErrorTypes.error : zombieKeys[0].errorType;
this.printMessage(`Zombie Keys: \t ${zombieKeys.length}`, errorType);
}

if (keysOnViews.length !== 0) {
const errorType:ErrorTypes = this.cli.isFullOfWarning() ? ErrorTypes.error : keysOnViews[0].errorType;
this.printMessage(`Key On Views: \t ${keysOnViews.length}`, errorType);
}


if (misprintKeys.length !== 0) {
const errorType:ErrorTypes = this.cli.isFullOfWarning() ? ErrorTypes.error : misprintKeys[0].errorType;
this.printMessage(`Misprint Keys: \t ${misprintKeys.length}`, errorType);
}


this.printMessage(`--------------------`, totalErrorType);
this.printMessage(`TOTAL: \t\t ${this.cli.countWarnings() + this.cli.countErrors()}`, totalErrorType);
this.printMessage(`\n`);
}
}
}

export { ResultModel };

0 comments on commit acf5caf

Please sign in to comment.