Skip to content

Commit

Permalink
feat(reporter): add statistic reporter
Browse files Browse the repository at this point in the history
add statistic about clones and analyzed sources
  • Loading branch information
Andrii Kucherenko committed Aug 15, 2018
1 parent 68ca373 commit 01fc2b3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 23 deletions.
Empty file.
23 changes: 0 additions & 23 deletions src/reporters/spinner.ts

This file was deleted.

46 changes: 46 additions & 0 deletions src/reporters/statistic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { bold, green, red } from 'colors/safe';
import { relative } from 'path';
import { Events } from '../events';
import { IClone } from '../interfaces/clone.interface';
import { IOptions } from '../interfaces/options.interface';
import { IReporter } from '../interfaces/reporter.interface';
import { IToken } from '../interfaces/token/token.interface';
import { StoresManager } from '../stores/stores-manager';

export class ConsoleReporter implements IReporter {
constructor(private options: IOptions) {}

public attach(): void {
Events.on('clone', this.cloneFound.bind(this));
}

private cloneFound(clone: IClone) {
const { duplicationA, duplicationB, format } = clone;
console.log(
'Clone found (' + format + '):' + (clone.is_new ? red('*') : '')
);
console.log(
` - ${getPath(
this.options,
StoresManager.get('source').get(duplicationA.sourceId).id
)} [${getSourceLocation(duplicationA.start, duplicationA.end)}]`
);
console.log(
` ${getPath(
this.options,
StoresManager.get('source').get(duplicationB.sourceId).id
)} [${getSourceLocation(duplicationB.start, duplicationB.end)}]`
);
console.log('');
}
}

function getPath(options: IOptions, path: string): string {
return bold(green(relative(options.path, path)));
}

function getSourceLocation(start: IToken, end: IToken): string {
return `${start.loc.start.line}:${start.loc.start.column} - ${
end.loc.start.line
}:${end.loc.start.column}`;
}

0 comments on commit 01fc2b3

Please sign in to comment.