<commit_before>'use strict';

var _ = require('lodash');
var utils = require('./utils');
var GruntOModuleContext = require('./GruntOModuleContext');
var gruntOverride = require('./override');

/**
 * @class GruntO
 * @property {Date} _time
 * @property {grunt} grunt
 * @property {Object} _gruntOverrider
 * @property {Object} config
 * @property {Object} _options
 * @property {Array} _scans
 * @param {Object} grunt - task runner
 * @param {Object} params - init params
*/
var GruntO = function (grunt, params) {
	this._time = Date.now();
	this.grunt = grunt || require('grunt');
	this._gruntOverrider = gruntOverride(grunt);
	this.params = _.extend({
		autoload: true,
		statistic: true,
		timeMetric: true
	}, params);

	this._config = {};
	this._options = {};
	this._scans = [];

	this._gruntOverrider.override();
};

GruntO.prototype = {

	/**
	 * @this GruntO
	 * @public
	 * @param {!Object|Array|String} files - array of file glob-patterns for scanning
	 * @returns {GruntO} this
	 */
	scan: function (files) {
		if (_.isArray(files)) {
			this._scans = this._scans.concat(files);
			return this;
		}

		if (_.isPlainObject(files)) {
			this._scans.push(files);
			return this;
		}

		if (_.isString(files)) {
			this._scans.push(files);
			return this;
		}

		this.grunt.fail.fatal('Invalid scan type, must be object/array');
	},

	/**
	 * @this GruntO
	 * @public
	 * @param {!Object} params - params for extend the standard GruntO context
	 * @returns {GruntO} this
	 */
	context: function (params) {
		if (!_.isPlainObject(params)) {
			this.grunt.fail.fatal('Invalid options type, must be object');
		}

		_.extend(this._options, params);

		return this;
	},

	/**
	 * @this GruntO
	 * @public
	 * @param {!Object} config - config object for adding to main config
	 * @returns {GruntO} this
	 */
	config: function (config) {
		if (_.isPlainObject(config)) {
			_.extend(this._config, config);
		} else if (config != null) {
			this.grunt.fail.fatal('invalid config value, must be object');
		}

		return this;
	},

	/**
	 * @this GruntO
	 * @public
	 * @param {!String} fPath - file path
	 * @param {!String} cwd - main dir path
	 * @returns {String} - prefix of task context
	 */
	getPrefix: function (fPath, cwd) {
		return fPath.replace(/^[\/]?(.+?)(?:\/default)?(?:\.js)?$/, '$1').replace(/\\+/g, '/');
	},

	/**
	 * @this GruntO
	 * @private
	 * @returns {Array} - modules
	 */<commit_msg>fix config extension<commit_after>'use strict';

var _ = require('lodash');
var utils = require('./utils');
var GruntOModuleContext = require('./GruntOModuleContext');
var gruntOverride = require('./override');

/**
 * @class GruntO
 * @property {Date} _time
 * @property {grunt} grunt
 * @property {Object} _gruntOverrider
 * @property {Object} config
 * @property {Object} _options
 * @property {Array} _scans
 * @param {Object} grunt - task runner
 * @param {Object} params - init params
*/
var GruntO = function (grunt, params) {
	this._time = Date.now();
	this.grunt = grunt || require('grunt');
	this._gruntOverrider = gruntOverride(grunt);
	this.params = _.extend({
		autoload: true,
		statistic: true,
		timeMetric: true
	}, params);

	this._config = {};
	this._options = {};
	this._scans = [];

	this._gruntOverrider.override();
};

GruntO.prototype = {

	/**
	 * @this GruntO
	 * @public
	 * @param {!Object|Array|String} files - array of file glob-patterns for scanning
	 * @returns {GruntO} this
	 */
	scan: function (files) {
		if (_.isArray(files)) {
			this._scans = this._scans.concat(files);
			return this;
		}

		if (_.isPlainObject(files)) {
			this._scans.push(files);
			return this;
		}

		if (_.isString(files)) {
			this._scans.push(files);
			return this;
		}

		this.grunt.fail.fatal('Invalid scan type, must be object/array');
	},

	/**
	 * @this GruntO
	 * @public
	 * @param {!Object} params - params for extend the standard GruntO context
	 * @returns {GruntO} this
	 */
	context: function (params) {
		if (!_.isPlainObject(params)) {
			this.grunt.fail.fatal('Invalid options type, must be object');
		}

		_.extend(this._options, params);

		return this;
	},

	/**
	 * @this GruntO
	 * @public
	 * @param {!Object} config - config object for adding to main config
	 * @returns {GruntO} this
	 */
	config: function (config) {
		if (_.isPlainObject(config)) {
			var conf = this._config;

			_.each(config, function (v, k) {
				conf[k] = conf.hasOwnProperty(k) ? _.extend(conf[k], v) : v;
			});
		} else if (config != null) {
			this.grunt.fail.fatal('invalid config value, must be object');
		}

		return this;
	},

	/**
	 * @this GruntO
	 * @public
	 * @param {!String} fPath - file path
	 * @param {!String} cwd - main dir path
	 * @returns {String} - prefix of task context
	 */
	getPrefix: function (fPath, cwd) {
		return fPath.replace(/^[\/]?(.+?)(?:\/default)?(?:\.js)?$/, '$1').replace(/\\+/g, '/');
	},

	/**
	 * @this GruntO
	 * @private
	 * @returns {Array} - modules
	 */
{'fraction_non_alphanumeric': 0.17421319796954315, 'fraction_numerical': 0.0004060913705583756, 'mean_word_length': 3.382562277580071, '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': '169902', 'n_tokens_mistral': 1863, 'n_tokens_neox': 1703, 'n_words': 428}