Skip to content

Commit

Permalink
Add failing test for Boolean options starting with no-
Browse files Browse the repository at this point in the history
  • Loading branch information
milindl authored and SBoudrias committed Feb 11, 2017
1 parent 51414c0 commit 67b90f4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,14 @@ Base.prototype.option = function option(name, config) {
hide: false
});

// Check whether boolean option is invalid (starts with no-)
if (config.type === Boolean && name.match(/^no-.+/)) {
return this.emit('error', new Error('Option name ' + chalk.bold(name) +
' cannot start with no-\nTo allow user to pass `--no-' +
name + '` use `this.option({' +
name + '}, {type: Boolean})` instead.'));
}

if (this._options[name] == null) {
this._options[name] = config;
}
Expand Down
12 changes: 12 additions & 0 deletions test/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,18 @@ describe('Base', function () {

assert.equal(gen.options.undef, undefined);
});

it('disallows Boolean options starting with no-', function () {
var generator = new this.Dummy([], {
env: this.env,
resolved: 'test'
});
var addWrongOp = function() {
generator.option('no-op');
};
assert.throws(addWrongOp, Error);
});

});

describe('#parseOptions()', function () {
Expand Down

0 comments on commit 67b90f4

Please sign in to comment.