Skip to content

Commit 2caffd5

Browse files
committed
Merge pull request #52 from hzoo/require-hyphen-before-@param-description
new rule: requireHyphenBeforeDescription
2 parents bf7b174 + e317b03 commit 2caffd5

13 files changed

+129
-50
lines changed

lib/rules/validate-jsdoc/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var validatorsByName = module.exports = {
66
checkParamNames: require('./check-param-names'),
77
checkRedundantParams: require('./check-redundant-params'),
88
requireParamTypes: require('./require-param-types'),
9+
requireHyphenBeforeDescription: require('./require-hyphen-before-description'),
910

1011
checkReturnTypes: require('./check-return-types'),
1112
requireReturnTypes: require('./require-return-types'),
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports = requireHyphenBeforeDescription;
2+
module.exports.tags = ['param', 'arg', 'argument'];
3+
module.exports.scopes = ['function'];
4+
module.exports.options = {
5+
requireHyphenBeforeDescription: {allowedValues: [true]}
6+
};
7+
8+
/**
9+
* checking returns types
10+
* @param {(FunctionDeclaration|FunctionExpression)} node
11+
* @param {DocTag} tag
12+
* @param {Function} err
13+
*/
14+
function requireHyphenBeforeDescription(node, tag, err) {
15+
if (!tag.description) {
16+
return;
17+
}
18+
19+
if (tag.description.substring(0, 2) !== '- ') {
20+
err('Missing hyphen before description', tag.loc);
21+
}
22+
}

test/lib/rules/validate-jsdoc/check-param-names.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ describe('lib/rules/validate-jsdoc/check-param-names', function () {
33
additionalRules: ['lib/rules/validate-jsdoc.js']
44
});
55

6-
describe('configured', function() {
6+
describe('not configured', function() {
77

8-
it('with undefined should throws', function() {
8+
it('should report with undefined', function() {
99
global.expect(function() {
1010
checker.configure({checkParamNames: undefined});
1111
}).to.throws(/accepted value/i);
1212
});
1313

14-
it('with undefined should throws', function() {
14+
it('should report with an object', function() {
1515
global.expect(function() {
1616
checker.configure({checkParamNames: {}});
1717
}).to.throws(/accepted value/i);
@@ -25,7 +25,7 @@ describe('lib/rules/validate-jsdoc/check-param-names', function () {
2525
checker.cases([
2626
/* jshint ignore:start */
2727
{
28-
it: 'should not throw',
28+
it: 'should not report',
2929
code: function() {
3030
function yay(yey) {
3131
}
@@ -37,7 +37,6 @@ describe('lib/rules/validate-jsdoc/check-param-names', function () {
3737
function yey(yay) {
3838
}
3939
}
40-
4140
}, {
4241
it: 'should report invalid jsdoc',
4342
code: function () {

test/lib/rules/validate-jsdoc/check-redundant-access.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ describe('lib/rules/validate-jsdoc/check-redundant-access', function () {
33
additionalRules: ['lib/rules/validate-jsdoc.js']
44
});
55

6-
describe('configured', function() {
6+
describe('not configured', function() {
77

8-
it('with undefined should throws', function() {
8+
it('should report with undefined', function() {
99
global.expect(function() {
1010
checker.configure({checkRedundantAccess: undefined});
1111
}).to.throws(/accepted value/i);
1212
});
1313

14-
it('with undefined should throws', function() {
14+
it('should report with an object', function() {
1515
global.expect(function() {
1616
checker.configure({checkRedundantAccess: {}});
1717
}).to.throws(/accepted value/i);
@@ -25,12 +25,11 @@ describe('lib/rules/validate-jsdoc/check-redundant-access', function () {
2525
checker.cases([
2626
/* jshint ignore:start */
2727
{
28-
it: 'should not throw',
28+
it: 'should not report',
2929
code: function() {
3030
function yay(yey) {
3131
}
3232
}
33-
3433
}, {
3534
it: 'should report confusing multiaccess',
3635
errors: 1,

test/lib/rules/validate-jsdoc/check-redundant-params.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ describe('lib/rules/validate-jsdoc/check-redundant-params', function () {
33
additionalRules: ['lib/rules/validate-jsdoc.js']
44
});
55

6-
describe('configured', function() {
6+
describe('not configured', function() {
77

8-
it('with undefined should throws', function() {
8+
it('should report with undefined', function() {
99
global.expect(function() {
1010
checker.configure({checkRedundantParams: undefined});
1111
}).to.throws(/accepted value/i);
1212
});
1313

14-
it('with undefined should throws', function() {
14+
it('should report with an object', function() {
1515
global.expect(function() {
1616
checker.configure({checkRedundantParams: {}});
1717
}).to.throws(/accepted value/i);
@@ -25,12 +25,11 @@ describe('lib/rules/validate-jsdoc/check-redundant-params', function () {
2525
checker.cases([
2626
/* jshint ignore:start */
2727
{
28-
it: 'should not throw',
28+
it: 'should not report',
2929
code: function() {
3030
function yay(yey) {
3131
}
3232
}
33-
3433
}, {
3534
it: 'should report redundant jsdoc-param for function',
3635
errors: 1,

test/lib/rules/validate-jsdoc/check-redundant-returns.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ describe('lib/rules/validate-jsdoc/check-redundant-returns', function () {
33
additionalRules: ['lib/rules/validate-jsdoc.js']
44
});
55

6-
describe('configured', function() {
6+
describe('not configured', function() {
77

8-
it('with undefined should throws', function() {
8+
it('should report with undefined', function() {
99
global.expect(function() {
1010
checker.configure({checkRedundantReturns: undefined});
1111
}).to.throws(/accepted value/i);
1212
});
1313

14-
it('with undefined should throws', function() {
14+
it('should report with an object', function() {
1515
global.expect(function() {
1616
checker.configure({checkRedundantReturns: {}});
1717
}).to.throws(/accepted value/i);
@@ -25,12 +25,11 @@ describe('lib/rules/validate-jsdoc/check-redundant-returns', function () {
2525
checker.cases([
2626
/* jshint ignore:start */
2727
{
28-
it: 'should not throw',
28+
it: 'should not report',
2929
code: function() {
3030
function yay(yey) {
3131
}
3232
}
33-
3433
}, {
3534
it: 'should report redundant @returns for function',
3635
errors: 3,

test/lib/rules/validate-jsdoc/check-return-types.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ describe('lib/rules/validate-jsdoc/check-return-types', function () {
33
additionalRules: ['lib/rules/validate-jsdoc.js']
44
});
55

6-
describe('configured', function() {
6+
describe('not configured', function() {
77

8-
it('with undefined should throws', function() {
8+
it('should report with undefined', function() {
99
global.expect(function() {
1010
checker.configure({checkReturnTypes: undefined});
1111
}).to.throws(/accepted value/i);
1212
});
1313

14-
it('with undefined should throws', function() {
14+
it('should report with an object', function() {
1515
global.expect(function() {
1616
checker.configure({checkReturnTypes: {}});
1717
}).to.throws(/accepted value/i);
@@ -25,14 +25,13 @@ describe('lib/rules/validate-jsdoc/check-return-types', function () {
2525
checker.cases([
2626
/* jshint ignore:start */
2727
{
28-
it: 'should not throw',
28+
it: 'should not report',
2929
code: function() {
3030
function yay(yey) {
3131
}
3232
}
33-
3433
}, {
35-
it: 'should throw invalid type',
34+
it: 'should report invalid type',
3635
errors: 1,
3736
code: function () {
3837
/**
@@ -43,7 +42,7 @@ describe('lib/rules/validate-jsdoc/check-return-types', function () {
4342
}
4443
}
4544
}, {
46-
it: 'should neither throw nor report',
45+
it: 'should not report',
4746
code: function () {
4847
/**
4948
* @return {{a: number, b: string}}

test/lib/rules/validate-jsdoc/check-types.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ describe('lib/rules/validate-jsdoc/check-types', function() {
33
additionalRules: ['lib/rules/validate-jsdoc.js']
44
});
55

6-
describe('configured', function() {
6+
describe('not configured', function() {
77

8-
it('with undefined should throws', function() {
8+
it('should report with undefined', function() {
99
global.expect(function() {
1010
checker.configure({checkTypes: undefined});
1111
}).to.throws(/accepted value/i);
1212
});
1313

14-
it('with undefined should throws', function() {
14+
it('should report with an object', function() {
1515
global.expect(function() {
1616
checker.configure({checkTypes: {}});
1717
}).to.throws(/accepted value/i);
@@ -25,12 +25,11 @@ describe('lib/rules/validate-jsdoc/check-types', function() {
2525
checker.cases([
2626
/* jshint ignore:start */
2727
{
28-
it: 'should not throw',
28+
it: 'should not report',
2929
code: function() {
3030
function yay(yey) {
3131
}
3232
}
33-
3433
}, {
3534
it: 'should report invalid typedef',
3635
errors: 1,

test/lib/rules/validate-jsdoc/enforce-existence.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ describe('lib/rules/validate-jsdoc/enforce-existence', function () {
33
additionalRules: ['lib/rules/validate-jsdoc.js']
44
});
55

6-
describe('configured', function() {
6+
describe('not configured', function() {
77

8-
it('with undefined should throws', function() {
8+
it('should report with undefined', function() {
99
global.expect(function() {
1010
checker.configure({enforceExistence: undefined});
1111
}).to.throws(/accepted value/i);
1212
});
1313

14-
it('with undefined should throws', function() {
14+
it('should report with an object', function() {
1515
global.expect(function() {
1616
checker.configure({enforceExistence: {}});
1717
}).to.throws(/accepted value/i);

test/lib/rules/validate-jsdoc/leading-underscore-access.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ describe('lib/rules/validate-jsdoc/leading-underscore-access', function () {
33
additionalRules: ['lib/rules/validate-jsdoc.js']
44
});
55

6-
describe('configured', function() {
6+
describe('not configured', function() {
77

8-
it('with undefined should throws', function() {
8+
it('should report with undefined', function() {
99
global.expect(function() {
1010
checker.configure({leadingUnderscoreAccess: undefined});
1111
}).to.throws(/accepted value/i);
1212
});
1313

14-
it('with object should throws', function() {
14+
it('should report with an object', function() {
1515
global.expect(function() {
1616
checker.configure({leadingUnderscoreAccess: {}});
1717
}).to.throws(/accepted value/i);
@@ -24,13 +24,12 @@ describe('lib/rules/validate-jsdoc/leading-underscore-access', function () {
2424
checker.cases([
2525
/* jshint ignore:start */
2626
{
27-
it: 'should not throw',
27+
it: 'should not report',
2828
rules: {leadingUnderscoreAccess: true},
2929
code: function() {
3030
function yay(yey) {
3131
}
3232
}
33-
3433
}, {
3534
it: 'should report enforcing @private on leading underscores',
3635
rules: {leadingUnderscoreAccess: 'private'},

0 commit comments

Comments
 (0)