Skip to content

Commit

Permalink
feat: add jsdocAddDefaultToDescription
Browse files Browse the repository at this point in the history
  • Loading branch information
hosseinmd committed Nov 5, 2021
1 parent e51d0e8 commit c3fb168
Show file tree
Hide file tree
Showing 19 changed files with 83 additions and 2,280 deletions.
7 changes: 6 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ module.exports = {
ecmaVersion: "next",
},
parser: "@typescript-eslint/parser",
extends: ["prettier", "eslint:recommended"],
plugins: ["@typescript-eslint"],
extends: [
"prettier",
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
],
rules: {
"@typescript-eslint/no-explicit-any": "off",
"no-unused-vars": "off",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"devDependencies": {
"@commitlint/config-conventional": "^14.1.0",
"@react-native-community/eslint-config": "^3.0.1",
"@typescript-eslint/eslint-plugin": "^5.3.0",
"@types/jest": "^27.0.2",
"@types/mdast": "^3.0.10",
"@typescript-eslint/parser": "^5.3.0",
Expand Down Expand Up @@ -76,4 +77,4 @@
"engines": {
"node": ">=12.0.0"
}
}
}
2 changes: 1 addition & 1 deletion src/custom.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
declare namespace jest {
interface Matchers<R, T> {
interface Matchers<R> {
toMatchSpecificSnapshot(filename: string): R;
}
}
10 changes: 10 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ const options: Record<keyof JsdocOptions, SupportOption> = {
description:
"If You don't set value to jsdocPrintWidth, the printWidth will be use as jsdocPrintWidth.",
},
jsdocAddDefaultToDescription: {
since: "0.3.29",
name: "jsdocAddDefaultToDescription",
type: "boolean",
category: "jsdoc",
default: true,
description: "Add Default value of a param to end description",
},
};

const defaultOptions: JsdocOptions = {
Expand All @@ -113,6 +121,8 @@ const defaultOptions: JsdocOptions = {
jsdocSeparateTagGroups: options.jsdocSeparateTagGroups.default as boolean,
jsdocCapitalizeDescription: options.jsdocCapitalizeDescription
.default as boolean,
jsdocAddDefaultToDescription: options.jsdocAddDefaultToDescription
.default as boolean,
tsdoc: options.tsdoc.default as boolean,
};

Expand Down
9 changes: 5 additions & 4 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@ export const getParser = (originalParse: Parser["parse"], parserName: string) =>
return [tag];
});
}
if (options.jsdocAddDefaultToDescription) {
tags = tags.map(addDefaultValueToDescription);
}

tags = tags
.map(addDefaultValueToDescription)
.map(assignOptionalAndDefaultToName)
.map(({ type, name, description, tag, ...rest }) => {
const isVerticallyAlignAbleTags =
Expand Down Expand Up @@ -415,7 +417,6 @@ function convertCommentDescToDescTag(parsed: Block): void {
* This is for find params of function name in code as strings of array
*/
function getParamsOrders(ast: AST, tokenIndex: number): string[] | undefined {
let paramsOrder: string[] | undefined;
let params: Token[] | undefined;

try {
Expand Down Expand Up @@ -476,14 +477,14 @@ function getParamsOrders(ast: AST, tokenIndex: number): string[] | undefined {
}
}

paramsOrder = params
return params
?.filter(({ type }) => typeof type === "object" && type.label === "name")
.map(({ value }) => value);
} catch {
//
}

return paramsOrder;
return;
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface JsdocOptions {
jsdocSingleLineComment: boolean;
jsdocSeparateReturnsFromParam: boolean;
jsdocSeparateTagGroups: boolean;
jsdocAddDefaultToDescription: boolean;
jsdocCapitalizeDescription: boolean;
tsdoc: boolean;
}
Expand Down
46 changes: 0 additions & 46 deletions tests/__snapshots__/files/create-ignorer.js.shot
Original file line number Diff line number Diff line change
Expand Up @@ -45,49 +45,3 @@ function _createIgnorer(ignoreContent, withNodeModules) {
module.exports = createIgnorer;
"
`;

exports[`File: create-ignorer.js index: 5 1`] = `
"\\"use strict\\";

const path = require(\\"path\\");
const ignore = require(\\"ignore\\");
const getFileContentOrNull = require(\\"../utils/get-file-content-or-null\\");

/**
* @param {string | null} ignorePath
* @param {boolean | null} withNodeModules
*/
async function createIgnorer(ignorePath, withNodeModules) {
const ignoreContent = ignorePath
? await getFileContentOrNull(path.resolve(ignorePath))
: null;

return _createIgnorer(ignoreContent, withNodeModules);
}

/**
* @param {string | null} ignorePath
* @param {boolean | null} withNodeModules
*/
createIgnorer.sync = function (ignorePath, withNodeModules) {
const ignoreContent = !ignorePath
? null
: getFileContentOrNull.sync(path.resolve(ignorePath));
return _createIgnorer(ignoreContent, withNodeModules);
};

/**
* @param {null | string} ignoreContent
* @param {boolean | null} withNodeModules
*/
function _createIgnorer(ignoreContent, withNodeModules) {
const ignorer = ignore().add(ignoreContent || \\"\\");
if (!withNodeModules) {
ignorer.add(\\"node_modules\\");
}
return ignorer;
}

module.exports = createIgnorer;
"
`;
19 changes: 0 additions & 19 deletions tests/__snapshots__/files/order.jsx.shot
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,3 @@ exports[`File: order.jsx 1`] = `
*/
"
`;

exports[`File: order.jsx index: 4 1`] = `
"/**
* @callback ClassMapper
* @param {string} className
* @param {string} language
* @returns {string}
*
* @callback ClassAdder
* @param {ClassAdderEnvironment} env
* @returns {undefined | string | string[]}
*
* @typedef ClassAdderEnvironment
* @property {string} language
* @property {string} type
* @property {string} content
*/
"
`;

0 comments on commit c3fb168

Please sign in to comment.