Skip to content

Commit 47519b4

Browse files
committed
html-writer: linkify [SC1234] event suffix
... in SHELLCHECK_WARNING reports
1 parent 2848539 commit 47519b4

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

html-writer.cc

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,11 @@ void HtmlWriter::Private::writeNewDefWarning(const Defect &def) {
420420
}
421421

422422
void linkifyShellCheckMsg(std::string *pMgs) {
423-
static boost::regex reShellCheckMsg(" \\[SC([0-9]+)\\]$");
423+
static boost::regex reShellCheckMsg("(\\[)?SC([0-9]+)(\\])?$");
424424
*pMgs = boost::regex_replace(*pMgs, reShellCheckMsg,
425-
" <a href=\"https://github.com/koalaman/shellcheck/wiki/SC\\1\""
426-
" title=\"description of ShellCheck's checker SC\\1\">"
427-
"[SC\\1]</a>");
425+
"<a href=\"https://github.com/koalaman/shellcheck/wiki/SC\\2\""
426+
" title=\"description of ShellCheck's checker SC\\2\">"
427+
"\\1SC\\2\\3</a>");
428428
}
429429

430430
void HtmlWriter::handleDef(const Defect &def) {
@@ -487,11 +487,15 @@ void HtmlWriter::handleDef(const Defect &def) {
487487

488488
boost::smatch sm;
489489
const std::string &evtName = evt.event;
490-
if (boost::regex_match(evtName, sm, d->reEvent))
490+
if (boost::regex_match(evtName, sm, d->reEvent)) {
491+
std::string msgId = HtmlLib::escapeTextInline(sm[/* id */ 2]);
492+
if (def.checker == "SHELLCHECK_WARNING")
493+
linkifyShellCheckMsg(&msgId);
491494
d->str
492-
<< HtmlLib::escapeTextInline(sm[1]) << "<b>"
493-
<< HtmlLib::escapeTextInline(sm[2]) << "</b>"
495+
<< HtmlLib::escapeTextInline(sm[1])
496+
<< "<b>" << msgId << "</b>"
494497
<< HtmlLib::escapeTextInline(sm[3]);
498+
}
495499
else
496500
d->str << "<b>" << HtmlLib::escapeTextInline(evtName) << "</b>";
497501

0 commit comments

Comments
 (0)