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 19, 2014
1 parent c70fec7 commit 4fa4b7a
Show file tree
Hide file tree
Showing 15 changed files with 507 additions and 678 deletions.
53 changes: 25 additions & 28 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 @@ -25,13 +24,9 @@ utils.inherits(Checker, StringChecker);
* @param {Object} config
*/
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();
};

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

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

var defer = Vow.defer();
defer.resolve(null);

return defer.promise();
return Vow.resolve(null);
};

/**
Expand All @@ -62,38 +52,35 @@ 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._configuration.isFileExcluded(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 +168,14 @@ Checker.prototype._hasCorrectExtension = function(testPath) {
);
};

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

module.exports = Checker;

0 comments on commit 4fa4b7a

Please sign in to comment.