From a0231f6f13af1e34bc89199ccd0cc3bd14c9d049 Mon Sep 17 00:00:00 2001 From: Jorge Gonzalez Date: Mon, 23 Jul 2018 18:08:35 -0400 Subject: [PATCH 01/13] Add initial support for TOML in configuration files --- package.json | 3 +- src/config/resolve-config.js | 13 +++++++++ .../__snapshots__/config-resolution.js.snap | 29 +++++++++++++++++++ .../with-config-precedence.js.snap | 20 +++++++++++++ .../__tests__/config-resolution.js | 6 ++++ .../cli/config/rc-toml/.prettierrc.toml | 2 ++ tests_integration/cli/config/rc-toml/file.js | 7 +++++ yarn.lock | 28 ++++++++++-------- 8 files changed, 95 insertions(+), 13 deletions(-) create mode 100644 tests_integration/cli/config/rc-toml/.prettierrc.toml create mode 100644 tests_integration/cli/config/rc-toml/file.js diff --git a/package.json b/package.json index 3696649e19ec..9915bbe15601 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "camelcase": "4.1.0", "chalk": "2.1.0", "cjk-regex": "1.0.2", - "cosmiconfig": "3.1.0", + "cosmiconfig": "5.0.5", "dashify": "0.2.2", "dedent": "0.7.0", "diff": "3.2.0", @@ -56,6 +56,7 @@ "resolve": "1.5.0", "semver": "5.4.1", "string-width": "2.1.1", + "toml": "2.3.3", "typescript": "3.0.0-dev.20180626", "typescript-eslint-parser": "eslint/typescript-eslint-parser#6eec85b1466fbef087838203b246f70fa71ac0ac", "unicode-regex": "1.0.1", diff --git a/src/config/resolve-config.js b/src/config/resolve-config.js index c8f0f43433ab..55c6b96197cd 100644 --- a/src/config/resolve-config.js +++ b/src/config/resolve-config.js @@ -4,9 +4,19 @@ const thirdParty = require("../common/third-party"); const minimatch = require("minimatch"); const path = require("path"); const mem = require("mem"); +const toml = require("toml"); const resolveEditorConfig = require("./resolve-config-editorconfig"); +function loadToml(filePath, content) { + try { + return toml.parse(content); + } catch (error) { + error.message = `TOML Error in ${filePath}:\n${error.message}`; + throw error; + } +} + const getExplorerMemoized = mem(opts => thirdParty.cosmiconfig("prettier", { sync: opts.sync, @@ -17,6 +27,9 @@ const getExplorerMemoized = mem(opts => delete result.config.$schema; } return result; + }, + loaders: { + ".toml": loadToml } }) ); diff --git a/tests_integration/__tests__/__snapshots__/config-resolution.js.snap b/tests_integration/__tests__/__snapshots__/config-resolution.js.snap index 79857ce207f9..b80e9f359b27 100644 --- a/tests_integration/__tests__/__snapshots__/config-resolution.js.snap +++ b/tests_integration/__tests__/__snapshots__/config-resolution.js.snap @@ -62,6 +62,16 @@ function rcJson() { ], ); } +function rcToml() { + console.log.apply( + null, + [ + 'rc-toml/file.js', + 'should have trailing comma', + 'and single quotes', + ], + ); +} function rcYaml() { console.log.apply( null, @@ -142,6 +152,16 @@ function rcJson() { 'and single quotes', ]); } +function rcToml() { + console.log.apply( + null, + [ + 'rc-toml/file.js', + 'should have trailing comma', + 'and single quotes', + ], + ); +} function rcYaml() { console.log.apply(null, [ 'rc-yaml/file.js', @@ -181,6 +201,15 @@ exports[`resolves json configuration file with --find-config-path file (stdout) exports[`resolves json configuration file with --find-config-path file (write) 1`] = `Array []`; +exports[`resolves toml configuration file with --find-config-path file (stderr) 1`] = `""`; + +exports[`resolves toml configuration file with --find-config-path file (stdout) 1`] = ` +".prettierrc +" +`; + +exports[`resolves toml configuration file with --find-config-path file (write) 1`] = `Array []`; + exports[`resolves yaml configuration file with --find-config-path file (stderr) 1`] = `""`; exports[`resolves yaml configuration file with --find-config-path file (stdout) 1`] = ` diff --git a/tests_integration/__tests__/__snapshots__/with-config-precedence.js.snap b/tests_integration/__tests__/__snapshots__/with-config-precedence.js.snap index 5e817c5fac16..ce5002c6b275 100644 --- a/tests_integration/__tests__/__snapshots__/with-config-precedence.js.snap +++ b/tests_integration/__tests__/__snapshots__/with-config-precedence.js.snap @@ -139,6 +139,16 @@ function rcJson() { ], ); } +function rcToml() { + console.log.apply( + null, + [ + 'rc-toml/file.js', + 'should have trailing comma', + 'and single quotes', + ], + ); +} function rcYaml() { console.log.apply( null, @@ -216,6 +226,16 @@ function rcJson() { ], ); } +function rcToml() { + console.log.apply( + null, + [ + 'rc-toml/file.js', + 'should have trailing comma', + 'and single quotes', + ], + ); +} function rcYaml() { console.log.apply( null, diff --git a/tests_integration/__tests__/config-resolution.js b/tests_integration/__tests__/config-resolution.js index d78a55eb84ae..6072fde9796d 100644 --- a/tests_integration/__tests__/config-resolution.js +++ b/tests_integration/__tests__/config-resolution.js @@ -43,6 +43,12 @@ describe("resolves yaml configuration file with --find-config-path file", () => }); }); +describe("resolves toml configuration file with --find-config-path file", () => { + runPrettier("cli/config/", ["--find-config-path", "rc-toml/file.js"]).test({ + status: 0 + }); +}); + describe("prints nothing when no file found with --find-config-path", () => { runPrettier("cli/config/", ["--find-config-path", ".."]).test({ stdout: "", diff --git a/tests_integration/cli/config/rc-toml/.prettierrc.toml b/tests_integration/cli/config/rc-toml/.prettierrc.toml new file mode 100644 index 000000000000..971b0d4cff7b --- /dev/null +++ b/tests_integration/cli/config/rc-toml/.prettierrc.toml @@ -0,0 +1,2 @@ +trailingComma = "all" +singleQuote = true diff --git a/tests_integration/cli/config/rc-toml/file.js b/tests_integration/cli/config/rc-toml/file.js new file mode 100644 index 000000000000..75df5b4b52d2 --- /dev/null +++ b/tests_integration/cli/config/rc-toml/file.js @@ -0,0 +1,7 @@ +function rcToml() { + console.log.apply(null, [ + "rc-toml/file.js", + "should have trailing comma", + "and single quotes" + ]); +} diff --git a/yarn.lock b/yarn.lock index 1407a4102b73..2e33774c6c24 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1504,14 +1504,13 @@ core-util-is@~1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" -cosmiconfig@3.1.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-3.1.0.tgz#640a94bf9847f321800403cd273af60665c73397" +cosmiconfig@5.0.5: + version "5.0.5" + resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-5.0.5.tgz#a809e3c2306891ce17ab70359dc8bdf661fe2cd0" dependencies: is-directory "^0.3.1" js-yaml "^3.9.0" - parse-json "^3.0.0" - require-from-string "^2.0.1" + parse-json "^4.0.0" create-ecdh@^4.0.0: version "4.0.0" @@ -3592,6 +3591,10 @@ json-loader@^0.5.4: version "0.5.4" resolved "https://registry.yarnpkg.com/json-loader/-/json-loader-0.5.4.tgz#8baa1365a632f58a3c46d20175fc6002c96e37de" +json-parse-better-errors@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz#bb867cfb3450e69107c131d1c514bab3dc8bcaa9" + json-schema-traverse@^0.3.0: version "0.3.1" resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz#349a6d44c53a51de89b40805c5d5e59b417d3340" @@ -4308,11 +4311,12 @@ parse-json@^2.2.0: dependencies: error-ex "^1.2.0" -parse-json@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-3.0.0.tgz#fa6f47b18e23826ead32f263e744d0e1e847fb13" +parse-json@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-4.0.0.tgz#be35f5425be1f7f6c747184f98a788cb99477ee0" dependencies: error-ex "^1.3.1" + json-parse-better-errors "^1.0.1" parse5@3.0.3: version "3.0.3" @@ -4873,10 +4877,6 @@ require-directory@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42" -require-from-string@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/require-from-string/-/require-from-string-2.0.1.tgz#c545233e9d7da6616e9d59adfb39fc9f588676ff" - require-main-filename@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-1.0.1.tgz#97f717b69d48784f5f526a6c5aa8ffdda055a4d1" @@ -5549,6 +5549,10 @@ to-regex@^3.0.1, to-regex@^3.0.2: regex-not "^1.0.2" safe-regex "^1.1.0" +toml@2.3.3: + version "2.3.3" + resolved "https://registry.yarnpkg.com/toml/-/toml-2.3.3.tgz#8d683d729577cb286231dfc7a8affe58d31728fb" + tough-cookie@>=2.3.3, tough-cookie@^2.3.3, tough-cookie@~2.3.0, tough-cookie@~2.3.3: version "2.3.4" resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.3.4.tgz#ec60cee38ac675063ffc97a5c18970578ee83655" From 199c36abfc290f0848d9c5f92df02bca09c9f172 Mon Sep 17 00:00:00 2001 From: Jorge Gonzalez Date: Sun, 29 Jul 2018 11:37:39 -0400 Subject: [PATCH 02/13] Missed brace --- src/config/resolve-config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/resolve-config.js b/src/config/resolve-config.js index 4ba32ab0b325..4c013db4fb37 100644 --- a/src/config/resolve-config.js +++ b/src/config/resolve-config.js @@ -17,7 +17,7 @@ function loadToml(filePath, content) { } } -const getExplorerMemoized = mem(opts => +const getExplorerMemoized = mem(opts => { const explorer = thirdParty.cosmiconfig("prettier", { cache: opts.cache, transform: result => { From 49aa533ff910d702e23f11fa34031bc9fd053623 Mon Sep 17 00:00:00 2001 From: Jorge Gonzalez Date: Sun, 29 Jul 2018 12:19:50 -0400 Subject: [PATCH 03/13] Fix snapshots --- src/config/resolve-config.js | 10 ++++++++++ .../__snapshots__/config-resolution.js.snap | 15 ++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/config/resolve-config.js b/src/config/resolve-config.js index 4c013db4fb37..65fd9e5c1b4e 100644 --- a/src/config/resolve-config.js +++ b/src/config/resolve-config.js @@ -33,6 +33,16 @@ const getExplorerMemoized = mem(opts => { } return result; }, + searchPlaces: [ + "package.json", + ".prettierrc", + ".prettierrc.json", + ".prettierrc.yaml", + ".prettierrc.yml", + ".prettierrc.js", + "prettier.config.js", + ".prettierrc.toml" + ], loaders: { ".toml": loadToml } diff --git a/tests_integration/__tests__/__snapshots__/config-resolution.js.snap b/tests_integration/__tests__/__snapshots__/config-resolution.js.snap index b80e9f359b27..96d3dec43199 100644 --- a/tests_integration/__tests__/__snapshots__/config-resolution.js.snap +++ b/tests_integration/__tests__/__snapshots__/config-resolution.js.snap @@ -153,14 +153,11 @@ function rcJson() { ]); } function rcToml() { - console.log.apply( - null, - [ - 'rc-toml/file.js', - 'should have trailing comma', - 'and single quotes', - ], - ); + console.log.apply(null, [ + 'rc-toml/file.js', + 'should have trailing comma', + 'and single quotes', + ]); } function rcYaml() { console.log.apply(null, [ @@ -204,7 +201,7 @@ exports[`resolves json configuration file with --find-config-path file (write) 1 exports[`resolves toml configuration file with --find-config-path file (stderr) 1`] = `""`; exports[`resolves toml configuration file with --find-config-path file (stdout) 1`] = ` -".prettierrc +"rc-toml/.prettierrc.toml " `; From 1c9e2b2424a9e53c5a0e79bf0b4c982b4d3c5f1a Mon Sep 17 00:00:00 2001 From: Jorge Gonzalez Date: Sun, 29 Jul 2018 13:19:26 -0400 Subject: [PATCH 04/13] refactor: move loadToml to utils --- src/config/resolve-config.js | 11 +---------- src/utils/load-toml.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 10 deletions(-) create mode 100644 src/utils/load-toml.js diff --git a/src/config/resolve-config.js b/src/config/resolve-config.js index 65fd9e5c1b4e..ef6898dc4d78 100644 --- a/src/config/resolve-config.js +++ b/src/config/resolve-config.js @@ -4,18 +4,9 @@ const thirdParty = require("../common/third-party"); const minimatch = require("minimatch"); const path = require("path"); const mem = require("mem"); -const toml = require("toml"); const resolveEditorConfig = require("./resolve-config-editorconfig"); - -function loadToml(filePath, content) { - try { - return toml.parse(content); - } catch (error) { - error.message = `TOML Error in ${filePath}:\n${error.message}`; - throw error; - } -} +const loadToml = require("../utils/load-toml"); const getExplorerMemoized = mem(opts => { const explorer = thirdParty.cosmiconfig("prettier", { diff --git a/src/utils/load-toml.js b/src/utils/load-toml.js new file mode 100644 index 000000000000..83c34b77f430 --- /dev/null +++ b/src/utils/load-toml.js @@ -0,0 +1,12 @@ +"use strict"; + +const toml = require("toml"); + +module.exports = function(filePath, content) { + try { + return toml.parse(content); + } catch (error) { + error.message = `TOML Error in ${filePath}:\n${error.message}`; + throw error; + } +}; From 99b9ccdd81f6b5cb0b901a90d964a90d5a601396 Mon Sep 17 00:00:00 2001 From: Jorge Gonzalez Date: Sun, 29 Jul 2018 13:21:20 -0400 Subject: [PATCH 05/13] Use @iarna/toml --- package.json | 2 +- src/utils/load-toml.js | 2 +- yarn.lock | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index d8ee40c4612c..c64c68f78203 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "@babel/code-frame": "7.0.0-beta.46", "@babel/parser": "7.0.0-beta.49", "@glimmer/syntax": "0.30.3", + "@iarna/toml": "2.0.0", "camelcase": "4.1.0", "chalk": "2.1.0", "cjk-regex": "1.0.2", @@ -56,7 +57,6 @@ "resolve": "1.5.0", "semver": "5.4.1", "string-width": "2.1.1", - "toml": "2.3.3", "typescript": "3.0.0-dev.20180626", "typescript-eslint-parser": "17.0.0", "unicode-regex": "1.0.1", diff --git a/src/utils/load-toml.js b/src/utils/load-toml.js index 83c34b77f430..0658c248be61 100644 --- a/src/utils/load-toml.js +++ b/src/utils/load-toml.js @@ -1,6 +1,6 @@ "use strict"; -const toml = require("toml"); +const toml = require("@iarna/toml"); module.exports = function(filePath, content) { try { diff --git a/yarn.lock b/yarn.lock index 451e7c0e89e6..64843118f27a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -563,6 +563,10 @@ dependencies: "@glimmer/util" "^0.30.3" +"@iarna/toml@2.0.0": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@iarna/toml/-/toml-2.0.0.tgz#7802115684397785b3b6dc8a3ba50e30d7a7422b" + "@types/commander@^2.11.0": version "2.12.2" resolved "https://registry.yarnpkg.com/@types/commander/-/commander-2.12.2.tgz#183041a23842d4281478fa5d23c5ca78e6fd08ae" @@ -5549,10 +5553,6 @@ to-regex@^3.0.1, to-regex@^3.0.2: regex-not "^1.0.2" safe-regex "^1.1.0" -toml@2.3.3: - version "2.3.3" - resolved "https://registry.yarnpkg.com/toml/-/toml-2.3.3.tgz#8d683d729577cb286231dfc7a8affe58d31728fb" - tough-cookie@>=2.3.3, tough-cookie@^2.3.3, tough-cookie@~2.3.0, tough-cookie@~2.3.3: version "2.3.4" resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.3.4.tgz#ec60cee38ac675063ffc97a5c18970578ee83655" From 7dfe0b37c78a47c4526390e5497cf62cc288f553 Mon Sep 17 00:00:00 2001 From: Jorge Gonzalez Date: Sun, 29 Jul 2018 13:30:14 -0400 Subject: [PATCH 06/13] Add tests for loadToml --- jest.config.js | 1 + package.json | 1 + .../__tests__/__snapshots__/load-toml.js.snap | 10 +++ tests_integration/__tests__/load-toml.js | 40 ++++++++++++ yarn.lock | 61 ++++++++++++++++++- 5 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 tests_integration/__tests__/__snapshots__/load-toml.js.snap create mode 100644 tests_integration/__tests__/load-toml.js diff --git a/jest.config.js b/jest.config.js index 2351c2b5ab50..5baf5993cc48 100644 --- a/jest.config.js +++ b/jest.config.js @@ -12,6 +12,7 @@ const isOldNode = semver.parse(process.version).major <= 4; module.exports = { setupFiles: ["/tests_config/run_spec.js"], + setupTestFrameworkScriptFile: "jest-extended", snapshotSerializers: ["/tests_config/raw-serializer.js"], testRegex: "jsfmt\\.spec\\.js$|__tests__/.*\\.js$", testPathIgnorePatterns: ["tests/new_react", "tests/more_react"].concat( diff --git a/package.json b/package.json index c64c68f78203..d8b217b8fc79 100644 --- a/package.json +++ b/package.json @@ -81,6 +81,7 @@ "eslint-plugin-react": "7.7.0", "execa": "0.10.0", "jest": "23.3.0", + "jest-extended": "0.7.2", "jest-junit": "5.0.0", "jest-watch-typeahead": "0.1.0", "mkdirp": "0.5.1", diff --git a/tests_integration/__tests__/__snapshots__/load-toml.js.snap b/tests_integration/__tests__/__snapshots__/load-toml.js.snap new file mode 100644 index 000000000000..38a7db225ab5 --- /dev/null +++ b/tests_integration/__tests__/__snapshots__/load-toml.js.snap @@ -0,0 +1,10 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`TOML throws error on incorrect toml 1`] = ` +"TOML Error in /Users/jorge/Code/prettier/tests_integration/__tests__/load-toml.js: +Unknown character \\"47\\" at row 1, col 2, pos 1: +1> ///ERROR/// + ^ + +" +`; diff --git a/tests_integration/__tests__/load-toml.js b/tests_integration/__tests__/load-toml.js new file mode 100644 index 000000000000..8886cf121c6a --- /dev/null +++ b/tests_integration/__tests__/load-toml.js @@ -0,0 +1,40 @@ +"use strict"; + +require("jest-extended"); +const path = require("path"); +const loadToml = require("../../src/utils/load-toml"); + +describe("TOML", () => { + const currentFile = path.join(__dirname, "load-toml.js"); + + const exampleToml = ` +# This is a TOML document. +title = "TOML Example" +[owner] +name = "Tom Preston-Werner" +dob = 1979-05-27T07:32:00-08:00 # First class dates +[database] +server = "192.168.1.1" +ports = [ 8001, 8001, 8002 ] +connection_max = 5000 +enabled = true +`; + + const wrongToml = "///ERROR///"; + + test("loads toml successfully", () => { + const parsedToml = loadToml(currentFile, exampleToml); + expect(parsedToml).toBeObject(); + expect(parsedToml).toContainAllKeys(["title", "owner", "database"]); + }); + + test("throws error on incorrect toml", () => { + expect(() => { + loadToml(currentFile, wrongToml); + }).toThrow(); + + expect(() => { + loadToml(currentFile, wrongToml); + }).toThrowErrorMatchingSnapshot(); + }); +}); diff --git a/yarn.lock b/yarn.lock index 64843118f27a..d712ae0c2d75 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1288,7 +1288,7 @@ chalk@^1.0.0, chalk@^1.1.1, chalk@^1.1.3: strip-ansi "^3.0.0" supports-color "^2.0.0" -chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.1, chalk@^2.4.1: +chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.0, chalk@^2.3.1, chalk@^2.4.1: version "2.4.1" resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.1.tgz#18c49ab16a037b6eb0152cc83e3471338215b66e" dependencies: @@ -2195,6 +2195,17 @@ expand-range@^1.8.1: dependencies: fill-range "^2.1.0" +expect@^22.1.0: + version "22.4.3" + resolved "https://registry.yarnpkg.com/expect/-/expect-22.4.3.tgz#d5a29d0a0e1fb2153557caef2674d4547e914674" + dependencies: + ansi-styles "^3.2.0" + jest-diff "^22.4.3" + jest-get-type "^22.4.3" + jest-matcher-utils "^22.4.3" + jest-message-util "^22.4.3" + jest-regex-util "^22.4.3" + expect@^23.3.0: version "23.3.0" resolved "https://registry.yarnpkg.com/expect/-/expect-23.3.0.tgz#ecb051adcbdc40ac4db576c16067f12fdb13cc61" @@ -3269,6 +3280,15 @@ jest-config@^23.3.0: jest-validate "^23.3.0" pretty-format "^23.2.0" +jest-diff@^22.4.3: + version "22.4.3" + resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-22.4.3.tgz#e18cc3feff0aeef159d02310f2686d4065378030" + dependencies: + chalk "^2.0.1" + diff "^3.2.0" + jest-get-type "^22.4.3" + pretty-format "^22.4.3" + jest-diff@^23.0.1, jest-diff@^23.2.0: version "23.2.0" resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-23.2.0.tgz#9f2cf4b51e12c791550200abc16b47130af1062a" @@ -3310,7 +3330,15 @@ jest-environment-node@^23.3.0: jest-mock "^23.2.0" jest-util "^23.3.0" -jest-get-type@^22.1.0: +jest-extended@0.7.2: + version "0.7.2" + resolved "https://registry.yarnpkg.com/jest-extended/-/jest-extended-0.7.2.tgz#98fdb5349f1cf950ff7cd403a908ba525a77bba0" + dependencies: + chalk "^2.3.0" + expect "^22.1.0" + jest-matcher-utils "^22.0.0" + +jest-get-type@^22.1.0, jest-get-type@^22.4.3: version "22.4.3" resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-22.4.3.tgz#e3a8504d8479342dd4420236b322869f18900ce4" @@ -3357,6 +3385,14 @@ jest-leak-detector@^23.2.0: dependencies: pretty-format "^23.2.0" +jest-matcher-utils@^22.0.0, jest-matcher-utils@^22.4.3: + version "22.4.3" + resolved "https://registry.yarnpkg.com/jest-matcher-utils/-/jest-matcher-utils-22.4.3.tgz#4632fe428ebc73ebc194d3c7b65d37b161f710ff" + dependencies: + chalk "^2.0.1" + jest-get-type "^22.4.3" + pretty-format "^22.4.3" + jest-matcher-utils@^23.2.0: version "23.2.0" resolved "https://registry.yarnpkg.com/jest-matcher-utils/-/jest-matcher-utils-23.2.0.tgz#4d4981f23213e939e3cedf23dc34c747b5ae1913" @@ -3365,6 +3401,16 @@ jest-matcher-utils@^23.2.0: jest-get-type "^22.1.0" pretty-format "^23.2.0" +jest-message-util@^22.4.3: + version "22.4.3" + resolved "https://registry.yarnpkg.com/jest-message-util/-/jest-message-util-22.4.3.tgz#cf3d38aafe4befddbfc455e57d65d5239e399eb7" + dependencies: + "@babel/code-frame" "^7.0.0-beta.35" + chalk "^2.0.1" + micromatch "^2.3.11" + slash "^1.0.0" + stack-utils "^1.0.1" + jest-message-util@^23.3.0: version "23.3.0" resolved "https://registry.yarnpkg.com/jest-message-util/-/jest-message-util-23.3.0.tgz#bc07b11cec6971fb5dd9de2dfb60ebc22150c160" @@ -3379,6 +3425,10 @@ jest-mock@^23.2.0: version "23.2.0" resolved "https://registry.yarnpkg.com/jest-mock/-/jest-mock-23.2.0.tgz#ad1c60f29e8719d47c26e1138098b6d18b261134" +jest-regex-util@^22.4.3: + version "22.4.3" + resolved "https://registry.yarnpkg.com/jest-regex-util/-/jest-regex-util-22.4.3.tgz#a826eb191cdf22502198c5401a1fc04de9cef5af" + jest-regex-util@^23.3.0: version "23.3.0" resolved "https://registry.yarnpkg.com/jest-regex-util/-/jest-regex-util-23.3.0.tgz#5f86729547c2785c4002ceaa8f849fe8ca471bc5" @@ -4511,6 +4561,13 @@ prettier@1.14.0: version "1.14.0" resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.14.0.tgz#847c235522035fd988100f1f43cf20a7d24f9372" +pretty-format@^22.4.3: + version "22.4.3" + resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-22.4.3.tgz#f873d780839a9c02e9664c8a082e9ee79eaac16f" + dependencies: + ansi-regex "^3.0.0" + ansi-styles "^3.2.0" + pretty-format@^23.0.1: version "23.0.1" resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-23.0.1.tgz#d61d065268e4c759083bccbca27a01ad7c7601f4" From 6a0cda3c732399acaefd11d1388da048c65aa9af Mon Sep 17 00:00:00 2001 From: Jorge Gonzalez Date: Sun, 29 Jul 2018 13:48:46 -0400 Subject: [PATCH 07/13] Fix test for CI --- tests_integration/__tests__/__snapshots__/load-toml.js.snap | 2 +- tests_integration/__tests__/load-toml.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tests_integration/__tests__/__snapshots__/load-toml.js.snap b/tests_integration/__tests__/__snapshots__/load-toml.js.snap index 38a7db225ab5..090275707c78 100644 --- a/tests_integration/__tests__/__snapshots__/load-toml.js.snap +++ b/tests_integration/__tests__/__snapshots__/load-toml.js.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`TOML throws error on incorrect toml 1`] = ` -"TOML Error in /Users/jorge/Code/prettier/tests_integration/__tests__/load-toml.js: +"TOML Error in load-toml.js: Unknown character \\"47\\" at row 1, col 2, pos 1: 1> ///ERROR/// ^ diff --git a/tests_integration/__tests__/load-toml.js b/tests_integration/__tests__/load-toml.js index 8886cf121c6a..ceb55719989c 100644 --- a/tests_integration/__tests__/load-toml.js +++ b/tests_integration/__tests__/load-toml.js @@ -1,11 +1,10 @@ "use strict"; require("jest-extended"); -const path = require("path"); const loadToml = require("../../src/utils/load-toml"); describe("TOML", () => { - const currentFile = path.join(__dirname, "load-toml.js"); + const currentFile = "load-toml.js"; const exampleToml = ` # This is a TOML document. From 3a7d0a6e74c4efd5f6f243d93ff31d5a7a621852 Mon Sep 17 00:00:00 2001 From: Jorge Gonzalez Date: Sun, 29 Jul 2018 14:27:24 -0400 Subject: [PATCH 08/13] Remove jest-extended --- jest.config.js | 1 - package.json | 1 - tests_integration/__tests__/load-toml.js | 23 +++++++-- yarn.lock | 61 +----------------------- 4 files changed, 22 insertions(+), 64 deletions(-) diff --git a/jest.config.js b/jest.config.js index 5baf5993cc48..2351c2b5ab50 100644 --- a/jest.config.js +++ b/jest.config.js @@ -12,7 +12,6 @@ const isOldNode = semver.parse(process.version).major <= 4; module.exports = { setupFiles: ["/tests_config/run_spec.js"], - setupTestFrameworkScriptFile: "jest-extended", snapshotSerializers: ["/tests_config/raw-serializer.js"], testRegex: "jsfmt\\.spec\\.js$|__tests__/.*\\.js$", testPathIgnorePatterns: ["tests/new_react", "tests/more_react"].concat( diff --git a/package.json b/package.json index d8b217b8fc79..c64c68f78203 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,6 @@ "eslint-plugin-react": "7.7.0", "execa": "0.10.0", "jest": "23.3.0", - "jest-extended": "0.7.2", "jest-junit": "5.0.0", "jest-watch-typeahead": "0.1.0", "mkdirp": "0.5.1", diff --git a/tests_integration/__tests__/load-toml.js b/tests_integration/__tests__/load-toml.js index ceb55719989c..d074023ac013 100644 --- a/tests_integration/__tests__/load-toml.js +++ b/tests_integration/__tests__/load-toml.js @@ -1,6 +1,5 @@ "use strict"; -require("jest-extended"); const loadToml = require("../../src/utils/load-toml"); describe("TOML", () => { @@ -21,10 +20,28 @@ enabled = true const wrongToml = "///ERROR///"; + const expectedObject = { + title: "TOML Example", + owner: { + name: "Tom Preston-Werner", + dob: new Date("1979-05-27T15:32:00.000Z") + }, + database: { + server: "192.168.1.1", + ports: [8001, 8001, 8002], + connection_max: 5000, + enabled: true + } + }; + test("loads toml successfully", () => { const parsedToml = loadToml(currentFile, exampleToml); - expect(parsedToml).toBeObject(); - expect(parsedToml).toContainAllKeys(["title", "owner", "database"]); + + expect(parsedToml.title).toBe("TOML Example"); + expect(parsedToml).toEqual(expectedObject); + expect(Object.keys(parsedToml).sort()).toEqual( + Object.keys(expectedObject).sort() + ); }); test("throws error on incorrect toml", () => { diff --git a/yarn.lock b/yarn.lock index d712ae0c2d75..64843118f27a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1288,7 +1288,7 @@ chalk@^1.0.0, chalk@^1.1.1, chalk@^1.1.3: strip-ansi "^3.0.0" supports-color "^2.0.0" -chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.0, chalk@^2.3.1, chalk@^2.4.1: +chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.1, chalk@^2.4.1: version "2.4.1" resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.1.tgz#18c49ab16a037b6eb0152cc83e3471338215b66e" dependencies: @@ -2195,17 +2195,6 @@ expand-range@^1.8.1: dependencies: fill-range "^2.1.0" -expect@^22.1.0: - version "22.4.3" - resolved "https://registry.yarnpkg.com/expect/-/expect-22.4.3.tgz#d5a29d0a0e1fb2153557caef2674d4547e914674" - dependencies: - ansi-styles "^3.2.0" - jest-diff "^22.4.3" - jest-get-type "^22.4.3" - jest-matcher-utils "^22.4.3" - jest-message-util "^22.4.3" - jest-regex-util "^22.4.3" - expect@^23.3.0: version "23.3.0" resolved "https://registry.yarnpkg.com/expect/-/expect-23.3.0.tgz#ecb051adcbdc40ac4db576c16067f12fdb13cc61" @@ -3280,15 +3269,6 @@ jest-config@^23.3.0: jest-validate "^23.3.0" pretty-format "^23.2.0" -jest-diff@^22.4.3: - version "22.4.3" - resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-22.4.3.tgz#e18cc3feff0aeef159d02310f2686d4065378030" - dependencies: - chalk "^2.0.1" - diff "^3.2.0" - jest-get-type "^22.4.3" - pretty-format "^22.4.3" - jest-diff@^23.0.1, jest-diff@^23.2.0: version "23.2.0" resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-23.2.0.tgz#9f2cf4b51e12c791550200abc16b47130af1062a" @@ -3330,15 +3310,7 @@ jest-environment-node@^23.3.0: jest-mock "^23.2.0" jest-util "^23.3.0" -jest-extended@0.7.2: - version "0.7.2" - resolved "https://registry.yarnpkg.com/jest-extended/-/jest-extended-0.7.2.tgz#98fdb5349f1cf950ff7cd403a908ba525a77bba0" - dependencies: - chalk "^2.3.0" - expect "^22.1.0" - jest-matcher-utils "^22.0.0" - -jest-get-type@^22.1.0, jest-get-type@^22.4.3: +jest-get-type@^22.1.0: version "22.4.3" resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-22.4.3.tgz#e3a8504d8479342dd4420236b322869f18900ce4" @@ -3385,14 +3357,6 @@ jest-leak-detector@^23.2.0: dependencies: pretty-format "^23.2.0" -jest-matcher-utils@^22.0.0, jest-matcher-utils@^22.4.3: - version "22.4.3" - resolved "https://registry.yarnpkg.com/jest-matcher-utils/-/jest-matcher-utils-22.4.3.tgz#4632fe428ebc73ebc194d3c7b65d37b161f710ff" - dependencies: - chalk "^2.0.1" - jest-get-type "^22.4.3" - pretty-format "^22.4.3" - jest-matcher-utils@^23.2.0: version "23.2.0" resolved "https://registry.yarnpkg.com/jest-matcher-utils/-/jest-matcher-utils-23.2.0.tgz#4d4981f23213e939e3cedf23dc34c747b5ae1913" @@ -3401,16 +3365,6 @@ jest-matcher-utils@^23.2.0: jest-get-type "^22.1.0" pretty-format "^23.2.0" -jest-message-util@^22.4.3: - version "22.4.3" - resolved "https://registry.yarnpkg.com/jest-message-util/-/jest-message-util-22.4.3.tgz#cf3d38aafe4befddbfc455e57d65d5239e399eb7" - dependencies: - "@babel/code-frame" "^7.0.0-beta.35" - chalk "^2.0.1" - micromatch "^2.3.11" - slash "^1.0.0" - stack-utils "^1.0.1" - jest-message-util@^23.3.0: version "23.3.0" resolved "https://registry.yarnpkg.com/jest-message-util/-/jest-message-util-23.3.0.tgz#bc07b11cec6971fb5dd9de2dfb60ebc22150c160" @@ -3425,10 +3379,6 @@ jest-mock@^23.2.0: version "23.2.0" resolved "https://registry.yarnpkg.com/jest-mock/-/jest-mock-23.2.0.tgz#ad1c60f29e8719d47c26e1138098b6d18b261134" -jest-regex-util@^22.4.3: - version "22.4.3" - resolved "https://registry.yarnpkg.com/jest-regex-util/-/jest-regex-util-22.4.3.tgz#a826eb191cdf22502198c5401a1fc04de9cef5af" - jest-regex-util@^23.3.0: version "23.3.0" resolved "https://registry.yarnpkg.com/jest-regex-util/-/jest-regex-util-23.3.0.tgz#5f86729547c2785c4002ceaa8f849fe8ca471bc5" @@ -4561,13 +4511,6 @@ prettier@1.14.0: version "1.14.0" resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.14.0.tgz#847c235522035fd988100f1f43cf20a7d24f9372" -pretty-format@^22.4.3: - version "22.4.3" - resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-22.4.3.tgz#f873d780839a9c02e9664c8a082e9ee79eaac16f" - dependencies: - ansi-regex "^3.0.0" - ansi-styles "^3.2.0" - pretty-format@^23.0.1: version "23.0.1" resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-23.0.1.tgz#d61d065268e4c759083bccbca27a01ad7c7601f4" From 8e88fb1c16846afb02ae3bcb366bee8066bdf78c Mon Sep 17 00:00:00 2001 From: Jorge Gonzalez Date: Sun, 29 Jul 2018 14:37:15 -0400 Subject: [PATCH 09/13] Create snapshot for load-toml --- .../__tests__/__snapshots__/load-toml.js.snap | 26 +++++++++++++++++++ tests_integration/__tests__/load-toml.js | 21 +-------------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/tests_integration/__tests__/__snapshots__/load-toml.js.snap b/tests_integration/__tests__/__snapshots__/load-toml.js.snap index 090275707c78..ab4196da0552 100644 --- a/tests_integration/__tests__/__snapshots__/load-toml.js.snap +++ b/tests_integration/__tests__/__snapshots__/load-toml.js.snap @@ -1,5 +1,31 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`TOML loads toml successfully 1`] = ` +Object { + "database": Object { + "connection_max": 5000, + "enabled": true, + "ports": Array [ + 8001, + 8001, + 8002, + ], + "server": "192.168.1.1", + Symbol(type): Symbol(table), + Symbol(declared): true, + }, + "owner": Object { + "dob": 1979-05-27T15:32:00.000Z, + "name": "Tom Preston-Werner", + Symbol(type): Symbol(table), + Symbol(declared): true, + }, + "title": "TOML Example", + Symbol(type): Symbol(table), + Symbol(declared): false, +} +`; + exports[`TOML throws error on incorrect toml 1`] = ` "TOML Error in load-toml.js: Unknown character \\"47\\" at row 1, col 2, pos 1: diff --git a/tests_integration/__tests__/load-toml.js b/tests_integration/__tests__/load-toml.js index d074023ac013..c4fc69aad332 100644 --- a/tests_integration/__tests__/load-toml.js +++ b/tests_integration/__tests__/load-toml.js @@ -20,28 +20,9 @@ enabled = true const wrongToml = "///ERROR///"; - const expectedObject = { - title: "TOML Example", - owner: { - name: "Tom Preston-Werner", - dob: new Date("1979-05-27T15:32:00.000Z") - }, - database: { - server: "192.168.1.1", - ports: [8001, 8001, 8002], - connection_max: 5000, - enabled: true - } - }; - test("loads toml successfully", () => { const parsedToml = loadToml(currentFile, exampleToml); - - expect(parsedToml.title).toBe("TOML Example"); - expect(parsedToml).toEqual(expectedObject); - expect(Object.keys(parsedToml).sort()).toEqual( - Object.keys(expectedObject).sort() - ); + expect(parsedToml).toMatchSnapshot(); }); test("throws error on incorrect toml", () => { From c8e30f849c18957175914bd9742f99fe7a51b01d Mon Sep 17 00:00:00 2001 From: Jorge Gonzalez Date: Sun, 29 Jul 2018 18:17:51 -0400 Subject: [PATCH 10/13] Add feat to docs --- docs/configuration.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/configuration.md b/docs/configuration.md index 38afd0f312a0..ee0bd88fbb79 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -6,6 +6,7 @@ title: Configuration File Prettier uses [cosmiconfig](https://github.com/davidtheclark/cosmiconfig) for configuration file support. This means you can configure prettier via: - A `.prettierrc` file, written in YAML or JSON, with optional extensions: `.yaml/.yml/.json/.js`. +- A `.prettierrc.toml` file, written in TOML (the `.toml` extension is *required*). - A `prettier.config.js` file that exports an object. - A `"prettier"` key in your `package.json` file. @@ -42,6 +43,14 @@ printWidth: 100 parser: flow ``` +TOML: + +```toml +# .prettierrc.toml +printWidth = 100 +parser = "flow" +``` + ## Configuration Overrides Prettier borrows eslint's [override format](http://eslint.org/docs/user-guide/configuring#example-configuration). This allows you to apply configuration to specific files. From c293380eccf8b16db62c1f2e8d99215368736b40 Mon Sep 17 00:00:00 2001 From: Jorge Gonzalez Date: Sun, 29 Jul 2018 18:53:11 -0400 Subject: [PATCH 11/13] lint docs --- docs/configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/configuration.md b/docs/configuration.md index ee0bd88fbb79..1cb62755b1ed 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -6,7 +6,7 @@ title: Configuration File Prettier uses [cosmiconfig](https://github.com/davidtheclark/cosmiconfig) for configuration file support. This means you can configure prettier via: - A `.prettierrc` file, written in YAML or JSON, with optional extensions: `.yaml/.yml/.json/.js`. -- A `.prettierrc.toml` file, written in TOML (the `.toml` extension is *required*). +- A `.prettierrc.toml` file, written in TOML (the `.toml` extension is _required_). - A `prettier.config.js` file that exports an object. - A `"prettier"` key in your `package.json` file. From f55cf6185ebc95cef548cba0567988834fe385b0 Mon Sep 17 00:00:00 2001 From: Jorge Gonzalez Date: Sun, 29 Jul 2018 21:31:54 -0400 Subject: [PATCH 12/13] Use @iarna/toml/parse-string --- src/utils/load-toml.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/load-toml.js b/src/utils/load-toml.js index 0658c248be61..f8b5c7c7948c 100644 --- a/src/utils/load-toml.js +++ b/src/utils/load-toml.js @@ -1,10 +1,10 @@ "use strict"; -const toml = require("@iarna/toml"); +const parse = require("@iarna/toml/parse-string"); module.exports = function(filePath, content) { try { - return toml.parse(content); + return parse(content); } catch (error) { error.message = `TOML Error in ${filePath}:\n${error.message}`; throw error; From 34b1f7cb64fb4780a7dab6e832e4a1216bac2265 Mon Sep 17 00:00:00 2001 From: Jorge Gonzalez Date: Sun, 29 Jul 2018 21:35:57 -0400 Subject: [PATCH 13/13] Change path string --- .../__tests__/__snapshots__/load-toml.js.snap | 2 +- tests_integration/__tests__/load-toml.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests_integration/__tests__/__snapshots__/load-toml.js.snap b/tests_integration/__tests__/__snapshots__/load-toml.js.snap index ab4196da0552..175f48849c8f 100644 --- a/tests_integration/__tests__/__snapshots__/load-toml.js.snap +++ b/tests_integration/__tests__/__snapshots__/load-toml.js.snap @@ -27,7 +27,7 @@ Object { `; exports[`TOML throws error on incorrect toml 1`] = ` -"TOML Error in load-toml.js: +"TOML Error in example.toml: Unknown character \\"47\\" at row 1, col 2, pos 1: 1> ///ERROR/// ^ diff --git a/tests_integration/__tests__/load-toml.js b/tests_integration/__tests__/load-toml.js index c4fc69aad332..138847a92da3 100644 --- a/tests_integration/__tests__/load-toml.js +++ b/tests_integration/__tests__/load-toml.js @@ -3,7 +3,7 @@ const loadToml = require("../../src/utils/load-toml"); describe("TOML", () => { - const currentFile = "load-toml.js"; + const exampleFilePath = "example.toml"; const exampleToml = ` # This is a TOML document. @@ -21,17 +21,17 @@ enabled = true const wrongToml = "///ERROR///"; test("loads toml successfully", () => { - const parsedToml = loadToml(currentFile, exampleToml); + const parsedToml = loadToml(exampleFilePath, exampleToml); expect(parsedToml).toMatchSnapshot(); }); test("throws error on incorrect toml", () => { expect(() => { - loadToml(currentFile, wrongToml); + loadToml(exampleFilePath, wrongToml); }).toThrow(); expect(() => { - loadToml(currentFile, wrongToml); + loadToml(exampleFilePath, wrongToml); }).toThrowErrorMatchingSnapshot(); }); });