Skip to content

Commit

Permalink
fix: avoid highlighting whole function block upon missing jsdoc block…
Browse files Browse the repository at this point in the history
… in favor of highlighting first line only; fixes #386
  • Loading branch information
brettz9 authored and golopot committed Sep 27, 2019
1 parent c523384 commit f77144d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/rules/requireJsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,19 @@ export default {
return fixer.insertTextBefore(baseNode, insertion);
};

const report = () => {
const loc = {
end: node.loc.start,
start: node.loc.start,
};
context.report({
fix,
messageId: 'missingJsDoc',
node,
loc,
});
};

if (publicOnly) {
const opt = {
ancestorsOnly: Boolean(_.get(publicOnly, 'ancestorsOnly', false)),
Expand All @@ -183,18 +196,10 @@ export default {
const exported = exportParser.isExported(node, parseResult, opt);

if (exported) {
context.report({
fix,
messageId: 'missingJsDoc',
node,
});
report();
}
} else {
context.report({
fix,
messageId: 'missingJsDoc',
node,
});
report();
}
};

Expand Down
1 change: 1 addition & 0 deletions test/rules/assertions/requireJsdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ export default {
}`,
errors: [
{
endLine: 2,
line: 2,
message: 'Missing JSDoc comment.',
},
Expand Down

0 comments on commit f77144d

Please sign in to comment.