Skip to content

Commit 0b8f5a7

Browse files
author
Alexej Yaroshevich
committed
checkRedundantAccess: fixed false-positive reporting for unknown access
1 parent a69a2f9 commit 0b8f5a7

File tree

2 files changed

+36
-23
lines changed

2 files changed

+36
-23
lines changed

lib/rules/validate-jsdoc/check-redundant-access.js

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,33 @@ function checkRedundantAccess(node, err) {
3131
access = tag.id === 'access' ? tag.name.value : tag.id;
3232
});
3333

34-
if (access !== 'public' && (enforceLeadingUnderscore || enforceTrailingUnderscore)) {
35-
// fetch name from variable, property or function
36-
var name;
37-
var nameLocation;
38-
switch (node.parentNode.type) {
39-
case 'VariableDeclarator':
40-
name = node.parentNode.id.name;
41-
nameLocation = node.parentNode.id.loc;
42-
break;
43-
case 'Property':
44-
name = node.parentNode.key.name;
45-
nameLocation = node.parentNode.key.loc;
46-
break;
47-
default: // try to use func name itself (if not anonymous)
48-
name = (node.id || {}).name;
49-
nameLocation = (node.id || {}).loc;
50-
break;
51-
}
34+
// skip unknown and don't check if no forcing
35+
if (typeof access === 'undefined' || access === 'public' ||
36+
!(enforceLeadingUnderscore || enforceTrailingUnderscore)) {
37+
return;
38+
}
5239

53-
// skip anonymous and names without underscores at begin
54-
if (name && name[enforceLeadingUnderscore ? 0 : (name.length - 1)] !== '_') {
55-
err('Missing ' + (enforceLeadingUnderscore ? 'leading' : 'trailing') +
56-
' underscore for ' + name, (nameLocation || node.loc).start);
57-
}
40+
// fetch name from variable, property or function
41+
var name;
42+
var nameLocation;
43+
switch (node.parentNode.type) {
44+
case 'VariableDeclarator':
45+
name = node.parentNode.id.name;
46+
nameLocation = node.parentNode.id.loc;
47+
break;
48+
case 'Property':
49+
name = node.parentNode.key.name;
50+
nameLocation = node.parentNode.key.loc;
51+
break;
52+
default: // try to use func name itself (if not anonymous)
53+
name = (node.id || {}).name;
54+
nameLocation = (node.id || {}).loc;
55+
break;
56+
}
57+
58+
// skip anonymous and names without underscores at begin
59+
if (name && name[enforceLeadingUnderscore ? 0 : (name.length - 1)] !== '_') {
60+
err('Missing ' + (enforceLeadingUnderscore ? 'leading' : 'trailing') +
61+
' underscore for ' + name, (nameLocation || node.loc).start);
5862
}
5963
}

test/lib/rules/validate-jsdoc/check-redundant-access.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ describe('lib/rules/validate-jsdoc/check-redundant-access', function () {
107107
line: 4, column: 9, filename: 'input', rule: 'jsDoc',
108108
message: 'Missing leading underscore for funcName'
109109
}]
110+
}, {
111+
it: 'should not force unknown access',
112+
code: function () {
113+
/**
114+
* No access
115+
*/
116+
function funcName(p) {}
117+
},
118+
errors: []
110119
}
111120
/* jshint ignore:end */
112121
]);

0 commit comments

Comments
 (0)