From 3c2df88e6d21bbc33ebd60ade7b23492fbac4f2a Mon Sep 17 00:00:00 2001 From: Hossein Mohammadi Date: Wed, 30 Mar 2022 22:14:57 +0430 Subject: [PATCH] fix: jsdocParser option issue: https://github.com/hosseinmd/prettier-plugin-jsdoc/issues/157 --- src/index.ts | 9 +++++ src/types.ts | 1 + tests/__snapshots__/default.test.ts.snap | 19 +++++++++++ tests/__snapshots__/descriptions.test.ts.snap | 13 +++++++ .../jsdocParserDisable.test.ts.snap | 2 +- tests/default.test.ts | 34 +++++++++++++++++++ tests/descriptions.test.ts | 17 +++++++++- tests/jsdocParserDisable.test.ts | 21 +++++++++++- 8 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 tests/__snapshots__/default.test.ts.snap create mode 100755 tests/default.test.ts diff --git a/src/index.ts b/src/index.ts index e787821..6254535 100755 --- a/src/index.ts +++ b/src/index.ts @@ -7,6 +7,14 @@ import { JsdocOptions } from "./types"; import { findPluginByParser } from "./utils"; const options: Record = { + jsdocParser: { + since: "0.3.24", + name: "jsdocParser", + type: "boolean", + category: "jsdoc", + default: true, + description: "Enable/Disable jsdoc parser", + }, jsdocSpaces: { since: "0.3.24", name: "jsdocSpaces", @@ -116,6 +124,7 @@ const options: Record = { }; const defaultOptions: JsdocOptions = { + jsdocParser: options.jsdocParser.default as boolean, jsdocSpaces: options.jsdocSpaces.default as number, jsdocPrintWidth: options.jsdocPrintWidth.default as unknown as undefined, jsdocDescriptionWithDot: options.jsdocDescriptionWithDot.default as boolean, diff --git a/src/types.ts b/src/types.ts index 22a26a1..ac4c94b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,6 +1,7 @@ import { ParserOptions } from "prettier"; export interface JsdocOptions { + jsdocParser: boolean; jsdocSpaces: number; jsdocPrintWidth?: number; jsdocDescriptionWithDot: boolean; diff --git a/tests/__snapshots__/default.test.ts.snap b/tests/__snapshots__/default.test.ts.snap new file mode 100644 index 0000000..245a88a --- /dev/null +++ b/tests/__snapshots__/default.test.ts.snap @@ -0,0 +1,19 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Empty default 1`] = ` +"/** + * The value + * + * @default 'type' name description + */ +" +`; + +exports[`Empty default 2`] = ` +"/** + * The value + * + * @default + */ +" +`; diff --git a/tests/__snapshots__/descriptions.test.ts.snap b/tests/__snapshots__/descriptions.test.ts.snap index 7ef3959..7332adc 100644 --- a/tests/__snapshots__/descriptions.test.ts.snap +++ b/tests/__snapshots__/descriptions.test.ts.snap @@ -199,6 +199,19 @@ exports[`Jsx tsx css 1`] = ` " `; +exports[`Link 1`] = ` +"/** + * Name of something. + * + * See [documentation](1) for more details. + * + * # 1 + * + * https://www.documentation.com + */ +" +`; + exports[`List in tags 1`] = ` "/** * @param {any} var An example list: diff --git a/tests/__snapshots__/jsdocParserDisable.test.ts.snap b/tests/__snapshots__/jsdocParserDisable.test.ts.snap index 5df4e0d..d17b5b8 100644 --- a/tests/__snapshots__/jsdocParserDisable.test.ts.snap +++ b/tests/__snapshots__/jsdocParserDisable.test.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`extends 1`] = ` +exports[`disabled complex object typedef 1`] = ` "/** * The bread crumbs indicate the navigate path and trigger the active page. * @class diff --git a/tests/default.test.ts b/tests/default.test.ts new file mode 100755 index 0000000..5fc3c9f --- /dev/null +++ b/tests/default.test.ts @@ -0,0 +1,34 @@ +import prettier from "prettier"; +import { AllOptions } from "../src/types"; + +function subject(code: string, options: Partial = {}) { + return prettier.format(code, { + parser: "babel", + plugins: ["."], + jsdocSpaces: 1, + ...options, + } as AllOptions); +} + +test("Empty default", () => { + const result = subject(` + /** + * The value + * + * @default 'type' name description + */ +`); + + expect(result).toMatchSnapshot(); +}); +test("Empty default", () => { + const result = subject(` + /** + * The value + * + * @default [] + */ +`); + + expect(result).toMatchSnapshot(); +}); diff --git a/tests/descriptions.test.ts b/tests/descriptions.test.ts index a7ba766..237056e 100644 --- a/tests/descriptions.test.ts +++ b/tests/descriptions.test.ts @@ -524,7 +524,7 @@ test("matches prettier markdown format", () => { ); expect(result1).toMatchSnapshot(); -}) +}); test("description start underscores", () => { const result1 = subject( @@ -988,3 +988,18 @@ test("Code in description", () => { expect(result5).toMatchSnapshot(); }); + +test("Link ", () => { + const result = subject(` + /** + * Name of something. + * + * See [documentation](1) for more details. + * + * # 1 + * https://www.documentation.com + */ +`); + + expect(result).toMatchSnapshot(); +}); diff --git a/tests/jsdocParserDisable.test.ts b/tests/jsdocParserDisable.test.ts index 10ff014..dd7628b 100644 --- a/tests/jsdocParserDisable.test.ts +++ b/tests/jsdocParserDisable.test.ts @@ -23,7 +23,7 @@ test("template for callback", () => { expect(result).toMatchSnapshot(); }); -test("extends", () => { +test("disabled complex object typedef ", () => { const result = subject(` /** * The bread crumbs indicate the navigate path and trigger the active page. @@ -36,4 +36,23 @@ test("extends", () => { `); expect(result).toMatchSnapshot(); + + const result2 = subject( + ` + /** + * The bread crumbs indicate the navigate path and trigger the active page. + * @class + * @typedef {object} props + * @prop {any} navigation + * @extends {PureComponent< props>} + */ + export class BreadCrumbs extends PureComponent {} + `, + { + plugins: ["prettier-plugin-jsdoc"], + jsdocParser: false, + }, + ); + + expect(result).toBe(result2); });