Skip to content

Commit

Permalink
jscsrc: add requireNewlineAfterDescription rule
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexej Yaroshevich committed May 3, 2015
1 parent 3bb3c22 commit 0f3a308
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .jscsrc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"checkRedundantReturns": true,
"requireReturnTypes": true,
"checkTypes": "strictNativeCase",
"checkRedundantAccess": true
"checkRedundantAccess": true,
"requireNewlineAfterDescription": true
}
}
1 change: 1 addition & 0 deletions lib/esprima-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var scopeNodeTypes = [

/**
* Search for the closest scope node tree for Node
*
* @param {{type: string}} n
* @returns {EsprimaNode}
*/
Expand Down
12 changes: 11 additions & 1 deletion lib/jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module.exports = {

/**
* jsdoc comment object
*
* @param {string} value
* @param {{start: DocLocation}} loc
* @constructor
Expand Down Expand Up @@ -103,6 +104,7 @@ function DocComment(value, loc) {

/**
* Simple jsdoc tag object
*
* @param {Object} tag object from comment parser, fields: tag, line, value, name, type, description
* @param {DocLocation} loc
* @constructor
Expand Down Expand Up @@ -133,6 +135,7 @@ function DocTag(tag, loc) {

/**
* Parses jsdoctype string and provides several methods to work with it
*
* @param {string} type
* @param {DocLocation} loc
* @constructor
Expand All @@ -156,7 +159,8 @@ function DocType(type, loc) {
}

/**
* match type
* Match type
*
* @param {EsprimaNode} node
* @returns {boolean}
*/
Expand All @@ -178,6 +182,7 @@ function DocType(type, loc) {

/**
* DocLocation
*
* @constructor
* @param {number} line
* @param {number} column
Expand All @@ -193,6 +198,7 @@ function DocLocation(line, column, rel) {

/**
* Shift location by line and column
*
* @param {number|Object} line
* @param {number} [column]
* @returns {DocLocation}
Expand All @@ -207,6 +213,7 @@ DocLocation.prototype.shift = function(line, column) {

/**
* Comment parsing helper
*
* @param {string} comment
* @returns {Object}
* @private
Expand All @@ -229,6 +236,7 @@ function _parseComment(comment) {

/**
* analogue of str.match(/@(\S+)(?:\s+\{([^\}]+)\})?(?:\s+(\S+))?(?:\s+([^$]+))?/);
*
* @param {string} str raw jsdoc string
* @returns {?Object} parsed tag node
*/
Expand Down Expand Up @@ -444,6 +452,7 @@ function _iterateDocTypes(node, cb) {

/**
* Converts AST jsDoc node to simple object
*
* @param {Object} node
* @returns {!Array.<SimplifiedType>}
* @see https://github.com/Kuniwak/jsdoctypeparser
Expand All @@ -463,6 +472,7 @@ var jsPrimitives = 'string number boolean null undefined Object Function Array D

/**
* Compare parsed jsDocTypes with esprima node
*
* @param {SimplifiedType[]} variants - result of jsDocParseType
* @param {Object} argument - esprima source code node
*/
Expand Down
12 changes: 10 additions & 2 deletions lib/rules/validate-jsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var validators = require('./validate-jsdoc/index');

/**
* Rule constructor
*
* @this {module:jscs/Rule}
* @constructor
*/
Expand All @@ -15,6 +16,7 @@ module.exports.prototype = {

/**
* Load all rules and init them
*
* @param {Object} options
* @throws {Error} If options is not an Object
*/
Expand Down Expand Up @@ -137,7 +139,8 @@ module.exports.prototype = {
});

/**
* send error to jscs
* Send error to jscs
*
* @param {string} text
* @param {number|DocLocation} relLine
* @param {number} [relColumn]
Expand All @@ -157,6 +160,7 @@ module.exports.prototype = {

/**
* Generates function with location fixing logic to send error to jscs
*
* @param {function(string, number|Object, ?number)} err
* @param {DocTag} tag
* @returns {function(string, number|Object, ?number)}
Expand All @@ -175,7 +179,8 @@ module.exports.prototype = {
},

/**
* caching scope search. todo: move to patchNodesInFile
* Caching scope search. todo: move to patchNodesInFile
*
* @param {Object} node
*/
_getReturnStatementsForNode: function(node) {
Expand All @@ -199,6 +204,7 @@ module.exports.prototype = {

/**
* Extends each node with helper properties
*
* @param {Object} file
*/
function patchNodesInFile(file) {
Expand All @@ -218,6 +224,7 @@ function patchNodesInFile(file) {

/**
* Fetchs jsdoc block for this
*
* @this {module:esprima/Node}
* @returns {DocComment}
*/
Expand All @@ -231,6 +238,7 @@ function patchNodesInFile(file) {

/**
* Finds DocComment in file before passed line number
*
* @param {number} line
* @returns {?module:esprima/Node}
*/
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/validate-jsdoc/check-annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ validateAnnotations.configure = function(options) {
};

/**
* validator for annotations
* Validator for annotations
*
* @param {JSCS.JSFile} file
* @param {JSCS.Errors} errors
*/
Expand Down
6 changes: 4 additions & 2 deletions lib/rules/validate-jsdoc/check-param-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module.exports.options = {
};

/**
* validator for check-param-names
* Validator for check-param-names
*
* @param {(FunctionDeclaration|FunctionExpression)} node
* @param {Function} err
*/
Expand All @@ -31,7 +32,8 @@ function validateCheckParamNames(node, err) {

node.jsdoc.iterateByType(['param', 'arg', 'argument'],
/**
* tag checker
* Tag checker
*
* @param {DocType} tag
* @param {number} i index
*/
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/validate-jsdoc/check-redundant-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module.exports.options = {
};

/**
* validator for @access
* Validator for @access
*
* @param {(FunctionDeclaration|FunctionExpression)} node
* @param {Function} err
*/
Expand Down
6 changes: 4 additions & 2 deletions lib/rules/validate-jsdoc/check-redundant-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module.exports.options = {
};

/**
* validator for check-param-names
* Validator for check-param-names
*
* @param {(FunctionDeclaration|FunctionExpression)} node
* @param {Function} err
*/
Expand All @@ -18,7 +19,8 @@ function validateCheckParamNames(node, err) {

node.jsdoc.iterateByType(['param', 'arg', 'argument'],
/**
* tag checker
* Tag checker
*
* @param {DocType} tag
* @param {number} i index
*/
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/validate-jsdoc/check-redundant-returns.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module.exports.options = {
};

/**
* checking returns types
* Checking returns types
*
* @param {(FunctionDeclaration|FunctionExpression)} node
* @param {DocTag} tag
* @param {Function} err
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/validate-jsdoc/check-return-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module.exports.options = {
};

/**
* checking returns types
* Checking returns types
*
* @param {(FunctionDeclaration|FunctionExpression)} node
* @param {DocTag} tag
* @param {Function} err
Expand Down
5 changes: 3 additions & 2 deletions lib/rules/validate-jsdoc/check-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ var strictNatives = {
};

/**
* validator for types in tags
* Validator for types in tags
*
* @param {JSCS.JSFile} file
* @param {JSCS.Errors} errors
*/
Expand Down Expand Up @@ -91,10 +92,10 @@ function validateTypesInTags(file, errors) {
// is native?
var type = node.typeName;
var lowerType = type.toLowerCase();
//console.log(capitalizedNativeCase, type, lowerType, strictNatives.hasOwnProperty(type));
if (!strictNatives.hasOwnProperty(lowerType)) {
return;
}

var normType = strictNatives[lowerType];
if (strictNativeCase && type !== normType ||
capitalizedNativeCase && type !== (normType[0].toUpperCase() + normType.substr(1))) {
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/validate-jsdoc/enforce-existence.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module.exports.options = {
};

/**
* validator for jsdoc data existance
* Validator for jsdoc data existance
*
* @param {(FunctionDeclaration|FunctionExpression)} node
* @param {Function} err
*/
Expand Down
2 changes: 2 additions & 0 deletions lib/rules/validate-jsdoc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var validatorsByName = module.exports = {
Object.defineProperty(validatorsByName, 'load', {
/**
* loads and initializes existing and required validators
*
* @param {Object} passedOptions
* @returns {Array.<Function>}
*/
Expand Down Expand Up @@ -61,6 +62,7 @@ Object.defineProperty(validatorsByName, 'load', {
Object.defineProperty(validatorsByName, 'checkOptions', {
/**
* Validates passed options
*
* @param {Object} validator
* @param {Object} options
* @throws {Error} If option is not valid
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/validate-jsdoc/leading-underscore-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ var nativeUnderscoredProperties = [
];

/**
* validator for jsdoc data existance
* Validator for jsdoc data existance
*
* @param {(FunctionDeclaration|FunctionExpression)} node
* @param {Function} err
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module.exports.options = {
};

/**
* checking returns types
* Checking returns types
*
* @param {(FunctionDeclaration|FunctionExpression)} node
* @param {DocTag} tag
* @param {Function} err
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/validate-jsdoc/require-param-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module.exports.options = {
};

/**
* validator for @param
* Validator for @param
*
* @param {(FunctionDeclaration|FunctionExpression)} node
* @param {DocTag} tag
* @param {Function} err
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/validate-jsdoc/require-return-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module.exports.options = {
};

/**
* requiring returns types (?)
* Requiring returns types (?)
*
* @param {(FunctionDeclaration|FunctionExpression)} node
* @param {DocTag} tag
* @param {Function} err
Expand Down
13 changes: 9 additions & 4 deletions test/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ global.checker = rulesChecker;
global.expect = expect;

/**
* parses body of function
* Parses body of function
*
* @param {Function} func
* @returns {string} body of func
*/
Expand Down Expand Up @@ -41,6 +42,7 @@ function fnBody(func) {

/**
* Testing helper object
*
* @param {Object} opts default options for jscs string checker
* @returns {{rules: function(Object),
* configure: function(Object),
Expand All @@ -60,7 +62,8 @@ function rulesChecker(opts) {

return {
/**
* set rules for each case (beforeEach wrapper)
* Set rules for each case (beforeEach wrapper)
*
* @param {Object} rules
*/
rules: function(rules) {
Expand All @@ -70,15 +73,17 @@ function rulesChecker(opts) {
},

/**
* set rules immediately
* Set rules immediately
*
* @param {Object} rules
*/
configure: function(rules) {
checker.configure({jsDoc: rules});
},

/**
* describe cases (wrapper for mocha it calls)
* Describe cases (wrapper for mocha it calls)
*
* @param {Array.<{it: string, code: Function, ?rules: Object, ?errors: *, ?skip: boolean}>} items
*/
cases: function(items) {
Expand Down

0 comments on commit 0f3a308

Please sign in to comment.