Skip to content

Commit

Permalink
test(require-param): add test limiting function to those with @param
Browse files Browse the repository at this point in the history
Also:
- test(`match-name`): make non-matching Jsdoc AST pattern more realistic
  • Loading branch information
brettz9 committed Oct 22, 2022
1 parent 87c1c2a commit 64b1ead
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8012,7 +8012,7 @@ class A {
* @property opt_a
* @param {Foo|Bar} opt_b
*/
// "jsdoc/match-name": ["error"|"warn", {"match":[{"comment":"JsdocBlock > JsdocTag[tag=\"param\"] > JsdocTypeUnion[left.name=\"Bar\"]","disallowName":"/^opt_/i"}]}]
// "jsdoc/match-name": ["error"|"warn", {"match":[{"comment":"JsdocBlock:has(JsdocTag[tag=\"param\"]:has(JsdocTypeUnion:has(JsdocTypeName[value=\"Bar\"]:nth-child(1))))","disallowName":"/^opt_/i"}]}]
````


Expand Down Expand Up @@ -16264,6 +16264,14 @@ export function testFn1 ({ prop = { a: 1, b: 2 } }) {
/** Foo. */
function foo(a, b, c) {}
// Message: Missing JSDoc @param "a" declaration.

/**
* @param foo Some number.
* @param bar Some number.
*/
export function myPublicFunction(foo: number, bar: number, baz: number) {}
// "jsdoc/require-param": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:has(JsdocTag[tag=\"param\"])","context":"FunctionDeclaration"}]}]
// Message: Missing JSDoc @param "baz" declaration.
````

The following patterns are not considered problems:
Expand Down
2 changes: 1 addition & 1 deletion test/rules/assertions/matchName.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ export default {
{
match: [
{
comment: 'JsdocBlock > JsdocTag[tag="param"] > JsdocTypeUnion[left.name="Bar"]',
comment: 'JsdocBlock:has(JsdocTag[tag="param"]:has(JsdocTypeUnion:has(JsdocTypeName[value="Bar"]:nth-child(1))))',
disallowName: '/^opt_/i',
},
],
Expand Down
33 changes: 33 additions & 0 deletions test/rules/assertions/requireParam.js
Original file line number Diff line number Diff line change
Expand Up @@ -2375,6 +2375,39 @@ export default {
function foo(a, b, c) {}
`,
},
{
code: `
/**
* @param foo Some number.
* @param bar Some number.
*/
export function myPublicFunction(foo: number, bar: number, baz: number) {}
`,
errors: [
{
message: 'Missing JSDoc @param "baz" declaration.',
},
],
options: [
{
contexts: [
{
comment: 'JsdocBlock:has(JsdocTag[tag="param"])',
context: 'FunctionDeclaration',
},
],
},
],
output: `
/**
* @param foo Some number.
* @param bar Some number.
* @param baz
*/
export function myPublicFunction(foo: number, bar: number, baz: number) {}
`,
parser: require.resolve('@typescript-eslint/parser'),
},
],
valid: [
{
Expand Down

0 comments on commit 64b1ead

Please sign in to comment.