jsinspect-plus
Version:
Detect copy-pasted and structurally similar code. Supports ES2020 standard (and most proposed features), TS and TSX files. Using Babel 8's parser.
46 lines (40 loc) • 1.28 kB
JavaScript
var chalk = require('chalk');
var BaseReporter = require('./base');
class DefaultReporter extends BaseReporter {
/**
* The default reporter, which displays both file and line information for
* each given match.
*
* @constructor
*
* @param {Inspector} inspector Instance on which to register its listeners
* @param {object} opts Options to set for the reporter
*/
constructor(inspector, opts) {
opts = opts || {};
super(inspector, opts);
this._registerSummary();
}
/**
* Returns the string output to print for the given reporter. The string
* contains the number of instances associated with the match and the files
* and lines involved.
*
* @private
*
* @param {Match} match The inspector match to output
* @returns {string} The formatted output
*/
_getOutput(match) {
const instances = match.instances;
let output = '\n' + '-'.repeat(60) + '\n\n' +
chalk.bold(`Match - ${instances.length} instances\n`);
instances.forEach((instance) => {
const location = this._getFormattedLocation(instance);
const lines = this._getLines(instance);
output += `\n${location}\n${chalk.grey(lines)}\n`;
});
return output;
}
}
module.exports = DefaultReporter;