Skip to content

Commit

Permalink
checkRedundantAccess: fixed false-positive reporting for unknown access
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexej Yaroshevich committed Feb 17, 2015
1 parent a69a2f9 commit 0b8f5a7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 23 deletions.
50 changes: 27 additions & 23 deletions lib/rules/validate-jsdoc/check-redundant-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,33 @@ function checkRedundantAccess(node, err) {
access = tag.id === 'access' ? tag.name.value : tag.id;
});

if (access !== 'public' && (enforceLeadingUnderscore || enforceTrailingUnderscore)) {
// fetch name from variable, property or function
var name;
var nameLocation;
switch (node.parentNode.type) {
case 'VariableDeclarator':
name = node.parentNode.id.name;
nameLocation = node.parentNode.id.loc;
break;
case 'Property':
name = node.parentNode.key.name;
nameLocation = node.parentNode.key.loc;
break;
default: // try to use func name itself (if not anonymous)
name = (node.id || {}).name;
nameLocation = (node.id || {}).loc;
break;
}
// skip unknown and don't check if no forcing
if (typeof access === 'undefined' || access === 'public' ||
!(enforceLeadingUnderscore || enforceTrailingUnderscore)) {
return;
}

// skip anonymous and names without underscores at begin
if (name && name[enforceLeadingUnderscore ? 0 : (name.length - 1)] !== '_') {
err('Missing ' + (enforceLeadingUnderscore ? 'leading' : 'trailing') +
' underscore for ' + name, (nameLocation || node.loc).start);
}
// fetch name from variable, property or function
var name;
var nameLocation;
switch (node.parentNode.type) {
case 'VariableDeclarator':
name = node.parentNode.id.name;
nameLocation = node.parentNode.id.loc;
break;
case 'Property':
name = node.parentNode.key.name;
nameLocation = node.parentNode.key.loc;
break;
default: // try to use func name itself (if not anonymous)
name = (node.id || {}).name;
nameLocation = (node.id || {}).loc;
break;
}

// skip anonymous and names without underscores at begin
if (name && name[enforceLeadingUnderscore ? 0 : (name.length - 1)] !== '_') {
err('Missing ' + (enforceLeadingUnderscore ? 'leading' : 'trailing') +
' underscore for ' + name, (nameLocation || node.loc).start);
}
}
9 changes: 9 additions & 0 deletions test/lib/rules/validate-jsdoc/check-redundant-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ describe('lib/rules/validate-jsdoc/check-redundant-access', function () {
line: 4, column: 9, filename: 'input', rule: 'jsDoc',
message: 'Missing leading underscore for funcName'
}]
}, {
it: 'should not force unknown access',
code: function () {
/**
* No access
*/
function funcName(p) {}
},
errors: []
}
/* jshint ignore:end */
]);
Expand Down

0 comments on commit 0b8f5a7

Please sign in to comment.