diff --git a/src/analysis/line_length.d b/src/analysis/line_length.d index a4b2637..58f48ee 100644 --- a/src/analysis/line_length.d +++ b/src/analysis/line_length.d @@ -26,7 +26,7 @@ class LineLengthCheck : BaseAnalyzer ulong lastErrorLine = ulong.max; foreach (token; tokens) { - if (token.column + token.text.length > MAX_LINE_LENGTH && token.line != lastErrorLine) + if (tokenEndColumn(token) > MAX_LINE_LENGTH && token.line != lastErrorLine) { addErrorMessage(token.line, token.column, KEY, MESSAGE); lastErrorLine = token.line; @@ -38,6 +38,21 @@ class LineLengthCheck : BaseAnalyzer private: + static ulong tokenEndColumn(ref const Token tok) + { + import std.uni : lineSep, paraSep; + + ulong endColumn = tok.column; + foreach (dchar c; tok.text) + { + if (c == lineSep || c == '\n' || c == '\v' || c == '\r' || c == paraSep) + endColumn = 0; + else + endColumn++; + } + return endColumn; + } + import std.conv : to; enum string KEY = "dscanner.style.long_line";