Skip to content

Fix verbose flag and environment keys safeguard #491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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