Skip to content

Commit

Permalink
fix(check-access) ensures rule is still checked when a private ta…
Browse files Browse the repository at this point in the history
…g is present despite even a `true` `ignorePrivate` setting.

Also adds tests for `ignorePrivate` in another `iterateAllJsdocs` rule (`check-alignment`).
  • Loading branch information
brettz9 committed Dec 28, 2019
1 parent 9703aba commit 47198cb
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .README/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ supplied as the second argument in an array after the error level.
### Allow `@private` to disable rules for that comment block

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

### Mode

Expand Down
50 changes: 49 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ supplied as the second argument in an array after the error level.
### Allow <code>@private</code> to disable rules for that comment block

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

<a name="eslint-plugin-jsdoc-settings-mode"></a>
### Mode
Expand Down Expand Up @@ -406,6 +408,15 @@ function quux (foo) {
}
// Message: Missing valid JSDoc @access level.

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

}
// Settings: {"jsdoc":{"ignorePrivate":true}}
// Message: Missing valid JSDoc @access level.

/**
* @accessLevel foo
*/
Expand Down Expand Up @@ -450,6 +461,16 @@ function quux (foo) {
}
// Message: At most one access-control tag may be present on a jsdoc block.

/**
* @access public
* @access private
*/
function quux (foo) {

}
// Settings: {"jsdoc":{"ignorePrivate":true}}
// Message: At most one access-control tag may be present on a jsdoc block.

/**
* @public
* @private
Expand All @@ -459,6 +480,16 @@ function quux (foo) {
}
// Message: At most one access-control tag may be present on a jsdoc block.

/**
* @public
* @private
*/
function quux (foo) {

}
// Settings: {"jsdoc":{"ignorePrivate":true}}
// Message: At most one access-control tag may be present on a jsdoc block.

/**
* @public
* @public
Expand Down Expand Up @@ -507,6 +538,14 @@ class MyClass {
function quux (foo) {

}

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

}
// Settings: {"jsdoc":{"ignorePrivate":true}}
````


Expand Down Expand Up @@ -631,6 +670,15 @@ function quux (foo) {
* So this is unchecked.
*/
function quux (foo) {}

/**
* @param {Number} foo
* @private
*/
function quux (foo) {
// with spaces
}
// Settings: {"jsdoc":{"ignorePrivate":true}}
````


Expand Down
6 changes: 2 additions & 4 deletions src/iterateJsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ const iterate = (

if (
settings.ignorePrivate &&
!ruleConfig.checkPrivate &&
utils.hasTag('private')
) {
return;
Expand Down Expand Up @@ -529,10 +530,7 @@ export default function iterateJsdoc (iterator, ruleConfig) {
}

if (ruleConfig.iterateAllJsdocs) {
return iterateAllJsdocs(iterator, {
meta: ruleConfig.meta,
noTrim: ruleConfig.noTrim,
});
return iterateAllJsdocs(iterator, ruleConfig);
}

return {
Expand Down
1 change: 1 addition & 0 deletions src/rules/checkAccess.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default iterateJsdoc(({
);
}
}, {
checkPrivate: true,
iterateAllJsdocs: true,
meta: {
type: 'suggestion',
Expand Down
78 changes: 78 additions & 0 deletions test/rules/assertions/checkAccess.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@ export default {
},
],
},
{
code: `
/**
* @access foo
*/
function quux (foo) {
}
`,
errors: [
{
line: 3,
message: 'Missing valid JSDoc @access level.',
},
],
settings: {
jsdoc: {
ignorePrivate: true,
},
},
},
{
code: `
/**
Expand Down Expand Up @@ -110,6 +131,43 @@ export default {
},
],
},
{
code: `
/**
* @access public
* @access private
*/
function quux (foo) {
}
`,
errors: [
{
message: 'At most one access-control tag may be present on a jsdoc block.',
},
],
settings: {
jsdoc: {
ignorePrivate: true,
},
},
},
{
code: `
/**
* @public
* @private
*/
function quux (foo) {
}
`,
errors: [
{
message: 'At most one access-control tag may be present on a jsdoc block.',
},
],
},
{
code: `
/**
Expand All @@ -125,6 +183,11 @@ export default {
message: 'At most one access-control tag may be present on a jsdoc block.',
},
],
settings: {
jsdoc: {
ignorePrivate: true,
},
},
},
{
code: `
Expand Down Expand Up @@ -202,5 +265,20 @@ export default {
}
`,
},
{
code: `
/**
* @private
*/
function quux (foo) {
}
`,
settings: {
jsdoc: {
ignorePrivate: true,
},
},
},
],
};
16 changes: 16 additions & 0 deletions test/rules/assertions/checkAlignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,5 +260,21 @@ function quux (foo) {
function quux (foo) {}
`,
},
{
code: `
/**
* @param {Number} foo
* @private
*/
function quux (foo) {
// with spaces
}
`,
settings: {
jsdoc: {
ignorePrivate: true,
},
},
},
],
};

0 comments on commit 47198cb

Please sign in to comment.