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

Commit 5eb44a7

Browse files
committed
Configuration: do not try to load presets with function values
Fixes #1947 Closes gh-1950
1 parent b54acbe commit 5eb44a7

File tree

3 files changed

+12
-30
lines changed

3 files changed

+12
-30
lines changed

lib/config/configuration.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,10 @@ Configuration.prototype.getRegisteredRules = function() {
886886
Configuration.prototype.registerPreset = function(presetName, presetConfig) {
887887
assert(_.isPlainObject(presetConfig), 'Preset should be an object');
888888

889+
for (var key in presetConfig) {
890+
assert(typeof presetConfig[key] !== 'function', 'Preset should be an JSON object');
891+
}
892+
889893
this._presets[presetName] = presetConfig;
890894
};
891895

test/specs/config/configuration.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,14 @@ describe('config/configuration', function() {
242242
configuration.registerPreset.bind(configuration, 'test', undefined)
243243
).to.throw('Preset should be an object');
244244
});
245+
246+
it('should throw if preset if it is not JSON', function() {
247+
expect(
248+
configuration.registerPreset.bind(configuration, 'test', {
249+
'test': function() {}
250+
})
251+
).to.throw('Preset should be an JSON object');
252+
});
245253
});
246254

247255
describe('getFix', function() {

test/specs/config/node-configuration.js

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -228,26 +228,6 @@ describe('modules/config/node-configuration', function() {
228228
expect(configuration.getPresetName()).to.equal('external');
229229
});
230230

231-
it('should try to load preset from node', function() {
232-
configuration.registerDefaultRules();
233-
configuration.load({
234-
preset: 'path'
235-
});
236-
237-
expect(configuration.getPresetName()).to.equal('path');
238-
expect(configuration.getUnsupportedRuleNames().indexOf('resolve')).to.be.above(-1);
239-
});
240-
241-
it('should try to load preset from node_modules', function() {
242-
configuration.registerDefaultRules();
243-
configuration.load({
244-
preset: 'sinon'
245-
});
246-
247-
expect(configuration.getPresetName()).to.equal('sinon');
248-
expect(configuration.getUnsupportedRuleNames().indexOf('spy')).to.be.above(-1);
249-
});
250-
251231
it('should load preset from preset', function() {
252232
configuration.load({
253233
preset: path.resolve('./test/data/configs/modules/node_modules/jscs-t-test/index.json')
@@ -384,16 +364,6 @@ describe('modules/config/node-configuration', function() {
384364
})).to.throw('Preset "not-exist" does not exist');
385365
});
386366

387-
it('should try to load preset from node_modules', function() {
388-
configuration.registerDefaultRules();
389-
configuration.load({
390-
preset: 'sinon'
391-
});
392-
393-
expect(configuration.getPresetName()).to.equal('sinon');
394-
expect(configuration.getUnsupportedRuleNames().indexOf('spy')).to.be.above(-1);
395-
});
396-
397367
it('should accept `additionalRules` to register rule instances', function() {
398368
var rule = {
399369
getOptionName: function() {

0 commit comments

Comments
 (0)