<commit_before>'use strict';

var isCallable     = require('es5-ext/object/is-callable')
  , callable       = require('es5-ext/object/valid-callable')
  , reEscape       = require('es5-ext/reg-exp/escape')
  , endsWith       = require('es5-ext/string/#/ends-with')
  , d              = require('d')
  , deferred       = require('deferred')
  , memoize        = require('memoizee/plain')
  , resolve        = require('path').resolve
  , readdir        = require('fs2/readdir')
  , getOptsReader  = require('./lib/options/read').getReader
  , normalizeOpts  = require('./lib/options/normalize')
  , lintignoreMode = require('./lib/lintignore-mode')
  , LintFiles      = require('./lint-files').LintFiles

  , isArray = Array.isArray, push = Array.prototype.push
  , getReExtension, lintDirectory, LintDirectory;

getReExtension = memoize(function (ext) {
	return new RegExp('(?:^|[\\/\\\\])(?:[\0-\\-0-\\[\\]-\uffff]+|' +
		'[\0-\\.0-\\[\\]-\uffff]*\\.' + reEscape(ext) + ')$')
});

LintDirectory = function () { LintFiles.call(this); };
LintDirectory.prototype = Object.create(LintFiles.prototype, {
	init: d(function () {
		var waiting;
		this.reader = readdir(this.root, { watch: this.watch, depth: this.depth,
			stream: this.stream, ignoreRules: this.ignoreRules, type: { file: true },
			pattern: getReExtension(this.fileExt) });
		if (this.watch || this.stream) {
			if (this.stream) {
				waiting = [];
			}
			this.reader.on('change', function (data) {
				if (this.promise.resolved) {
					deferred.map(data.added, this.prelint, this).done();
				} else {
					push.apply(waiting, data.added.map(this.prelint, this));
				}
				data.removed.forEach(function (name) {
					if (this.linters[name]) {
						this.linters[name].close();
						this.clear(name);
					}
				}, this);
			}.bind(this));
			this.reader.on('end', function () {
				delete this.linters;
				this.promise.emit('end');
			}.bind(this));
		}
		this.reader.done(function (names) {
			(this.stream ? deferred.map(waiting) :
					deferred.map(names, this.prelint, this))
				.done(this.resolve.bind(this, this.result), this.reject);
		}.bind(this), this.reject);
		this.promise.root = this.root;
		this.promise.xlintId = this.linter.xlintId;
		return this.promise;
	}),
	prelint: d(function (name) {
		if (endsWith.call(name, this.fileExt)) return this.lint(name);<commit_msg>Fix shebang route<commit_after>'use strict';

var isCallable     = require('es5-ext/object/is-callable')
  , callable       = require('es5-ext/object/valid-callable')
  , reEscape       = require('es5-ext/reg-exp/escape')
  , endsWith       = require('es5-ext/string/#/ends-with')
  , d              = require('d')
  , deferred       = require('deferred')
  , memoize        = require('memoizee/plain')
  , resolve        = require('path').resolve
  , readdir        = require('fs2/readdir')
  , getOptsReader  = require('./lib/options/read').getReader
  , normalizeOpts  = require('./lib/options/normalize')
  , lintignoreMode = require('./lib/lintignore-mode')
  , LintFiles      = require('./lint-files').LintFiles

  , isArray = Array.isArray, push = Array.prototype.push
  , getReExtension, lintDirectory, LintDirectory;

getReExtension = memoize(function (ext) {
	return new RegExp('(?:^|[\\/\\\\])(?:[\0-\\-0-\\[\\]-\uffff]+|' +
		'[\0-\\.0-\\[\\]-\uffff]*\\.' + reEscape(ext) + ')$')
});

LintDirectory = function () { LintFiles.call(this); };
LintDirectory.prototype = Object.create(LintFiles.prototype, {
	init: d(function () {
		var waiting;
		this.reader = readdir(this.root, { watch: this.watch, depth: this.depth,
			stream: this.stream, ignoreRules: this.ignoreRules, type: { file: true },
			pattern: getReExtension(this.fileExt) });
		if (this.watch || this.stream) {
			if (this.stream) {
				waiting = [];
			}
			this.reader.on('change', function (data) {
				if (this.promise.resolved) {
					deferred.map(data.added, this.prelint, this).done();
				} else {
					push.apply(waiting, data.added.map(this.prelint, this));
				}
				data.removed.forEach(function (name) {
					if (this.linters[name]) {
						this.linters[name].close();
						this.clear(name);
					}
				}, this);
			}.bind(this));
			this.reader.on('end', function () {
				delete this.linters;
				this.promise.emit('end');
			}.bind(this));
		}
		this.reader.done(function (names) {
			(this.stream ? deferred.map(waiting) :
					deferred.map(names, this.prelint, this))
				.done(this.resolve.bind(this, this.result), this.reject);
		}.bind(this), this.reject);
		this.promise.root = this.root;
		this.promise.xlintId = this.linter.xlintId;
		return this.promise;
	}),
	prelint: d(function (name) {
		if (endsWith.call(name, this.fileExt)) return this.lint(name);
		if (this.fileExt !== 'js') return null;
{'fraction_non_alphanumeric': 0.19152970922882429, 'fraction_numerical': 0.0037926675094816687, 'mean_word_length': 3.1713532513181018, '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': '719265', 'n_tokens_mistral': 1841, 'n_tokens_neox': 1663, 'n_words': 258}