Fix false positive for strings with newlines

This commit is contained in:
Hackerpilot 2015-10-30 14:41:38 -07:00
parent ceff31d216
commit b3e22eb10e
1 changed files with 16 additions and 1 deletions

View File

@ -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";