Skip to content

Commit

Permalink
Merge pull request dlang#5182 from wilzbach/style-binary-ops
Browse files Browse the repository at this point in the history
Style: add a check to enforce whitespace between binary ops
  • Loading branch information
andralex authored Feb 23, 2017
2 parents f795add + a1bb051 commit 22331db
Show file tree
Hide file tree
Showing 36 changed files with 305 additions and 302 deletions.
108 changes: 54 additions & 54 deletions etc/c/sqlite3.d
Original file line number Diff line number Diff line change
Expand Up @@ -149,59 +149,59 @@ enum
*/
enum
{
SQLITE_IOERR_READ = (SQLITE_IOERR | (1<<8)),
SQLITE_IOERR_SHORT_READ = (SQLITE_IOERR | (2<<8)),
SQLITE_IOERR_WRITE = (SQLITE_IOERR | (3<<8)),
SQLITE_IOERR_FSYNC = (SQLITE_IOERR | (4<<8)),
SQLITE_IOERR_DIR_FSYNC = (SQLITE_IOERR | (5<<8)),
SQLITE_IOERR_TRUNCATE = (SQLITE_IOERR | (6<<8)),
SQLITE_IOERR_FSTAT = (SQLITE_IOERR | (7<<8)),
SQLITE_IOERR_UNLOCK = (SQLITE_IOERR | (8<<8)),
SQLITE_IOERR_RDLOCK = (SQLITE_IOERR | (9<<8)),
SQLITE_IOERR_DELETE = (SQLITE_IOERR | (10<<8)),
SQLITE_IOERR_BLOCKED = (SQLITE_IOERR | (11<<8)),
SQLITE_IOERR_NOMEM = (SQLITE_IOERR | (12<<8)),
SQLITE_IOERR_ACCESS = (SQLITE_IOERR | (13<<8)),
SQLITE_IOERR_CHECKRESERVEDLOCK = (SQLITE_IOERR | (14<<8)),
SQLITE_IOERR_LOCK = (SQLITE_IOERR | (15<<8)),
SQLITE_IOERR_CLOSE = (SQLITE_IOERR | (16<<8)),
SQLITE_IOERR_DIR_CLOSE = (SQLITE_IOERR | (17<<8)),
SQLITE_IOERR_SHMOPEN = (SQLITE_IOERR | (18<<8)),
SQLITE_IOERR_SHMSIZE = (SQLITE_IOERR | (19<<8)),
SQLITE_IOERR_SHMLOCK = (SQLITE_IOERR | (20<<8)),
SQLITE_IOERR_SHMMAP = (SQLITE_IOERR | (21<<8)),
SQLITE_IOERR_SEEK = (SQLITE_IOERR | (22<<8)),
SQLITE_IOERR_DELETE_NOENT = (SQLITE_IOERR | (23<<8)),
SQLITE_IOERR_MMAP = (SQLITE_IOERR | (24<<8)),
SQLITE_LOCKED_SHAREDCACHE = (SQLITE_LOCKED | (1<<8)),
SQLITE_BUSY_RECOVERY = (SQLITE_BUSY | (1<<8)),
SQLITE_CANTOPEN_NOTEMPDIR = (SQLITE_CANTOPEN | (1<<8)),
SQLITE_IOERR_GETTEMPPATH = (SQLITE_IOERR | (25<<8)),
SQLITE_IOERR_CONVPATH = (SQLITE_IOERR | (26<<8)),
SQLITE_BUSY_SNAPSHOT = (SQLITE_BUSY | (2<<8)),
SQLITE_CANTOPEN_ISDIR = (SQLITE_CANTOPEN | (2<<8)),
SQLITE_CANTOPEN_FULLPATH = (SQLITE_CANTOPEN | (3<<8)),
SQLITE_CANTOPEN_CONVPATH = (SQLITE_CANTOPEN | (4<<8)),
SQLITE_CORRUPT_VTAB = (SQLITE_CORRUPT | (1<<8)),
SQLITE_READONLY_RECOVERY = (SQLITE_READONLY | (1<<8)),
SQLITE_READONLY_CANTLOCK = (SQLITE_READONLY | (2<<8)),
SQLITE_READONLY_ROLLBACK = (SQLITE_READONLY | (3<<8)),
SQLITE_READONLY_DBMOVED = (SQLITE_READONLY | (4<<8)),
SQLITE_ABORT_ROLLBACK = (SQLITE_ABORT | (2<<8)),
SQLITE_CONSTRAINT_CHECK = (SQLITE_CONSTRAINT | (1<<8)),
SQLITE_CONSTRAINT_COMMITHOOK = (SQLITE_CONSTRAINT | (2<<8)),
SQLITE_CONSTRAINT_FOREIGNKEY = (SQLITE_CONSTRAINT | (3<<8)),
SQLITE_CONSTRAINT_FUNCTION = (SQLITE_CONSTRAINT | (4<<8)),
SQLITE_CONSTRAINT_NOTNULL = (SQLITE_CONSTRAINT | (5<<8)),
SQLITE_CONSTRAINT_PRIMARYKEY = (SQLITE_CONSTRAINT | (6<<8)),
SQLITE_CONSTRAINT_TRIGGER = (SQLITE_CONSTRAINT | (7<<8)),
SQLITE_CONSTRAINT_UNIQUE = (SQLITE_CONSTRAINT | (8<<8)),
SQLITE_CONSTRAINT_VTAB = (SQLITE_CONSTRAINT | (9<<8)),
SQLITE_CONSTRAINT_ROWID = (SQLITE_CONSTRAINT |(10<<8)),
SQLITE_NOTICE_RECOVER_WAL = (SQLITE_NOTICE | (1<<8)),
SQLITE_NOTICE_RECOVER_ROLLBACK = (SQLITE_NOTICE | (2<<8)),
SQLITE_WARNING_AUTOINDEX = (SQLITE_WARNING | (1<<8)),
SQLITE_AUTH_USER = (SQLITE_AUTH | (1<<8))
SQLITE_IOERR_READ = (SQLITE_IOERR | (1 << 8)),
SQLITE_IOERR_SHORT_READ = (SQLITE_IOERR | (2 << 8)),
SQLITE_IOERR_WRITE = (SQLITE_IOERR | (3 << 8)),
SQLITE_IOERR_FSYNC = (SQLITE_IOERR | (4 << 8)),
SQLITE_IOERR_DIR_FSYNC = (SQLITE_IOERR | (5 << 8)),
SQLITE_IOERR_TRUNCATE = (SQLITE_IOERR | (6 << 8)),
SQLITE_IOERR_FSTAT = (SQLITE_IOERR | (7 << 8)),
SQLITE_IOERR_UNLOCK = (SQLITE_IOERR | (8 << 8)),
SQLITE_IOERR_RDLOCK = (SQLITE_IOERR | (9 << 8)),
SQLITE_IOERR_DELETE = (SQLITE_IOERR | (10 << 8)),
SQLITE_IOERR_BLOCKED = (SQLITE_IOERR | (11 << 8)),
SQLITE_IOERR_NOMEM = (SQLITE_IOERR | (12 << 8)),
SQLITE_IOERR_ACCESS = (SQLITE_IOERR | (13 << 8)),
SQLITE_IOERR_CHECKRESERVEDLOCK = (SQLITE_IOERR | (14 << 8)),
SQLITE_IOERR_LOCK = (SQLITE_IOERR | (15 << 8)),
SQLITE_IOERR_CLOSE = (SQLITE_IOERR | (16 << 8)),
SQLITE_IOERR_DIR_CLOSE = (SQLITE_IOERR | (17 << 8)),
SQLITE_IOERR_SHMOPEN = (SQLITE_IOERR | (18 << 8)),
SQLITE_IOERR_SHMSIZE = (SQLITE_IOERR | (19 << 8)),
SQLITE_IOERR_SHMLOCK = (SQLITE_IOERR | (20 << 8)),
SQLITE_IOERR_SHMMAP = (SQLITE_IOERR | (21 << 8)),
SQLITE_IOERR_SEEK = (SQLITE_IOERR | (22 << 8)),
SQLITE_IOERR_DELETE_NOENT = (SQLITE_IOERR | (23 << 8)),
SQLITE_IOERR_MMAP = (SQLITE_IOERR | (24 << 8)),
SQLITE_LOCKED_SHAREDCACHE = (SQLITE_LOCKED | (1 << 8)),
SQLITE_BUSY_RECOVERY = (SQLITE_BUSY | (1 << 8)),
SQLITE_CANTOPEN_NOTEMPDIR = (SQLITE_CANTOPEN | (1 << 8)),
SQLITE_IOERR_GETTEMPPATH = (SQLITE_IOERR | (25 << 8)),
SQLITE_IOERR_CONVPATH = (SQLITE_IOERR | (26 << 8)),
SQLITE_BUSY_SNAPSHOT = (SQLITE_BUSY | (2 << 8)),
SQLITE_CANTOPEN_ISDIR = (SQLITE_CANTOPEN | (2 << 8)),
SQLITE_CANTOPEN_FULLPATH = (SQLITE_CANTOPEN | (3 << 8)),
SQLITE_CANTOPEN_CONVPATH = (SQLITE_CANTOPEN | (4 << 8)),
SQLITE_CORRUPT_VTAB = (SQLITE_CORRUPT | (1 << 8)),
SQLITE_READONLY_RECOVERY = (SQLITE_READONLY | (1 << 8)),
SQLITE_READONLY_CANTLOCK = (SQLITE_READONLY | (2 << 8)),
SQLITE_READONLY_ROLLBACK = (SQLITE_READONLY | (3 << 8)),
SQLITE_READONLY_DBMOVED = (SQLITE_READONLY | (4 << 8)),
SQLITE_ABORT_ROLLBACK = (SQLITE_ABORT | (2 << 8)),
SQLITE_CONSTRAINT_CHECK = (SQLITE_CONSTRAINT | (1 << 8)),
SQLITE_CONSTRAINT_COMMITHOOK = (SQLITE_CONSTRAINT | (2 << 8)),
SQLITE_CONSTRAINT_FOREIGNKEY = (SQLITE_CONSTRAINT | (3 << 8)),
SQLITE_CONSTRAINT_FUNCTION = (SQLITE_CONSTRAINT | (4 << 8)),
SQLITE_CONSTRAINT_NOTNULL = (SQLITE_CONSTRAINT | (5 << 8)),
SQLITE_CONSTRAINT_PRIMARYKEY = (SQLITE_CONSTRAINT | (6 << 8)),
SQLITE_CONSTRAINT_TRIGGER = (SQLITE_CONSTRAINT | (7 << 8)),
SQLITE_CONSTRAINT_UNIQUE = (SQLITE_CONSTRAINT | (8 << 8)),
SQLITE_CONSTRAINT_VTAB = (SQLITE_CONSTRAINT | (9 << 8)),
SQLITE_CONSTRAINT_ROWID = (SQLITE_CONSTRAINT |(10 << 8)),
SQLITE_NOTICE_RECOVER_WAL = (SQLITE_NOTICE | (1 << 8)),
SQLITE_NOTICE_RECOVER_ROLLBACK = (SQLITE_NOTICE | (2 << 8)),
SQLITE_WARNING_AUTOINDEX = (SQLITE_WARNING | (1 << 8)),
SQLITE_AUTH_USER = (SQLITE_AUTH | (1 << 8))
}

/**
Expand Down Expand Up @@ -1182,7 +1182,7 @@ int sqlite3_key_v2(

/**
** Change the key on an open database. If the current database is not
** encrypted, this routine will encrypt it. If pNew==0 or nNew==0, the
** encrypted, this routine will encrypt it. If pNew == 0 or nNew == 0, the
** database is decrypted.
**
** The code to implement this API is not available in the public release
Expand Down
3 changes: 3 additions & 0 deletions posix.mak
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,9 @@ style: ../dscanner/dsc
@echo "Enforce space between a .. b"
grep -nrE '[[:alnum:]][.][.][[:alnum:]]|[[:alnum:]] [.][.][[:alnum:]]|[[:alnum:]][.][.] [[:alnum:]]' $$(find . -name '*.d' | grep -vE 'std/string.d|std/uni.d') ; test $$? -eq 1

@echo "Enforce space between binary operators"
grep -nrE "[[:alnum:]](==|!=|<=|<<|>>|>>>|^^)[[:alnum:]]|[[:alnum:]] (==|!=|<=|<<|>>|>>>|^^)[[:alnum:]]|[[:alnum:]](==|!=|<=|<<|>>|>>>|^^) [[:alnum:]]" $$(find . -name '*.d'); test $$? -eq 1

# at the moment libdparse has problems to parse some modules (->excludes)
@echo "Running DScanner"
../dscanner/dsc --config .dscanner.ini --styleCheck $$(find etc std -type f -name '*.d' | grep -vE 'std/traits.d|std/typecons.d') -I.
Expand Down
2 changes: 1 addition & 1 deletion std/algorithm/mutation.d
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ if (isInputRange!InputRange
InputRange range;
fill(range,[1,2]);
foreach (i,value;range.arr)
assert(value == (i%2==0?1:2));
assert(value == (i%2 == 0?1:2));

//test with a input being a "reference forward" range
fill(a, new ReferenceForwardRange!int([8, 9]));
Expand Down
14 changes: 7 additions & 7 deletions std/algorithm/searching.d
Original file line number Diff line number Diff line change
Expand Up @@ -1575,11 +1575,11 @@ if (isInputRange!InputRange &&
{
int[] a1 = [1, 2, 3];
assert(!find ([1, 2, 3], 2).empty);
assert(!find!((a,b)=>a==b)([1, 2, 3], 2).empty);
assert(!find!((a,b)=>a == b)([1, 2, 3], 2).empty);
ubyte[] a2 = [1, 2, 3];
ubyte b2 = 2;
assert(!find ([1, 2, 3], 2).empty);
assert(!find!((a,b)=>a==b)([1, 2, 3], 2).empty);
assert(!find!((a,b)=>a == b)([1, 2, 3], 2).empty);
}

@safe pure unittest
Expand All @@ -1592,11 +1592,11 @@ if (isInputRange!InputRange &&
R r1 = "hello world";
E e1 = 'w';
assert(find ("hello world", 'w') == "world");
assert(find!((a,b)=>a==b)("hello world", 'w') == "world");
assert(find!((a,b)=>a == b)("hello world", 'w') == "world");
R r2 = "日c語";
E e2 = 'c';
assert(find ("日c語", 'c') == "c語");
assert(find!((a,b)=>a==b)("日c語", 'c') == "c語");
assert(find!((a,b)=>a == b)("日c語", 'c') == "c語");
R r3 = "0123456789";
E e3 = 'A';
assert(find ("0123456789", 'A').empty);
Expand All @@ -1605,7 +1605,7 @@ if (isInputRange!InputRange &&
R r4 = "hello world";
E e4 = 'w';
assert(find ("日本語", '') == "本語");
assert(find!((a,b)=>a==b)("日本語", '') == "本語");
assert(find!((a,b)=>a == b)("日本語", '') == "本語");
}
}
}
Expand All @@ -1621,11 +1621,11 @@ if (isInputRange!InputRange &&

int[] a1 = [1, 2, 3];
static assert(find ([1, 2, 3], 2));
static assert(find!((a,b)=>a==b)([1, 2, 3], 2));
static assert(find!((a,b)=>a == b)([1, 2, 3], 2));
ubyte[] a2 = [1, 2, 3];
ubyte b2 = 2;
static assert(find ([1, 2, 3], 2));
static assert(find!((a,b)=>a==b)([1, 2, 3], 2));
static assert(find!((a,b)=>a == b)([1, 2, 3], 2));
}

@safe unittest
Expand Down
2 changes: 1 addition & 1 deletion std/algorithm/setops.d
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ if (ranges.length >= 2 &&
r.popFront();
if (!r.empty) break;

static if (i==0)
static if (i == 0)
empty = true;
else
r = ranges[i].save; // rollover
Expand Down
10 changes: 5 additions & 5 deletions std/algorithm/sorting.d
Original file line number Diff line number Diff line change
Expand Up @@ -2327,7 +2327,7 @@ private template TimSortImpl(alias pred, R)
size_t minRunLength()(size_t n)
{
immutable shift = bsr(n)-5;
auto result = (n>>shift) + !!(n & ~((1<<shift)-1));
auto result = (n >> shift) + !!(n & ~((1 << shift)-1));
return result;
}

Expand Down Expand Up @@ -3955,15 +3955,15 @@ if (isRandomAccessRange!Range && hasLength!Range &&
static if (flag == No.leanRight)
{
// Eliminate the rightmost from the competition
if (lt(r[d], r[c])) r.swapAt(c, d); // c<=d
if (lt(r[d], r[b])) r.swapAt(b, d); // b<=d
if (lt(r[d], r[c])) r.swapAt(c, d); // c <= d
if (lt(r[d], r[b])) r.swapAt(b, d); // b <= d
medianOf!lt(r, a, b, c);
}
else
{
// Eliminate the leftmost from the competition
if (lt(r[b], r[a])) r.swapAt(a, b); // a<=b
if (lt(r[c], r[a])) r.swapAt(a, c); // a<=c
if (lt(r[b], r[a])) r.swapAt(a, b); // a <= b
if (lt(r[c], r[a])) r.swapAt(a, c); // a <= c
medianOf!lt(r, b, c, d);
}
}
Expand Down
10 changes: 5 additions & 5 deletions std/bigint.d
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public:
}
else static if (op=="/")
{
assert(y!=0, "Division by zero");
assert(y != 0, "Division by zero");
static if (T.sizeof <= uint.sizeof)
{
data = BigUint.divInt(data, cast(uint) u);
Expand All @@ -251,7 +251,7 @@ public:
}
else static if (op=="%")
{
assert(y!=0, "Division by zero");
assert(y != 0, "Division by zero");
static if (is(immutable(T) == immutable(long)) || is( immutable(T) == immutable(ulong) ))
{
this %= BigInt(y);
Expand Down Expand Up @@ -424,7 +424,7 @@ public:
auto opBinary(string op, T)(T y) pure nothrow const
if (op == "%" && isIntegral!T)
{
assert(y!=0);
assert(y != 0);

// BigInt % long => long
// BigInt % ulong => BigInt
Expand Down Expand Up @@ -658,7 +658,7 @@ public:
else
{
if (l <= ulong(T.max)+1)
return cast(T)-long(l); // -long.min==long.min
return cast(T)-long(l); // -long.min == long.min
}
}

Expand Down Expand Up @@ -761,7 +761,7 @@ public:
/// ditto
int opCmp(T:BigInt)(const T y) pure nothrow @nogc const
{
if (sign!=y.sign)
if (sign != y.sign)
return sign ? -1 : 1;
immutable cmp = data.opCmp(y.data);
return sign? -cmp: cmp;
Expand Down
2 changes: 1 addition & 1 deletion std/container/array.d
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ $(D r)
assert(i == 1);

//Just to make sure the GC doesn't collect before the above test.
assert(c.dummy ==1);
assert(c.dummy == 1);
}
@system unittest //6998-2
{
Expand Down
8 changes: 4 additions & 4 deletions std/conv.d
Original file line number Diff line number Diff line change
Expand Up @@ -1372,18 +1372,18 @@ if (!isImplicitlyConvertible!(S, T) &&
// Narrowing conversions from enum -> integral should be allowed, but they
// should throw at runtime if the enum value doesn't fit in the target
// type.
enum E1 : ulong { A = 1, B = 1UL<<48, C = 0 }
enum E1 : ulong { A = 1, B = 1UL << 48, C = 0 }
assert(to!int(E1.A) == 1);
assert(to!bool(E1.A) == true);
assertThrown!ConvOverflowException(to!int(E1.B)); // E1.B overflows int
assertThrown!ConvOverflowException(to!bool(E1.B)); // E1.B overflows bool
assert(to!bool(E1.C) == false);

enum E2 : long { A = -1L<<48, B = -1<<31, C = 1<<31 }
enum E2 : long { A = -1L << 48, B = -1 << 31, C = 1 << 31 }
assertThrown!ConvOverflowException(to!int(E2.A)); // E2.A overflows int
assertThrown!ConvOverflowException(to!uint(E2.B)); // E2.B overflows uint
assert(to!int(E2.B) == -1<<31); // but does not overflow int
assert(to!int(E2.C) == 1<<31); // E2.C does not overflow int
assert(to!int(E2.B) == -1 << 31); // but does not overflow int
assert(to!int(E2.C) == 1 << 31); // E2.C does not overflow int

enum E3 : int { A = -1, B = 1, C = 255, D = 0 }
assertThrown!ConvOverflowException(to!ubyte(E3.A));
Expand Down
2 changes: 1 addition & 1 deletion std/datetime.d
Original file line number Diff line number Diff line change
Expand Up @@ -21384,7 +21384,7 @@ private:
Date(2010, 9, 12),
Date(2010, 10, 1)
).fwdRange(
everyDayOfWeek!Date(DayOfWeek.fri), Yes.popFirst).front ==Date(2010, 9, 17));
everyDayOfWeek!Date(DayOfWeek.fri), Yes.popFirst).front == Date(2010, 9, 17));
}

//Verify Examples.
Expand Down
12 changes: 6 additions & 6 deletions std/digest/sha.d
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ struct SHA(uint hashBlockSize, uint digestSize)
static assert(!(blockSize == 1024 && digestSize < 224),
"Invalid SHA digestSize for a blockSize of 1024. The digestSize must be 224, 256, 384 or 512.");

static if (digestSize==160) /* SHA-1 */
static if (digestSize == 160) /* SHA-1 */
{
version(USE_SSSE3)
{
Expand Down Expand Up @@ -636,7 +636,7 @@ struct SHA(uint hashBlockSize, uint digestSize)
T_SHA2_16_79!Word(62, W, C, D, E, F, G, H, A, B, constants[62]);
T_SHA2_16_79!Word(63, W, B, C, D, E, F, G, H, A, constants[63]);

static if (is(Word==ulong))
static if (is(Word == ulong))
{
T_SHA2_16_79!Word(64, W, A, B, C, D, E, F, G, H, constants[64]);
T_SHA2_16_79!Word(65, W, H, A, B, C, D, E, F, G, constants[65]);
Expand Down Expand Up @@ -706,9 +706,9 @@ struct SHA(uint hashBlockSize, uint digestSize)
index = (cast(uint) count[0] >> 3) & (blockSizeInBytes - 1);

/* Update number of bits */
static if (blockSize==512)
static if (blockSize == 512)
count[0] += inputLen * 8;
else static if (blockSize==1024)
else static if (blockSize == 1024)
{
/* ugly hack to work around lack of ucent */
auto oldCount0 = count[0];
Expand Down Expand Up @@ -756,7 +756,7 @@ struct SHA(uint hashBlockSize, uint digestSize)
*/
ubyte[digestSize/8] finish() @trusted pure nothrow @nogc
{
static if (blockSize==512)
static if (blockSize == 512)
{
ubyte[32] data = void;
uint index, padLen;
Expand All @@ -780,7 +780,7 @@ struct SHA(uint hashBlockSize, uint digestSize)
start();
return data[0 .. digestSize/8];
}
else static if (blockSize==1024)
else static if (blockSize == 1024)
{
ubyte[64] data = void;
uint index, padLen;
Expand Down
4 changes: 2 additions & 2 deletions std/encoding.d
Original file line number Diff line number Diff line change
Expand Up @@ -3339,11 +3339,11 @@ version(unittest)
{
void transcodeReverse(Src,Dst)(immutable(Src)[] s, out immutable(Dst)[] r)
{
static if (is(Src==Dst))
static if (is(Src == Dst))
{
return s;
}
else static if (is(Src==AsciiChar))
else static if (is(Src == AsciiChar))
{
transcodeReverse!(char,Dst)(cast(string) s,r);
}
Expand Down
Loading

0 comments on commit 22331db

Please sign in to comment.