Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
Configuration: design review
Browse files Browse the repository at this point in the history
  • Loading branch information
mdevils committed Oct 14, 2014
1 parent c70fec7 commit 0f2a630
Show file tree
Hide file tree
Showing 14 changed files with 475 additions and 656 deletions.
51 changes: 30 additions & 21 deletions lib/checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ var Vow = require('vow');
var StringChecker = require('./string-checker');
var utils = require('util');
var path = require('path');
var minimatch = require('minimatch');

var additionalRules = require('./options/additional-rules');
var excludeFiles = require('./options/exclude-files');
var fileExtensions = require('./options/file-extensions');
var NodeConfiguration = require('./config/node-configuration');

/**
* Starts Code Style checking process.
Expand All @@ -27,11 +26,15 @@ utils.inherits(Checker, StringChecker);
Checker.prototype.configure = function(config) {
var cwd = config.configPath ? path.dirname(config.configPath) : process.cwd();

fileExtensions(config, this);
excludeFiles(config, this, cwd);
additionalRules(config, this, cwd);

StringChecker.prototype.configure.apply(this, arguments);

this._fileExtensions = this._configuration.getFileExtensions();

this._excludes = this._configuration.getExcludedFiles().map(function(pattern) {
return new minimatch.Minimatch(path.resolve(cwd, pattern), {
dot: true
});
});
};

/**
Expand All @@ -41,12 +44,10 @@ Checker.prototype.configure = function(config) {
* @returns {Promise * Errors}
*/
Checker.prototype.checkFile = function(path) {
var _this = this;

if (!_this._isExcluded(path)) {
if (!this._isExcluded(path)) {
return vowFs.read(path, 'utf8').then(function(data) {
return _this.checkString(data, path);
});
return this.checkString(data, path);
}, this);
}

var defer = Vow.defer();
Expand All @@ -62,38 +63,36 @@ Checker.prototype.checkFile = function(path) {
* @returns {Promise * Error[]}
*/
Checker.prototype.checkDirectory = function(path) {
var _this = this;

return vowFs.listDir(path).then(function(filenames) {
return Vow.all(filenames.map(function(filename) {
var fullname = path + '/' + filename;

// check for exclude path
if (_this._isExcluded(fullname)) {
if (this._isExcluded(fullname)) {
return [];
}

return vowFs.stat(fullname).then(function(stat) {
if (stat.isDirectory()) {
return _this.checkDirectory(fullname);
return this.checkDirectory(fullname);
}

if (!_this._hasCorrectExtension(fullname)) {
if (!this._hasCorrectExtension(fullname)) {
return [];
}

return Vow.when(_this.checkFile(fullname)).then(function(errors) {
return Vow.when(this.checkFile(fullname)).then(function(errors) {
if (errors) {
return errors;
}

return [];
});
});
})).then(function(results) {
}, this);
}, this)).then(function(results) {
return [].concat.apply([], results);
});
});
}, this);
};

/**
Expand Down Expand Up @@ -181,4 +180,14 @@ Checker.prototype._hasCorrectExtension = function(testPath) {
);
};

/**
* Returns new configuration instance.
*
* @protected
* @returns {Configuration}
*/
Checker.prototype._createConfiguration = function() {
return new NodeConfiguration();
};

module.exports = Checker;
Loading

0 comments on commit 0f2a630

Please sign in to comment.