Skip to content

Commit

Permalink
feat: add ignoreInternal setting to ignore blocks with @internal
Browse files Browse the repository at this point in the history
…tags; fixes gajus#639

Not applied to `empty-tags` rule
  • Loading branch information
brettz9 committed Sep 25, 2020
1 parent 6d0f351 commit a2f68dd
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 8 deletions.
8 changes: 6 additions & 2 deletions .README/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,16 @@ supplied as the second argument in an array after the error level.

## Settings

### Allow `@private` to disable rules for that comment block
### Allow tags (`@private` or `@internal`) to disable rules for that comment block

- `settings.jsdoc.ignorePrivate` - Disables all rules for the comment block
on which a `@private` tag (or `@access private`) occurs. Defaults to
`false`. Note: This has no effect with the rule `check-access` (whose
purpose is to check access modifiers).
purpose is to check access modifiers) or `empty-tags` (which checks
`@private` itself).
- `settings.jsdoc.ignoreInternal` - Disables all rules for the comment block
on which a `@internal` tag occurs. Defaults to `false`. Note: This has no
effect with the rule `empty-tags` (which checks `@internal` itself).

### `maxLines` and `minLines`

Expand Down
3 changes: 3 additions & 0 deletions .README/rules/empty-tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Note that `@private` will still be checked for content by this rule even with
`settings.jsdoc.ignorePrivate` set to `true` (a setting which normally
causes rules not to take effect).

Similarly, `@internal` will still be checked for content by this rule even with
`settings.jsdoc.ignoreInternal` set to `true`.

#### Options

##### `tags`
Expand Down
38 changes: 34 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ JSDoc linting rules for ESLint.
* [Configuration](#eslint-plugin-jsdoc-configuration)
* [Options](#eslint-plugin-jsdoc-options)
* [Settings](#eslint-plugin-jsdoc-settings)
* [Allow `@private` to disable rules for that comment block](#eslint-plugin-jsdoc-settings-allow-private-to-disable-rules-for-that-comment-block)
* [Allow tags (`@private` or `@internal`) to disable rules for that comment block](#eslint-plugin-jsdoc-settings-allow-tags-private-or-internal-to-disable-rules-for-that-comment-block)
* [`maxLines` and `minLines`](#eslint-plugin-jsdoc-settings-maxlines-and-minlines)
* [Mode](#eslint-plugin-jsdoc-settings-mode)
* [Alias Preference](#eslint-plugin-jsdoc-settings-alias-preference)
Expand Down Expand Up @@ -172,13 +172,17 @@ supplied as the second argument in an array after the error level.
<a name="eslint-plugin-jsdoc-settings"></a>
## Settings

<a name="eslint-plugin-jsdoc-settings-allow-private-to-disable-rules-for-that-comment-block"></a>
### Allow <code>@private</code> to disable rules for that comment block
<a name="eslint-plugin-jsdoc-settings-allow-tags-private-or-internal-to-disable-rules-for-that-comment-block"></a>
### Allow tags (<code>@private</code> or <code>@internal</code>) to disable rules for that comment block

- `settings.jsdoc.ignorePrivate` - Disables all rules for the comment block
on which a `@private` tag (or `@access private`) occurs. Defaults to
`false`. Note: This has no effect with the rule `check-access` (whose
purpose is to check access modifiers).
purpose is to check access modifiers) or `empty-tags` (which checks
`@private` itself).
- `settings.jsdoc.ignoreInternal` - Disables all rules for the comment block
on which a `@internal` tag occurs. Defaults to `false`. Note: This has no
effect with the rule `empty-tags` (which checks `@internal` itself).

<a name="eslint-plugin-jsdoc-settings-maxlines-and-minlines"></a>
### <code>maxLines</code> and <code>minLines</code>
Expand Down Expand Up @@ -5102,6 +5106,9 @@ Note that `@private` will still be checked for content by this rule even with
`settings.jsdoc.ignorePrivate` set to `true` (a setting which normally
causes rules not to take effect).
Similarly, `@internal` will still be checked for content by this rule even with
`settings.jsdoc.ignoreInternal` set to `true`.
<a name="eslint-plugin-jsdoc-rules-empty-tags-options-9"></a>
#### Options
Expand Down Expand Up @@ -5171,6 +5178,14 @@ function quux () {
}
// Message: @private should be empty.
/**
* @internal {someType}
*/
function quux () {
}
// Message: @internal should be empty.
/**
* @private {someType}
*/
Expand Down Expand Up @@ -5227,6 +5242,13 @@ function quux () {
*/
function quux () {
}
/**
* @internal
*/
function quux () {
}
````
Expand Down Expand Up @@ -12340,6 +12362,14 @@ class A {
}
// Settings: {"jsdoc":{"augmentsExtendsReplacesDocs":true}}

/**
* @internal
*/
function quux (foo) {

}
// Settings: {"jsdoc":{"ignoreInternal":true}}

/**
* @private
*/
Expand Down
10 changes: 8 additions & 2 deletions src/iterateJsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ const getSettings = (context) => {
const settings = {
// All rules
ignorePrivate: Boolean(context.settings.jsdoc?.ignorePrivate),
ignoreInternal: Boolean(context.settings.jsdoc?.ignoreInternal),
maxLines: Number(context.settings.jsdoc?.maxLines ?? 1),
minLines: Number(context.settings.jsdoc?.minLines ?? 0),

Expand Down Expand Up @@ -560,8 +561,13 @@ const iterate = (
);

if (
settings.ignorePrivate &&
!ruleConfig.checkPrivate &&
!ruleConfig.checkInternal && settings.ignoreInternal &&
utils.hasTag('internal')
) {
return;
}
if (
!ruleConfig.checkPrivate && settings.ignorePrivate &&
(utils.hasTag('private') || _.filter(jsdoc.tags, {
tag: 'access',
}).some(({description}) => {
Expand Down
4 changes: 4 additions & 0 deletions src/rules/emptyTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const defaultEmptyTags = new Set([
// jsdoc doesn't use this form in its docs, but allow for compatibility with
// TypeScript which allows and Closure which requires
'inheritDoc',

// jsdoc doesn't use but allow for TypeScript
'internal',
]);

const emptyIfNotClosure = new Set([
Expand Down Expand Up @@ -45,6 +48,7 @@ export default iterateJsdoc(({
}
});
}, {
checkInternal: true,
checkPrivate: true,
iterateAllJsdocs: true,
meta: {
Expand Down
34 changes: 34 additions & 0 deletions test/rules/assertions/emptyTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,30 @@ export default {
}
`,
},
{
code: `
/**
* @internal {someType}
*/
function quux () {
}
`,
errors: [
{
line: 3,
message: '@internal should be empty.',
},
],
output: `
/**
* @internal
*/
function quux () {
}
`,
},
{
code: `
/**
Expand Down Expand Up @@ -232,6 +256,16 @@ export default {
*/
function quux () {
}
`,
},
{
code: `
/**
* @internal
*/
function quux () {
}
`,
},
Expand Down
15 changes: 15 additions & 0 deletions test/rules/assertions/requireParam.js
Original file line number Diff line number Diff line change
Expand Up @@ -2593,6 +2593,21 @@ export default {
},
},
},
{
code: `
/**
* @internal
*/
function quux (foo) {
}
`,
settings: {
jsdoc: {
ignoreInternal: true,
},
},
},
{
code: `
/**
Expand Down

0 comments on commit a2f68dd

Please sign in to comment.