Simplify how options are normalized (fixes default options)
This commit is contained in:
1 parent
599b4311bb
commit
67e2f6d482
2 files changed
+8
-18
No files matched your search
@@ -49,8 +49,6 @@ module.exports = {
|
||||
});
|
||||
}
|
||||
|
||||
ast.tokens = [];
|
||||
|
||||
const printer = new Printer(opts);
|
||||
return printer.printGenerically(ast).code;
|
||||
}
|
||||
|
||||
+8
-16
@@ -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;
|
||||
};
|
||||
Reference in new issue
Block a user