<commit_before>var base = require('./base');
var A = base.A;
var Logger = require('./logger');
var File = require('./file');

// Expects a File object

var Formatter = function(file, logger) {
	if (A.Lang.isString(file)) {
		file = new File(file);
	}

	this.file = file;
	this.logger = logger || Logger;

	if (A.Lang.isFunction(this.init)) {
		this.init(file, logger);
	}
};

Formatter.prototype = {
	format: function(contents) {
		return contents;
	},

	log: function(line, msg, type, props) {
		this.logger.log(line, msg, this.file.path, type, props);
	}
};

Formatter._registered = {};

Formatter.create = function(obj) {
	if (!A.Lang.isObject(obj)) {
		throw Error('You must pass an object to Formatter.create');
	}

	var constructor;

	if (obj.hasOwnProperty('constructor')) {
		constructor = obj.constructor;

		delete obj.constructor;
	}
	else {
		constructor = function() {
			return Formatter.apply(this, arguments);
		};
	}

	var proto = Object.create(Formatter.prototype);

	var customProto = obj.prototype;

	delete obj.prototype;

	A.mix(proto, customProto, true);

	proto.constructor = constructor;

	constructor.prototype = proto;

	var id = obj.id;

	if (!id || Formatter._registered.hasOwnProperty(id)) {
		var errMsg = base.sub('The id: "{0}" is already taken', id);

		if (!id) {
			errMsg = 'You must give this formatter an id with the id property';
		}

		throw Error(errMsg);
	}

	var extensions = obj.extensions;

	if (!A.Lang.isString(extensions) || !extensions.length) {
		throw Error('The extensions property must be a string, and must be glob expression');
	}

	A.mix(constructor, obj, true);

	Formatter._registered[id] = constructor;

	return constructor;
};

// var minimatch = require('minimatch');
// var ext = '*.?(s)css';
// var ext = Formatter.HTML.extensions;

// 'js|css|scss|jsp|html|htm|vm|ftl|tpl|tmpl|jspf'.split('|').forEach(
// 	function(item, index) {
// 		var file = '/Users/ncavanaugh/Dev/Liferay/bar.' + item;

// 		console.log('"%s" %s %s', file, (minimatch(file, ext, {nocase: true, matchBase: true}) ? 'matches' : 'does not match'), ext);
// 	}
// );

module.exports = Formatter;<commit_msg>Source formatting<commit_after>var base = require('./base');
var A = base.A;
var Logger = require('./logger');
var File = require('./file');

// Expects a File object

var Formatter = function(file, logger) {
	if (A.Lang.isString(file)) {
		file = new File(file);
	}

	this.file = file;
	this.logger = logger || Logger;

	if (A.Lang.isFunction(this.init)) {
		this.init(file, logger);
	}
};

Formatter.prototype = {
	format: function(contents) {
		return contents;
	},

	log: function(line, msg, type, props) {
		this.logger.log(line, msg, this.file.path, type, props);
	}
};

Formatter._registered = {};

Formatter.create = function(obj) {
	if (!A.Lang.isObject(obj)) {
		throw Error('You must pass an object to Formatter.create');
	}

	var constructor;

	if (obj.hasOwnProperty('constructor')) {
		constructor = obj.constructor;

		delete obj.constructor;
	}
	else {
		constructor = function() {
			return Formatter.apply(this, arguments);
		};
	}

	var proto = Object.create(Formatter.prototype);

	var customProto = obj.prototype;

	delete obj.prototype;

	A.mix(proto, customProto, true);

	proto.constructor = constructor;

	constructor.prototype = proto;

	var id = obj.id;

	if (!id || Formatter._registered.hasOwnProperty(id)) {
		var errMsg = base.sub('The id: "{0}" is already taken', id);

		if (!id) {
			errMsg = 'You must give this formatter an id with the id property';
		}

		throw Error(errMsg);
	}

	var extensions = obj.extensions;

	if (!A.Lang.isString(extensions) || !extensions.length) {
		throw Error('The extensions property must be a string, and must be glob expression');
	}

	A.mix(constructor, obj, true);

	Formatter._registered[id] = constructor;

	return constructor;
};

module.exports = Formatter;
{'fraction_non_alphanumeric': 0.1605990188484379, 'fraction_numerical': 0.0005163955589981926, 'mean_word_length': 3.9350318471337578, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7110782', 'n_tokens_mistral': 1364, 'n_tokens_neox': 1281, 'n_words': 331}