<commit_before>var async = require('async');
var cli = require('cli');
var fs = require('fs');
var path = require('path');
var util = require('util');
var updateNotifier = require('update-notifier');
var _ = require('lodash');

var argv = require('./argv');
var base = require('./base');
var junit = require('./junit');
var re = require('./re');

var File = require('./file');
var Formatter = require('./formatter');

var A = base.A;

var fileErrors = base.fileErrors;

var notifier = updateNotifier(
	{
		pkg: require('../package.json')
	}
);

if (notifier.update) {
	notifier.notify(true);
}

var args = argv._;

var INDENT = base.INDENT;

var QUIET = argv.q;
var VERBOSE = argv.v;
var RELATIVE = argv.r;
var INLINE_REPLACE = argv.i;
var FILE_NAMES = argv.filenames;
var LINT_IDS = argv['lint-ids'];

var CWD = base.CWD;
var TOP_LEVEL;

var sub = base.sub;

var Logger = require('./logger');

var MAP_OMIT = {
	'$0': true,
	'_': true
};

var flags = _.reduce(
	argv,
	function(res, item, index) {
		if (index.length > 1 && !MAP_OMIT[index]) {
			index = _.camelCase(index);

			res[index] = item;
		}

		return res;
	},
	{}
);

var series = args.map(
	function(file) {
		return function(done) {
			var fileObj = new File(file);

			var formatter = Formatter.get(fileObj, Logger, flags);

			if (formatter) {
				fileObj.format(formatter).then(function(data) {
					var config = {};

					var out;

					if (FILE_NAMES) {
						if (RELATIVE) {
							config.relative = CWD;
						}

						out = Logger.renderFileNames(fileObj, config);
					}
					else {
						config.showBanner = QUIET;
						config.showLintIds = LINT_IDS;

						out = Logger.render(fileObj, config);
					}

					if (out) {
						console.log(out);
					}

					if (this.isDirty() && INLINE_REPLACE) {
						this.write().then(
							function(data) {
								return util.format('Wrote file: %s', file);
							}
						)
						.catch(this.handleFileWriteError)
						.then(console.log)
					}
				})
				.error(
					function(err) {
						console.log(fileObj.handleFileReadError(err));
					}
				)
				.catch(
					function(err) {
						console.error(('Something went wrong.\nDetails below:'.error) + '\n%s', err.stack);
					}
				)
				.then(done);
			}
		};
	}
);

series.push(
	function(done) {
		if (Formatter.JS.needsModuleVerification) {
			require('./meta').check(
				{
					done: done,
					liferayModuleDir: Formatter.JS.liferayModuleDir,
					series: series
				}
			);
		}
		else {
			done();
		}
	}
);

if (argv.junit) {
	series.push(junit.generate);
}

var callback = function() {};

if (argv.o) {
	callback = function(err, result) {
		var errorFiles = Object.keys(fileErrors);

		if (errorFiles.length) {
			cli.exec(
				'git config --get user.editor',
				function(res) {
					cli.exec(
						'open -a "' + res[0] + '" "' + errorFiles.join('" "') + '"'
					);
				}
			);
		}
	};
}

if (RELATIVE) {
	series.unshift(
		function(done) {
			cli.exec(
				'git rev-parse --show-toplevel',
				function(res) {
					TOP_LEVEL = res;

					done();
				}
			);
		}
	);
}

async.series(series, callback);<commit_msg>Allow formatter to provide verbose details (Should eventually format this into using events)<commit_after>var async = require('async');
var cli = require('cli');
var fs = require('fs');
var path = require('path');
var util = require('util');
var updateNotifier = require('update-notifier');
var _ = require('lodash');

var argv = require('./argv');
var base = require('./base');
var junit = require('./junit');
var re = require('./re');

var File = require('./file');
var Formatter = require('./formatter');

var A = base.A;

var fileErrors = base.fileErrors;

var notifier = updateNotifier(
	{
		pkg: require('../package.json')
	}
);

if (notifier.update) {
	notifier.notify(true);
}

var args = argv._;

var INDENT = base.INDENT;

var QUIET = argv.q;
var VERBOSE = argv.v;
var RELATIVE = argv.r;
var INLINE_REPLACE = argv.i;
var FILE_NAMES = argv.filenames;
var LINT_IDS = argv['lint-ids'];

var CWD = base.CWD;
var TOP_LEVEL;

var sub = base.sub;

var Logger = require('./logger');

var MAP_OMIT = {
	'$0': true,
	'_': true
};

var flags = _.reduce(
	argv,
	function(res, item, index) {
		if (index.length > 1 && !MAP_OMIT[index]) {
			index = _.camelCase(index);

			res[index] = item;
		}

		return res;
	},
	{}
);

var series = args.map(
	function(file) {
		return function(done) {
			var fileObj = new File(file);

			var formatter = Formatter.get(fileObj, Logger, flags);

			if (formatter) {
				fileObj.format(formatter).then(function(data) {
					var config = {};

					var out;

					if (FILE_NAMES) {
						if (RELATIVE) {
							config.relative = CWD;
						}

						out = Logger.renderFileNames(fileObj, config);
					}
					else {
						config.showBanner = QUIET;
						config.showLintIds = LINT_IDS;

						out = Logger.render(fileObj, config);
					}

					if (out) {
						console.log(out);
					}

					if (Logger.verboseDetails) {
						console.log(Logger.verboseDetails);
					}

					if (this.isDirty() && INLINE_REPLACE) {
						this.write().then(
							function(data) {
								return util.format('Wrote file: %s', file);
							}
						)
						.catch(this.handleFileWriteError)
						.then(console.log)
					}
				})
				.error(
					function(err) {
						console.log(fileObj.handleFileReadError(err));
					}
				)
				.catch(
					function(err) {
						console.error(('Something went wrong.\nDetails below:'.error) + '\n%s', err.stack);
					}
				)
				.then(done);
			}
		};
	}
);

series.push(
	function(done) {
		if (Formatter.JS.needsModuleVerification) {
			require('./meta').check(
				{
					done: done,
					liferayModuleDir: Formatter.JS.liferayModuleDir,
					series: series
				}
			);
		}
		else {
			done();
		}
	}
);

if (argv.junit) {
	series.push(junit.generate);
}

var callback = function() {};

if (argv.o) {
	callback = function(err, result) {
		var errorFiles = Object.keys(fileErrors);

		if (errorFiles.length) {
			cli.exec(
				'git config --get user.editor',
				function(res) {
					cli.exec(
						'open -a "' + res[0] + '" "' + errorFiles.join('" "') + '"'
					);
				}
			);
		}
	};
}

if (RELATIVE) {
	series.unshift(
		function(done) {
			cli.exec(
				'git rev-parse --show-toplevel',
				function(res) {
					TOP_LEVEL = res;

					done();
				}
			);
		}
	);
}

async.series(series, callback);
{'fraction_non_alphanumeric': 0.16963021243115656, 'fraction_numerical': 0.0009441384736428009, 'mean_word_length': 2.6528735632183906, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5844693', 'n_tokens_mistral': 2867, 'n_tokens_neox': 2288, 'n_words': 472}