From 67e2f6d4820da024269fc37c4082cea7ac87ae2b Mon Sep 17 00:00:00 2001 From: James Long Date: Wed, 4 Jan 2017 20:45:28 -0500 Subject: [PATCH] Simplify how options are normalized (fixes default options) --- index.js | 2 -- src/options.js | 24 ++++++++---------------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index b8c33665a..8cddebe9c 100644 --- a/index.js +++ b/index.js @@ -49,8 +49,6 @@ module.exports = { }); } - ast.tokens = []; - const printer = new Printer(opts); return printer.printGenerically(ast).code; } diff --git a/src/options.js b/src/options.js index 43ec74271..90423779e 100644 --- a/src/options.js +++ b/src/options.js @@ -29,23 +29,15 @@ var defaults = { // Controls the printing of spaces inside array and objects // See: http://eslint.org/docs/rules/array-bracket-spacing bracketSpacing: true -}, hasOwn = defaults.hasOwnProperty; +}; // Copy options and fill in default values. exports.normalize = function(options) { - options = options || defaults; - - function get(key) { - return hasOwn.call(options, key) - ? options[key] - : defaults[key]; - } - - return { - tabWidth: +get("tabWidth"), - printWidth: Math.max(get("printWidth"), 0), - quote: get("quote"), - trailingComma: get("trailingComma"), - bracketSpacing: get("bracketSpacing") - }; + const normalized = Object.assign({}, options); + Object.keys(defaults).forEach(k => { + if(normalized[k] == null) { + normalized[k] = defaults[k]; + } + }); + return normalized; };