Skip to content

Commit 605ef1c

Browse files
brokentonegajus
authored andcommitted
feat: add support for reporting individual lines of jsdoc infraction (#82)
1 parent c315d55 commit 605ef1c

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/iterateJsdoc.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ const curryUtils = (functionNode, jsdoc, tagNamePreference, additionalTagNames,
3636
return utils;
3737
};
3838

39-
export const parseComment = (commentNode) => {
39+
export const parseComment = (commentNode, indent) => {
4040
// Preserve JSDoc block start/end indentation.
41-
const indent = _.repeat(' ', commentNode.loc.start.column);
42-
4341
return commentParser(indent + '/*' + commentNode.value + indent + '*/', {
4442
// @see https://github.com/yavorskiy/comment-parser/issues/21
4543
parsers: [
@@ -73,14 +71,29 @@ export default (iterator) => {
7371

7472
const indent = _.repeat(' ', jsdocNode.loc.start.column);
7573

76-
const jsdoc = parseComment(jsdocNode);
74+
const jsdoc = parseComment(jsdocNode, indent);
75+
76+
const report = (message, fixer = null, jsdocLine = null) => {
77+
let loc;
7778

78-
const report = (message, fixer = null) => {
79+
if (jsdocLine) {
80+
const lineNumber = jsdocNode.loc.start.line + jsdocLine.line;
81+
82+
loc = {
83+
end: {line: lineNumber},
84+
start: {line: lineNumber}
85+
};
86+
}
7987
if (fixer === null) {
80-
context.report(jsdocNode, message);
88+
context.report({
89+
loc,
90+
message,
91+
node: jsdocNode
92+
});
8193
} else {
8294
context.report({
8395
fix: fixer,
96+
loc,
8497
message,
8598
node: jsdocNode
8699
});

0 commit comments

Comments
 (0)