diff --git a/src/main/options-normalizer.js b/src/main/options-normalizer.js index ca9dd2bff..69fd3384d 100644 --- a/src/main/options-normalizer.js +++ b/src/main/options-normalizer.js @@ -46,6 +46,8 @@ class FlagSchema extends vnopts.ChoiceSchema { } } +let hasDeprecationWarned; + function normalizeOptions( options, optionInfos, @@ -60,7 +62,25 @@ function normalizeOptions( const descriptor = isCLI ? cliDescriptor : vnopts.apiDescriptor; const schemas = optionInfosToSchemas(optionInfos, { isCLI }); - return vnopts.normalize(options, schemas, { logger, unknown, descriptor }); + const normalizer = new vnopts.Normalizer(schemas, { + logger, + unknown, + descriptor + }); + + const shouldSuppressDuplicateDeprecationWarnings = logger !== false; + + if (shouldSuppressDuplicateDeprecationWarnings && hasDeprecationWarned) { + normalizer._hasDeprecationWarned = hasDeprecationWarned; + } + + const normalized = normalizer.normalize(options); + + if (shouldSuppressDuplicateDeprecationWarnings) { + hasDeprecationWarned = normalizer._hasDeprecationWarned; + } + + return normalized; } function optionInfosToSchemas(optionInfos, { isCLI }) { diff --git a/tests_integration/__tests__/__snapshots__/deprecated-parser.js.snap b/tests_integration/__tests__/__snapshots__/deprecated-parser.js.snap index 464381bb6..5c4cc0c03 100644 --- a/tests_integration/__tests__/__snapshots__/deprecated-parser.js.snap +++ b/tests_integration/__tests__/__snapshots__/deprecated-parser.js.snap @@ -1,10 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`API format with deprecated parser (babylon) should work 1`] = ` -"{ parser: \\"babylon\\" } is deprecated; we now treat it as { parser: \\"babel\\" }. -" -`; - exports[`API format with deprecated parser (postcss) should work 1`] = ` "{ parser: \\"postcss\\" } is deprecated; we now treat it as { parser: \\"css\\" }. " diff --git a/tests_integration/__tests__/deprecated-parser.js b/tests_integration/__tests__/deprecated-parser.js index 5c305d8c6..71c961eb2 100644 --- a/tests_integration/__tests__/deprecated-parser.js +++ b/tests_integration/__tests__/deprecated-parser.js @@ -25,9 +25,13 @@ test("API format with deprecated parser (postcss) should work", () => { expect(warnings).toMatchSnapshot(); }); -test("API format with deprecated parser (babylon) should work", () => { - expect(() => - prettier.format("hello_world( )", { parser: "babylon" }) - ).not.toThrowError(); - expect(warnings).toMatchSnapshot(); +test("API format with deprecated parser (babylon) should work and do not report the same deprecation warning more than once", () => { + expect(() => { + prettier.format("hello_world( )", { parser: "babylon" }); + prettier.format("hello_world( )", { parser: "babylon" }); + }).not.toThrowError(); + expect(warnings).toMatchInlineSnapshot(` +"{ parser: \\"babylon\\" } is deprecated; we now treat it as { parser: \\"babel\\" }. +" +`); });