Skip to content

Commit 3e86bd4

Browse files
author
Alexej Yaroshevich
committed
disallowNewlineAfterDescription: mirror for require
Ref #85 Closes gh-99
1 parent ca972d4 commit 3e86bd4

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module.exports = disallowNewlineAfterDescription;
2+
module.exports.scopes = ['function'];
3+
module.exports.options = {
4+
disallowNewlineAfterDescription: {allowedValues: [true]}
5+
};
6+
7+
var RE_NEWLINE_AT_THE_END = /\n$/;
8+
var RE_NEWLINES = /\n/g;
9+
10+
/**
11+
* Disallows newline after description in jsdoc comment
12+
*
13+
* @param {(FunctionDeclaration|FunctionExpression)} node
14+
* @param {Function} err
15+
*/
16+
function disallowNewlineAfterDescription(node, err) {
17+
var doc = node.jsdoc;
18+
if (!doc || !doc.tags.length || !doc.description || !doc.description.length) {
19+
return;
20+
}
21+
22+
if (!RE_NEWLINE_AT_THE_END.test(doc.description)) {
23+
return;
24+
}
25+
26+
var loc = node.jsdoc.loc.start;
27+
var lines = doc.description.split(RE_NEWLINES);
28+
err('Newline required after description', {
29+
line: loc.line + lines.length,
30+
column: loc.column + 3 + lines[lines.length - 1].length
31+
});
32+
}

lib/rules/validate-jsdoc/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var validatorsByName = module.exports = {
1515
checkAnnotations: require('./check-annotations'),
1616

1717
requireNewlineAfterDescription: require('./require-newline-after-description'),
18+
disallowNewlineAfterDescription: require('./disallow-newline-after-description'),
1819

1920
checkRedundantAccess: require('./check-redundant-access'),
2021
enforceExistence: require('./enforce-existence'),
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
describe('lib/rules/validate-jsdoc/disallow-newline-after-description', function () {
2+
var checker = global.checker({
3+
additionalRules: ['lib/rules/validate-jsdoc.js']
4+
});
5+
6+
describe('not configured', function() {
7+
8+
it('should report with undefined', function() {
9+
global.expect(function() {
10+
checker.configure({disallowNewlineAfterDescription: undefined});
11+
}).to.throws(/accepted value/i);
12+
});
13+
14+
it('should report with an object', function() {
15+
global.expect(function() {
16+
checker.configure({disallowNewlineAfterDescription: {}});
17+
}).to.throws(/accepted value/i);
18+
});
19+
20+
});
21+
22+
describe('with true', function() {
23+
checker.rules({disallowNewlineAfterDescription: true});
24+
25+
checker.cases([
26+
/* jshint ignore:start */
27+
{
28+
it: 'should not report common cases',
29+
code: function() {
30+
function fun(p) {
31+
}
32+
33+
/**
34+
* Description
35+
*/
36+
function fun(p) {
37+
}
38+
39+
/**
40+
* @param p
41+
*/
42+
function fun(p) {
43+
}
44+
}
45+
}, {
46+
it: 'should node report newline absence after description',
47+
code: function () {
48+
/**
49+
* Some description
50+
* @param {number} p description without hyphen
51+
*/
52+
function fun(p) {
53+
}
54+
},
55+
}, {
56+
it: 'should report newline after description',
57+
code: function () {
58+
/**
59+
* Some description.
60+
* Get me higher and higher!
61+
*
62+
* @param {number} p description without hyphen
63+
*/
64+
function fun(p) {}
65+
},
66+
errors: {
67+
line: 4,
68+
column: 3
69+
},
70+
}
71+
/* jshint ignore:end */
72+
]);
73+
74+
});
75+
76+
});

0 commit comments

Comments
 (0)