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

Commit 9aae17e

Browse files
committed
Relative path resolving fix. Fixes #829
1 parent 5eb1541 commit 9aae17e

6 files changed

Lines changed: 48 additions & 16 deletions

File tree

lib/config/configuration.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,9 @@ Configuration.prototype.load = function(config) {
4949

5050
var overrides = this._overrides;
5151
var currentConfig = {};
52-
Object.keys(config).forEach(function(key) {
53-
currentConfig[key] = config[key];
54-
});
55-
Object.keys(overrides).forEach(function(key) {
56-
currentConfig[key] = overrides[key];
57-
});
52+
53+
copyConfiguration(config, currentConfig);
54+
copyConfiguration(overrides, currentConfig);
5855

5956
var ruleSettings = this._processConfig(currentConfig);
6057
var processedSettings = {};
@@ -630,3 +627,12 @@ Configuration.prototype.registerDefaultPresets = function() {
630627
};
631628

632629
module.exports = Configuration;
630+
631+
function copyConfiguration(source, dest) {
632+
Object.keys(source).forEach(function(key) {
633+
dest[key] = source[key];
634+
});
635+
if (source.configPath) {
636+
dest.configPath = source.configPath;
637+
}
638+
}

test/cli.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ var hooker = require('hooker');
22
var sinon = require('sinon');
33
var glob = require('glob');
44
var assert = require('assert');
5-
var Vow = require('vow');
65
var hasAnsi = require('has-ansi');
76
var rewire = require('rewire');
87

@@ -41,7 +40,13 @@ describe('modules/cli', function() {
4140

4241
function assertNoCliErrors(vow) {
4342
return vow.promise.always(function() {
44-
assert(console.log.getCall(0).args[0] === 'No code style errors found.');
43+
var stdout = process.stdout.write.getCall(0) ? process.stdout.write.getCall(0).args[0] : '';
44+
var stderr = process.stderr.write.getCall(0) ? process.stderr.write.getCall(0).args[0] : '';
45+
assert.equal(
46+
stdout,
47+
'No code style errors found.\n',
48+
stderr
49+
);
4550
rAfter();
4651
});
4752
}
@@ -578,7 +583,7 @@ describe('modules/cli', function() {
578583

579584
it('should accept a relative path to a filter module', function() {
580585
return assertNoCliErrors(cli({
581-
errorFilter: './test/data/error-filter.js',
586+
errorFilter: '../error-filter.js',
582587
args: ['test/data/cli/error.js'],
583588
config: 'test/data/cli/cli.json'
584589
}));
@@ -627,4 +632,13 @@ describe('modules/cli', function() {
627632
}));
628633
});
629634
});
635+
636+
describe('additionalRules', function() {
637+
it('should correctly handle additionalRules paths', function() {
638+
return assertNoCliErrors(cli({
639+
args: ['test/data/cli/success.js'],
640+
config: 'test/data/configs/additionalRules/.jscsrc'
641+
}));
642+
});
643+
});
630644
});

test/data/cli/errorFilter.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"errorFilter": "./test/data/error-filter.js",
2+
"errorFilter": "../error-filter.js",
33
"disallowKeywords": ["with"]
44
}

test/data/configs/additionalRules/.jscs.json

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"successRule": true,
3+
"additionalRules": [
4+
"./success-rule.js"
5+
]
6+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = function() {};
2+
3+
module.exports.prototype = {
4+
5+
configure: function() {},
6+
7+
getOptionName: function() {
8+
return 'successRule';
9+
},
10+
11+
check: function(file, errors) {}
12+
};

0 commit comments

Comments
 (0)