-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(
check-access
): add rule to check access levels
BREAKING CHANGE: New rule updates `recommended` Checks `@access` for allowed values and prohibits multiple access modifier tags on the same block
- Loading branch information
Showing
8 changed files
with
409 additions
and
1 deletion.
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,21 @@ | ||
### `check-access` | ||
|
||
Checks that `@access` tags use one of the following values: | ||
|
||
- "package", "private", "protected", "public" | ||
|
||
Also reports: | ||
|
||
- Mixing of `@access` with `@public`, `@private`, `@protected`, or `@package` | ||
on the same doc block. | ||
- Use of multiple instances of `@access` (or the `@public`, etc. style tags) | ||
on the same doc block. | ||
|
||
||| | ||
|---|---| | ||
|Context|everywhere| | ||
|Tags|`@access`| | ||
|Settings|| | ||
|Options|| | ||
|
||
<!-- assertions checkAccess --> |
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
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,39 @@ | ||
import iterateJsdoc from '../iterateJsdoc'; | ||
|
||
const accessLevels = ['package', 'private', 'protected', 'public']; | ||
|
||
export default iterateJsdoc(({ | ||
report, | ||
utils, | ||
}) => { | ||
utils.forEachPreferredTag('access', (jsdocParameter, targetTagName) => { | ||
const desc = targetTagName === 'access' ? | ||
jsdocParameter.description : | ||
jsdocParameter.name + ' ' + jsdocParameter.description; | ||
|
||
if (!accessLevels.includes(desc.trim())) { | ||
report( | ||
`Missing valid JSDoc @${targetTagName} level.`, | ||
null, | ||
jsdocParameter, | ||
); | ||
} | ||
}); | ||
const accessLength = utils.getTags('access').length; | ||
const individualTagLength = utils.getPresentTags(accessLevels).length; | ||
if (accessLength && individualTagLength) { | ||
report( | ||
'The @access tag may not be used with specific access-control tags (@package, @private, @protected, or @public).', | ||
); | ||
} | ||
if (accessLength > 1 || individualTagLength > 1) { | ||
report( | ||
'At most one access-control tag may be present on a jsdoc block.', | ||
); | ||
} | ||
}, { | ||
iterateAllJsdocs: true, | ||
meta: { | ||
type: 'suggestion', | ||
}, | ||
}); |
Oops, something went wrong.