Skip to content
This repository was archived by the owner on Feb 21, 2022. It is now read-only.

Commit 6f8ce27

Browse files
authored
Merge pull request #221 from reduckted/valid-jsdoc-location-fix
[bug] fixed valid-jsdoc rule (closes #220)
2 parents a44c93f + 82a3ca7 commit 6f8ce27

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/rules/validJsdocRule.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,11 @@ class ValidJsdocWalker extends Lint.RuleWalker {
261261
}
262262

263263
let comments = node.getFullText();
264-
comments = comments.substring(comments.indexOf('/**'));
264+
let offset = comments.indexOf('/**');
265+
comments = comments.substring(offset);
265266
comments = comments.substring(0, comments.indexOf('*/') + 2);
266267

267-
let start = node.pos;
268+
let start = node.pos + offset;
268269
let width = comments.length;
269270

270271
if (!/^\/\*\*/.test(comments) || !/\*\/$/.test(comments)) {

src/test/rules/validJsdocRuleTests.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,4 +718,28 @@ ruleTester.addTestGroup('param-type', 'should handle requireParamType option', [
718718
}
719719
]);
720720

721+
ruleTester.addTestGroup('error-location', 'error location should span the comment', [
722+
{
723+
code: dedent`
724+
/**
725+
* Class
726+
*/
727+
class Foo {
728+
729+
/**
730+
* Function
731+
*/
732+
public bar(x: any): void {
733+
}
734+
735+
}`,
736+
options: { requireReturn: false },
737+
errors: [{
738+
failure: "missing JSDoc for parameter 'x'",
739+
startPosition: new Position(6, 2),
740+
endPosition: new Position(8, 5)
741+
}]
742+
}
743+
]);
744+
721745
ruleTester.runTests();

0 commit comments

Comments
 (0)