From b3e22eb10e5ffaed16f41b1a95ba049c01906f06 Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Fri, 30 Oct 2015 14:41:38 -0700 Subject: [PATCH] Fix false positive for strings with newlines --- src/analysis/line_length.d | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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";