Skip to content

Commit

Permalink
fix: sort params order without name
Browse files Browse the repository at this point in the history
  • Loading branch information
hosseinmd committed Feb 13, 2021
1 parent b17e982 commit 5da7a26
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,13 @@ export const getParser = (parser: Parser["parse"]) =>
a.tag === PARAM &&
b.tag === PARAM
) {
//sort params
return paramsOrder.indexOf(a.name) - paramsOrder.indexOf(b.name);
const aIndex = paramsOrder.indexOf(a.name);
const bIndex = paramsOrder.indexOf(b.name);
if (aIndex > -1 && bIndex > -1) {
//sort params
return aIndex - bIndex;
}
return 0;
}
return getTagOrderWeight(a.tag) - getTagOrderWeight(b.tag);
});
Expand Down
16 changes: 16 additions & 0 deletions tests/__snapshots__/main.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,22 @@ const fun = (param0: () => {}, param1: number, param2) => {
"
`;

exports[`param order 2`] = `
"/**
* @param {string} a - A for foo.
* @param {object} c - Options.
* @param {object} opts - Options.
* @param {string} opts.b - Option b.
* @param {string} v - Option b.
* @param {string} opt2 - Option b.
*/
const foo = (a, c, { b }, v, opt2) => {
console.log(a, v, c, b);
};
foo(\\"a\\", { b: \\"b\\" });
"
`;

exports[`since 1`] = `
"/** @since 3.16.0 */
"
Expand Down
23 changes: 23 additions & 0 deletions tests/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,4 +525,27 @@ async subDomain(subDomainAddress2,subDomainAddress) {
`);

expect(result).toMatchSnapshot();

const result2 = subject(
`
/**
* @param {object} c - Options.
* @param {string} a - A for foo.
* @param {object} opts - Options.
* @param {string} opts.b - Option b.
* @param {string} opt2 - Option b.
* @param {string} v - Option b.
*/
const foo = (a,c, { b }, v, opt2) => {
console.log(a,v,c, b);
};
foo('a', { b: 'b' });
`,
{
jsdocVerticalAlignment: true,
},
);

expect(result2).toMatchSnapshot();
});

0 comments on commit 5da7a26

Please sign in to comment.