-
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.
disallowNewlineAfterDescription: mirror for require
Ref #85
- Loading branch information
Alexej Yaroshevich
committed
May 3, 2015
1 parent
3346922
commit 789474a
Showing
3 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
lib/rules/validate-jsdoc/disallow-newline-after-description.js
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,32 @@ | ||
module.exports = disallowNewlineAfterDescription; | ||
module.exports.scopes = ['function']; | ||
module.exports.options = { | ||
disallowNewlineAfterDescription: {allowedValues: [true]} | ||
}; | ||
|
||
var RE_NEWLINE_AT_THE_END = /\n$/; | ||
var RE_NEWLINES = /\n/g; | ||
|
||
/** | ||
* Disallows newline after description in jsdoc comment | ||
* | ||
* @param {(FunctionDeclaration|FunctionExpression)} node | ||
* @param {Function} err | ||
*/ | ||
function disallowNewlineAfterDescription(node, err) { | ||
var doc = node.jsdoc; | ||
if (!doc || !doc.tags.length || !doc.description || !doc.description.length) { | ||
return; | ||
} | ||
|
||
if (!RE_NEWLINE_AT_THE_END.test(doc.description)) { | ||
return; | ||
} | ||
|
||
var loc = node.jsdoc.loc.start; | ||
var lines = doc.description.split(RE_NEWLINES); | ||
err('Newline required after description', { | ||
line: loc.line + lines.length, | ||
column: loc.column + 3 + lines[lines.length - 1].length | ||
}); | ||
} |
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
76 changes: 76 additions & 0 deletions
76
test/lib/rules/validate-jsdoc/disallow-newline-after-description.js
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,76 @@ | ||
describe('lib/rules/validate-jsdoc/disallow-newline-after-description', function () { | ||
var checker = global.checker({ | ||
additionalRules: ['lib/rules/validate-jsdoc.js'] | ||
}); | ||
|
||
describe('not configured', function() { | ||
|
||
it('should report with undefined', function() { | ||
global.expect(function() { | ||
checker.configure({disallowNewlineAfterDescription: undefined}); | ||
}).to.throws(/accepted value/i); | ||
}); | ||
|
||
it('should report with an object', function() { | ||
global.expect(function() { | ||
checker.configure({disallowNewlineAfterDescription: {}}); | ||
}).to.throws(/accepted value/i); | ||
}); | ||
|
||
}); | ||
|
||
describe('with true', function() { | ||
checker.rules({disallowNewlineAfterDescription: true}); | ||
|
||
checker.cases([ | ||
/* jshint ignore:start */ | ||
{ | ||
it: 'should not report common cases', | ||
code: function() { | ||
function fun(p) { | ||
} | ||
|
||
/** | ||
* Description | ||
*/ | ||
function fun(p) { | ||
} | ||
|
||
/** | ||
* @param p | ||
*/ | ||
function fun(p) { | ||
} | ||
} | ||
}, { | ||
it: 'should node report newline absence after description', | ||
code: function () { | ||
/** | ||
* Some description | ||
* @param {number} p description without hyphen | ||
*/ | ||
function fun(p) { | ||
} | ||
}, | ||
}, { | ||
it: 'should report newline after description', | ||
code: function () { | ||
/** | ||
* Some description. | ||
* Get me higher and higher! | ||
* | ||
* @param {number} p description without hyphen | ||
*/ | ||
function fun(p) {} | ||
}, | ||
errors: { | ||
line: 4, | ||
column: 3 | ||
}, | ||
} | ||
/* jshint ignore:end */ | ||
]); | ||
|
||
}); | ||
|
||
}); |