D-Scanner icon indicating copy to clipboard operation
D-Scanner copied to clipboard

Improve the unnecessary parentheses checker

Open wilzbach opened this issue 8 years ago • 2 comments

A good example is return (42); or (foo) ? bar : foobar - both aren't found by Dscanner atm.

For the first one, there are many example to be found in Phobos (only lists the first 30 hits):

> grep "return *(" **/*.d
etc/c/odbc/sql.d:bool SQL_SUCCEEDED()(uint rc) { return (rc & ~1U) == 0; }
etc/c/odbc/sqlext.d:    return ( ( -1 * length ) + cast(uint) SQL_LEN_DATA_AT_EXEC_OFFSET );
etc/c/odbc/sqlext.d:    return ( ( -1 * length ) + cast(uint) SQL_LEN_BINARY_ATTR_OFFSET );
std/algorithm/iteration.d:        return ( (x + 4.0) * (x + 1.0) * (x - 1.0) * (x - 3.0) ) / 14.0 + 0.5;
std/algorithm/iteration.d:    return (((cast(F) r[ 0] + r[ 1]) + (cast(F) r[ 2] + r[ 3]))
std/algorithm/sorting.d:    static bool even(int a) { return (a & 1) == 0; }
std/algorithm/sorting.d:    static bool even(int a) { return (a & 1) == 0; }
std/algorithm/sorting.d:        return (cast(T*) malloc(nbytes))[0 .. len];
std/algorithm/sorting.d:    topN!((a, b){ return (*a)[1] < (*b)[1]; })(idx, mid);
std/array.d:        return (() @trusted => cast(E[]) result)();
std/array.d:        return (() @trusted => cast(RetType) result)();
std/array.d:            return (() @trusted => cast(RetType) result)();
std/array.d:        return (() @trusted => cast(RetType) result)();
std/ascii.d:    return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
std/base64.d:            return (sourceLength / 3) * 4 + (sourceLength % 3 == 0 ? 0 : sourceLength % 3 == 1 ? 2 : 3);
std/base64.d:            return (sourceLength / 3 + (sourceLength % 3 ? 1 : 0)) * 4;
std/base64.d:            return (sourceLength / 4) * 3 + (sourceLength % 4 < 2 ? 0 : sourceLength % 4 == 2 ? 1 : 2);
std/base64.d:            return (sourceLength / 4) * 3;
std/bigint.d:        return (sign ? -1 : 1) *
std/bigint.d:        return (sign ? -1 : 1) *
std/bitmanip.d:        return (size_t(1) << endBits) - 1;
std/bitmanip.d:        return (len + (bitsPerSizeT-1)) / bitsPerSizeT;
std/bitmanip.d:        return (p1[i] & endMask) == (p2[i] & endMask);
std/bitmanip.d:        return (this.length > a2.length) - (this.length < a2.length);
std/bitmanip.d:        return (upper << (bitsPerSizeT - nbits)) | (lower >> nbits);
std/bitmanip.d:        return (upper << nbits) | (lower >> (bitsPerSizeT - nbits));
std/bitmanip.d:    return ((val & 0xff00U) >> 8) |
std/container/dlist.d:        return (cast(inout(DList!T.PayNode)*)&this)._payload;
std/container/dlist.d:        return (new PayNode(BaseNode(prev, next), arg)).asBaseNode();
std/conv.d:        return () @system {

wilzbach avatar Feb 23 '17 01:02 wilzbach

The purpose of that checker is to find things like ((a)), not (a), so I think this is more of an enhancement request than a bug. Also, a lot of those examples are false positives. Were you showing those to show the need for D-Scanner to do the check instead of a regex?

Hackerpilot avatar Feb 23 '17 22:02 Hackerpilot

I think this is more of an enhancement request than a bug

Yes.

Were you showing those [examples with false positives] to show the need for D-Scanner to do the check instead of a regex?

Yes ;-)

wilzbach avatar Feb 24 '17 05:02 wilzbach