Skip to content

Commit

Permalink
fix: jsdocParser option
Browse files Browse the repository at this point in the history
issue: #157
  • Loading branch information
hosseinmd committed Mar 30, 2022
1 parent 73cd9db commit 3c2df88
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ import { JsdocOptions } from "./types";
import { findPluginByParser } from "./utils";

const options: Record<keyof JsdocOptions, SupportOption> = {
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",
Expand Down Expand Up @@ -116,6 +124,7 @@ const options: Record<keyof JsdocOptions, SupportOption> = {
};

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,
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ParserOptions } from "prettier";

export interface JsdocOptions {
jsdocParser: boolean;
jsdocSpaces: number;
jsdocPrintWidth?: number;
jsdocDescriptionWithDot: boolean;
Expand Down
19 changes: 19 additions & 0 deletions tests/__snapshots__/default.test.ts.snap
Original file line number Diff line number Diff line change
@@ -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
*/
"
`;
13 changes: 13 additions & 0 deletions tests/__snapshots__/descriptions.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/__snapshots__/jsdocParserDisable.test.ts.snap
Original file line number Diff line number Diff line change
@@ -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
Expand Down
34 changes: 34 additions & 0 deletions tests/default.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import prettier from "prettier";
import { AllOptions } from "../src/types";

function subject(code: string, options: Partial<AllOptions> = {}) {
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();
});
17 changes: 16 additions & 1 deletion tests/descriptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ test("matches prettier markdown format", () => {
);

expect(result1).toMatchSnapshot();
})
});

test("description start underscores", () => {
const result1 = subject(
Expand Down Expand Up @@ -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();
});
21 changes: 20 additions & 1 deletion tests/jsdocParserDisable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
});

0 comments on commit 3c2df88

Please sign in to comment.