From 9aae17edb06606af1396461e7746c38be436dfad Mon Sep 17 00:00:00 2001 From: mdevils Date: Thu, 18 Dec 2014 16:47:12 +0300 Subject: [PATCH] Relative path resolving fix. Fixes #829 --- lib/config/configuration.js | 18 +++++++++++------ test/cli.js | 20 ++++++++++++++++--- test/data/cli/errorFilter.json | 2 +- test/data/configs/additionalRules/.jscs.json | 6 ------ test/data/configs/additionalRules/.jscsrc | 6 ++++++ .../configs/additionalRules/success-rule.js | 12 +++++++++++ 6 files changed, 48 insertions(+), 16 deletions(-) delete mode 100644 test/data/configs/additionalRules/.jscs.json create mode 100644 test/data/configs/additionalRules/.jscsrc create mode 100644 test/data/configs/additionalRules/success-rule.js diff --git a/lib/config/configuration.js b/lib/config/configuration.js index de2e6caf2..369252187 100644 --- a/lib/config/configuration.js +++ b/lib/config/configuration.js @@ -49,12 +49,9 @@ Configuration.prototype.load = function(config) { var overrides = this._overrides; var currentConfig = {}; - Object.keys(config).forEach(function(key) { - currentConfig[key] = config[key]; - }); - Object.keys(overrides).forEach(function(key) { - currentConfig[key] = overrides[key]; - }); + + copyConfiguration(config, currentConfig); + copyConfiguration(overrides, currentConfig); var ruleSettings = this._processConfig(currentConfig); var processedSettings = {}; @@ -630,3 +627,12 @@ Configuration.prototype.registerDefaultPresets = function() { }; module.exports = Configuration; + +function copyConfiguration(source, dest) { + Object.keys(source).forEach(function(key) { + dest[key] = source[key]; + }); + if (source.configPath) { + dest.configPath = source.configPath; + } +} diff --git a/test/cli.js b/test/cli.js index 6fb6d0c48..5441beb82 100644 --- a/test/cli.js +++ b/test/cli.js @@ -2,7 +2,6 @@ var hooker = require('hooker'); var sinon = require('sinon'); var glob = require('glob'); var assert = require('assert'); -var Vow = require('vow'); var hasAnsi = require('has-ansi'); var rewire = require('rewire'); @@ -41,7 +40,13 @@ describe('modules/cli', function() { function assertNoCliErrors(vow) { return vow.promise.always(function() { - assert(console.log.getCall(0).args[0] === 'No code style errors found.'); + var stdout = process.stdout.write.getCall(0) ? process.stdout.write.getCall(0).args[0] : ''; + var stderr = process.stderr.write.getCall(0) ? process.stderr.write.getCall(0).args[0] : ''; + assert.equal( + stdout, + 'No code style errors found.\n', + stderr + ); rAfter(); }); } @@ -578,7 +583,7 @@ describe('modules/cli', function() { it('should accept a relative path to a filter module', function() { return assertNoCliErrors(cli({ - errorFilter: './test/data/error-filter.js', + errorFilter: '../error-filter.js', args: ['test/data/cli/error.js'], config: 'test/data/cli/cli.json' })); @@ -627,4 +632,13 @@ describe('modules/cli', function() { })); }); }); + + describe('additionalRules', function() { + it('should correctly handle additionalRules paths', function() { + return assertNoCliErrors(cli({ + args: ['test/data/cli/success.js'], + config: 'test/data/configs/additionalRules/.jscsrc' + })); + }); + }); }); diff --git a/test/data/cli/errorFilter.json b/test/data/cli/errorFilter.json index 33b43cba6..a6fc3efe1 100644 --- a/test/data/cli/errorFilter.json +++ b/test/data/cli/errorFilter.json @@ -1,4 +1,4 @@ { - "errorFilter": "./test/data/error-filter.js", + "errorFilter": "../error-filter.js", "disallowKeywords": ["with"] } diff --git a/test/data/configs/additionalRules/.jscs.json b/test/data/configs/additionalRules/.jscs.json deleted file mode 100644 index c739d62cf..000000000 --- a/test/data/configs/additionalRules/.jscs.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "testAdditionalRules": true, - "additionalRules": [ - "../../rules/*.js" - ] -} diff --git a/test/data/configs/additionalRules/.jscsrc b/test/data/configs/additionalRules/.jscsrc new file mode 100644 index 000000000..efb3937db --- /dev/null +++ b/test/data/configs/additionalRules/.jscsrc @@ -0,0 +1,6 @@ +{ + "successRule": true, + "additionalRules": [ + "./success-rule.js" + ] +} diff --git a/test/data/configs/additionalRules/success-rule.js b/test/data/configs/additionalRules/success-rule.js new file mode 100644 index 000000000..ca52de75a --- /dev/null +++ b/test/data/configs/additionalRules/success-rule.js @@ -0,0 +1,12 @@ +module.exports = function() {}; + +module.exports.prototype = { + + configure: function() {}, + + getOptionName: function() { + return 'successRule'; + }, + + check: function(file, errors) {} +};