Skip to content

Commit

Permalink
Merge pull request #491 from SassDoc/hotfix/verbose-flag
Browse files Browse the repository at this point in the history
Fix verbose flag and environment keys safeguard
  • Loading branch information
pascalduez committed Mar 27, 2017
2 parents 434f4d9 + 6f1a4b3 commit a8d9699
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function cli (argv = process.argv.slice(2)) {
}

let logger = new Logger(options['--verbose'], options['--debug'] || process.env.SASSDOC_DEBUG)
let env = new Environment(logger, options['--strict'])
let env = new Environment(logger, options['--verbose'], options['--strict'])

logger.debug('argv:', () => JSON.stringify(argv))

Expand Down
18 changes: 10 additions & 8 deletions src/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,17 @@ export default class Environment extends EventEmitter {
this.dir = path.dirname(this.file)
}

for (let k of Object.keys(config)) {
if (k in this) {
return this.emit('error', new Error(
`Reserved configuration key \`${k}\`.`
))
}
Object.keys(config)
.filter(key => ['verbose', 'strict'].indexOf(key) === -1)
.forEach(k => {
if (k in this) {
return this.emit('error', new Error(
`Reserved configuration key \`${k}\`.`
))
}

this[k] = config[k]
}
this[k] = config[k]
})
}

/**
Expand Down
18 changes: 16 additions & 2 deletions test/env/environment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('#environment', function () {

beforeEach(function () {
logger = new mock.Logger(true)
env = new Environment(logger, false)
env = new Environment(logger)
warnings = logger.output
})

Expand Down Expand Up @@ -88,7 +88,7 @@ describe('#environment', function () {

beforeEach(function () {
env.on('error', spy)
env.load({ fdomain: 'fail', strict: 'fail' }) // @TODO should not failt on 'strcit'
env.load({ logger: 'fail' })
env.postProcess()
})

Expand All @@ -97,6 +97,20 @@ describe('#environment', function () {
})
})

describe('#config-fail', function () {
var spy = sinon.spy()

beforeEach(function () {
env.on('error', spy)
env.load({ verbose: true, strict: true })
env.postProcess()
})

it('should not error if config contains verbose or strict keys', function () {
assert.equal(spy.called, false)
})
})

/**
* Default .sassdocrc process.
*/
Expand Down

0 comments on commit a8d9699

Please sign in to comment.