Validate user-provided config with jest-validate (#301)
* Validate user-provided config with jest-validate * Don't use object shorthand * Update jest-validate to 18.2 * Fix Node4 destructuring from require * Make use of jest-validate for deprecation message * Remove chalk referencemaster
parent
c230562f65
commit
66fe2f78fa
|
@ -27,6 +27,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"jest": "18.0.0",
|
||||
"jest-validate": "18.2.0",
|
||||
"rollup": "0.41.1",
|
||||
"rollup-plugin-commonjs": "7.0.0",
|
||||
"rollup-plugin-json": "2.1.0",
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
"use strict";
|
||||
|
||||
const deprecated = {
|
||||
useFlowParser: config =>
|
||||
` The ${"\"useFlowParser\""} option is deprecated. Use ${"\"parser\""} instead.
|
||||
|
||||
Prettier now treats your configuration as:
|
||||
{
|
||||
${"\"parser\""}: ${config.seFlowParser ? "\"flow\"" : "\"babylon\""}
|
||||
}`
|
||||
};
|
||||
|
||||
module.exports = deprecated;
|
|
@ -1,4 +1,8 @@
|
|||
"use strict";
|
||||
|
||||
var validate = require("jest-validate").validate;
|
||||
var deprecatedConfig = require("./deprecated");
|
||||
|
||||
var defaults = {
|
||||
// Number of spaces the pretty-printer should use per tab
|
||||
tabWidth: 2,
|
||||
|
@ -14,15 +18,19 @@ var defaults = {
|
|||
parser: "babylon"
|
||||
};
|
||||
|
||||
var exampleConfig = Object.assign({}, defaults, {
|
||||
filename: "testFilename",
|
||||
printWidth: 80,
|
||||
originalText: "text"
|
||||
});
|
||||
|
||||
// Copy options and fill in default values.
|
||||
function normalize(options) {
|
||||
validate(options, { exampleConfig, deprecatedConfig });
|
||||
const normalized = Object.assign({}, options || {});
|
||||
|
||||
// For backward compatibility. Deprecated in 0.0.10
|
||||
if ("useFlowParser" in normalized) {
|
||||
console.warn(
|
||||
'The `"useFlowParser": true/false` option is deprecated. Use `parser: "flow"` instead.'
|
||||
);
|
||||
normalized.parser = normalized.useFlowParser ? "flow" : "babylon";
|
||||
delete normalized.useFlowParser;
|
||||
}
|
||||
|
|
13
yarn.lock
13
yarn.lock
|
@ -1441,6 +1441,15 @@ jest-util@^18.1.0:
|
|||
jest-mock "^18.0.0"
|
||||
mkdirp "^0.5.1"
|
||||
|
||||
jest-validate@18.2.0:
|
||||
version "18.2.0"
|
||||
resolved "https://registry.yarnpkg.com/jest-validate/-/jest-validate-18.2.0.tgz#01f93ac78f23901cf9889808e2bbb931ffc58d86"
|
||||
dependencies:
|
||||
chalk "^1.1.1"
|
||||
jest-matcher-utils "^18.1.0"
|
||||
leven "^2.0.0"
|
||||
pretty-format "^18.1.0"
|
||||
|
||||
jest@18.0.0:
|
||||
version "18.0.0"
|
||||
resolved "https://registry.yarnpkg.com/jest/-/jest-18.0.0.tgz#ef12f70befe0fcb30f1c61c0ae58748706267d4b"
|
||||
|
@ -1551,6 +1560,10 @@ lcid@^1.0.0:
|
|||
dependencies:
|
||||
invert-kv "^1.0.0"
|
||||
|
||||
leven@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/leven/-/leven-2.0.0.tgz#74c45744439550da185801912829f61d22071bc1"
|
||||
|
||||
levn@~0.3.0:
|
||||
version "0.3.0"
|
||||
resolved "https://registry.yarnpkg.com/levn/-/levn-0.3.0.tgz#3b09924edf9f083c0490fdd4c0bc4421e04764ee"
|
||||
|
|
Loading…
Reference in New Issue