-
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add "require-param-name" rule (#50)
* feat(rules): Add "require-param-name" rule * docs(README): Generate README.md
- Loading branch information
Showing
7 changed files
with
173 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
### `require-param-name` | ||
|
||
Requires that all function parameters have name. | ||
|
||
> The `@param` tag requires you to specify the name of the parameter you are documenting. You can also include the parameter's type, enclosed in curly brackets, and a description of the parameter. | ||
> | ||
> [JSDoc](http://usejsdoc.org/tags-param.html#overview) | ||
||| | ||
|---|---| | ||
|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`| | ||
|Tags|`param`| | ||
|
||
<!-- assertions requireParamName --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import _ from 'lodash'; | ||
import iterateJsdoc from '../iterateJsdoc'; | ||
|
||
export default iterateJsdoc(({ | ||
jsdoc, | ||
report, | ||
utils | ||
}) => { | ||
const targetTagName = utils.getPreferredTagName('param'); | ||
|
||
const jsdocParameters = _.filter(jsdoc.tags, { | ||
tag: targetTagName | ||
}); | ||
|
||
_.forEach(jsdocParameters, (jsdocParameter) => { | ||
if (jsdocParameter.tag && jsdocParameter.name === '') { | ||
report('There must be an identifier after @param ' + (jsdocParameter.type === '' ? 'type' : 'tag') + '.'); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* eslint-disable no-restricted-syntax */ | ||
|
||
export default { | ||
invalid: [ | ||
{ | ||
code: ` | ||
/** | ||
* @param | ||
*/ | ||
function quux (foo) { | ||
} | ||
`, | ||
errors: [ | ||
{ | ||
message: 'There must be an identifier after @param type.' | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
/** | ||
* @param {string} | ||
*/ | ||
function quux (foo) { | ||
} | ||
`, | ||
errors: [ | ||
{ | ||
message: 'There must be an identifier after @param tag.' | ||
} | ||
] | ||
} | ||
], | ||
valid: [ | ||
{ | ||
code: ` | ||
/** | ||
* @param foo | ||
*/ | ||
function quux (foo) { | ||
} | ||
` | ||
}, | ||
{ | ||
code: ` | ||
/** | ||
* @param {string} foo | ||
*/ | ||
function quux (foo) { | ||
} | ||
` | ||
} | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters