mirror of
https://github.com/dlang/tools.git
synced 2025-04-25 20:51:00 +03:00
checkwhitespace.d: Allow individual errors to be turned off.
To allow running checkwhitespace on files not recognized by the program, e.g: 'checkwhitespace --allow-tabs Makefile'
This commit is contained in:
parent
a36dafa5e6
commit
c3349fd512
1 changed files with 10 additions and 3 deletions
|
@ -15,6 +15,13 @@ import std.path;
|
||||||
|
|
||||||
int main(string[] args)
|
int main(string[] args)
|
||||||
{
|
{
|
||||||
|
import std.getopt;
|
||||||
|
bool allowdos, allowtabs, allowtrailing;
|
||||||
|
getopt(args,
|
||||||
|
"allow-windows-newlines", &allowdos,
|
||||||
|
"allow-tabs", &allowtabs,
|
||||||
|
"allow-trailing-whitespace", &allowtrailing);
|
||||||
|
|
||||||
bool error;
|
bool error;
|
||||||
auto r = regex(r" +\n");
|
auto r = regex(r" +\n");
|
||||||
foreach(a; args[1..$])
|
foreach(a; args[1..$])
|
||||||
|
@ -23,18 +30,18 @@ int main(string[] args)
|
||||||
{
|
{
|
||||||
ptrdiff_t pos;
|
ptrdiff_t pos;
|
||||||
auto str = a.readText();
|
auto str = a.readText();
|
||||||
if ((pos = str.indexOf("\r\n")) >= 0)
|
if (!allowdos && (pos = str.indexOf("\r\n")) >= 0)
|
||||||
{
|
{
|
||||||
writefln("Error - file '%s' contains windows line endings at line %d", a, str[0..pos].count('\n') + 1);
|
writefln("Error - file '%s' contains windows line endings at line %d", a, str[0..pos].count('\n') + 1);
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
if (a.extension() != ".mak" && (pos = str.indexOf('\t')) >= 0)
|
if (!allowtabs && a.extension() != ".mak" && (pos = str.indexOf('\t')) >= 0)
|
||||||
{
|
{
|
||||||
writefln("Error - file '%s' contains tabs at line %d", a, str[0..pos].count('\n') + 1);
|
writefln("Error - file '%s' contains tabs at line %d", a, str[0..pos].count('\n') + 1);
|
||||||
error = true;
|
error = true;
|
||||||
}
|
}
|
||||||
auto m = str.matchFirst(r);
|
auto m = str.matchFirst(r);
|
||||||
if (!m.empty)
|
if (!allowtrailing && !m.empty)
|
||||||
{
|
{
|
||||||
pos = m.front.ptr - str.ptr; // assume the match is a slice of the string
|
pos = m.front.ptr - str.ptr; // assume the match is a slice of the string
|
||||||
writefln("Error - file '%s' contains trailing whitespace at line %d", a, str[0..pos].count('\n') + 1);
|
writefln("Error - file '%s' contains trailing whitespace at line %d", a, str[0..pos].count('\n') + 1);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue