-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
some renames, readme update, remove trailingUnderscore, fixes
rename enforce to enforceExistence rename strict to checkRedundantAccess moved out strict of leadingUnderscoreAccess checker upgrade validators interface fixup incorrects in readme
- Loading branch information
Alexej Yaroshevich
committed
Aug 24, 2014
1 parent
487eccd
commit aee2805
Showing
15 changed files
with
300 additions
and
276 deletions.
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
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,34 @@ | ||
module.exports = checkRedundantAccess; | ||
|
||
module.exports.options = { | ||
checkRedundantAccess: {allowedValues: [true]} | ||
}; | ||
|
||
/** | ||
* validator for @access | ||
* @param {(FunctionDeclaration|FunctionExpression)} node | ||
* @param {Function} err | ||
*/ | ||
function checkRedundantAccess(node, err) { | ||
if (!node.jsDoc) { | ||
return; | ||
} | ||
|
||
var access; | ||
node.jsDoc.data.tags.forEach(function (tag) { | ||
if (['private', 'protected', 'public', 'access'].indexOf(tag.tag) === -1) { | ||
return; | ||
} | ||
|
||
if (access) { | ||
err('Multiple access definition'); | ||
return; | ||
} | ||
|
||
if (tag.tag === 'access' && !tag.name) { | ||
err('Invalid access definition'); | ||
} | ||
|
||
access = tag.tag === 'access' ? tag.name : tag.tag || 'unspecified'; | ||
}); | ||
} |
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,16 @@ | ||
module.exports = enforceExistence; | ||
|
||
module.exports.options = { | ||
enforceExistence: {allowedValues: [true]} | ||
}; | ||
|
||
/** | ||
* validator for jsdoc data existance | ||
* @param {(FunctionDeclaration|FunctionExpression)} node | ||
* @param {Function} err | ||
*/ | ||
function enforceExistence(node, err) { | ||
if (!node.jsDoc) { | ||
err('jsdoc definition required', node.loc.start); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,6 +1,67 @@ | ||
module.exports = { | ||
enforce: require('./enforce'), | ||
var assert = require('assert'); | ||
|
||
var validatorsByName = module.exports = { | ||
param: require('./param'), | ||
returns: require('./returns'), | ||
trailingUnderscores: require('./trailing-underscores') | ||
checkRedundantAccess: require('./check-redundant-access'), | ||
enforceExistence: require('./enforce-existence'), | ||
leadingUnderscoreAccess: require('./leading-underscore-access') | ||
}; | ||
|
||
Object.defineProperty(validatorsByName, 'load', { | ||
value: function loadValidators(passedOptions) { | ||
var validators = []; | ||
|
||
if (!passedOptions) { | ||
return validators; | ||
} | ||
|
||
Object.keys(validatorsByName).forEach(function (name) { | ||
var v = validatorsByName[name]; | ||
|
||
// skip unknown | ||
var coveredOptions = v.coveredOptions || (v.options && Object.keys(v.options)); | ||
if (!coveredOptions || !coveredOptions.length) { | ||
return; | ||
} | ||
|
||
// store used | ||
for (var i = 0, l = coveredOptions.length; i < l; i += 1) { | ||
if (passedOptions.indexOf(coveredOptions[i]) !== -1) { | ||
v._name = name; | ||
validators.push(v); | ||
return; | ||
} | ||
} | ||
}); | ||
|
||
return validators; | ||
} | ||
}); | ||
|
||
Object.defineProperty(validatorsByName, 'checkOptions', { | ||
value: function checkOptions(validator, options) { | ||
Object.keys(validator.options).forEach(function (data, option) { | ||
if (!data.allowedValues) { | ||
return; | ||
} | ||
|
||
var values; | ||
if (typeof data.allowedValues === 'function') { | ||
values = data.allowedValues(); | ||
} | ||
|
||
if (!Array.isArray(values)) { | ||
throw new Error('Internal error in jsDoc validator ' + validator._name); | ||
|
||
} else if (values.length > 1) { | ||
assert(values.indexOf(options[option]) !== -1, | ||
'Available values for option jsDoc.' + option + ' are ' + values.map(JSON.stringify).join(', ')); | ||
|
||
} else if (values.length) { | ||
assert(values[0] === options[option], | ||
'Only accepted value for jsDoc.' + option + ' is ' + JSON.stringify(values[0])); | ||
} | ||
}); | ||
} | ||
}); |
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,49 @@ | ||
module.exports = validateLeadingUnderscoresAccess; | ||
|
||
module.exports.options = { | ||
leadingUnderscoreAccess: { | ||
allowedValues: [true, 'private', 'protected'] | ||
} | ||
}; | ||
|
||
/** | ||
* validator for jsdoc data existance | ||
* @param {(FunctionDeclaration|FunctionExpression)} node | ||
* @param {Function} err | ||
*/ | ||
function validateLeadingUnderscoresAccess(node, err) { | ||
var option = this._options.leadingUnderscoreAccess; | ||
if (!node.jsDoc) { | ||
return; | ||
} | ||
|
||
// fetch name from variable, property or function | ||
var name; | ||
switch (node.parentNode.type) { | ||
case 'VariableDeclarator': | ||
name = node.parentNode.id.name; | ||
break; | ||
case 'Property': | ||
name = node.parentNode.key.name; | ||
break; | ||
default: // try to use func name itself (if not anonymous) | ||
name = (node.id||{}).name; | ||
break; | ||
} | ||
|
||
// skip anonymous and names without underscores at begin | ||
if (!name || name[0] !== '_') { | ||
return; | ||
} | ||
|
||
var access; | ||
node.jsDoc.data.tags.forEach(function (tag) { | ||
if (!access && ['private', 'protected', 'public', 'access'].indexOf(tag.tag) !== -1) { | ||
access = (tag.tag === 'access' ? tag.name : tag.tag); | ||
} | ||
}); | ||
|
||
if (!access || [true, access].indexOf(option) === -1) { | ||
err('Method access doesn\'t match'); | ||
} | ||
} |
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
Oops, something went wrong.