Merge pull request #4 from hvitved/csharp/whitespaces

C#: Fix whitespaces
This commit is contained in:
calumgrant
2018-08-03 16:06:47 +01:00
committed by GitHub
38 changed files with 199 additions and 176 deletions

23
csharp/fix-whitespaces.sh Executable file
View File

@@ -0,0 +1,23 @@
BASEDIR=$(dirname "$0")
cat > "$BASEDIR/reformat.vim" <<"EOF"
:set ff=unix ts=2 et
:retab!
:%s/\r//g
:%s/ \+$//
:wq
EOF
find "$BASEDIR" \( -name "*.ql" -or -name "*.qll" -or -name "*.csv" \) -exec vim -u /dev/null -s reformat.vim {} \;
cat > reformat.vim <<"EOF"
:set ff=unix ts=4 et
:retab!
:%s/\r//g
:%s/ \+$//
:wq
EOF
find "$BASEDIR" \( -name "*.cs" \) -exec vim -u /dev/null -s reformat.vim {} \;
rm "$BASEDIR/reformat.vim"

View File

@@ -19,7 +19,7 @@ import semmle.code.csharp.commons.StructuralComparison as SC
/** A structural comparison configuration for comparing the conditions of nested `for` loops. */ /** A structural comparison configuration for comparing the conditions of nested `for` loops. */
class NestedForConditions extends SC::StructuralComparisonConfiguration { class NestedForConditions extends SC::StructuralComparisonConfiguration {
NestedForConditions() { this = "Compare nested for conditions" } NestedForConditions() { this = "Compare nested for conditions" }
override predicate candidate(Element e1, Element e2) { override predicate candidate(Element e1, Element e2) {
exists(NestedForLoopSameVariable nested | exists(NestedForLoopSameVariable nested |
e1 = nested.getInnerForStmt().getCondition() and e1 = nested.getInnerForStmt().getCondition() and

View File

@@ -62,7 +62,7 @@ abstract class UnbracedControlStmt extends Stmt
getSuccessorStmt() = result getSuccessorStmt() = result
and getBlockStmt(this) = getBlockStmt(result) and getBlockStmt(this) = getBlockStmt(result)
} }
private Location getBodyLocation() { private Location getBodyLocation() {
result = getBody().getLocation() result = getBody().getLocation()
} }

View File

@@ -14,4 +14,4 @@ public static void foo(int count)
} }
timesLeft--; timesLeft--;
} }
} }

View File

@@ -15,4 +15,4 @@ import csharp
from Callable c from Callable c
where c.isSourceDeclaration() where c.isSourceDeclaration()
select c, c.getCyclomaticComplexity() as n select c, c.getCyclomaticComplexity() as n
order by n desc order by n desc

View File

@@ -14,4 +14,4 @@ import csharp
from Callable c from Callable c
where c.isSourceDeclaration() where c.isSourceDeclaration()
select c, c.getNumberOfLinesOfCode() as n select c, c.getNumberOfLinesOfCode() as n
order by n desc order by n desc

View File

@@ -14,4 +14,4 @@ import csharp
from Callable c from Callable c
where c.isSourceDeclaration() where c.isSourceDeclaration()
select c, c.getNumberOfLinesOfComments() as n select c, c.getNumberOfLinesOfComments() as n
order by n desc order by n desc

View File

@@ -13,7 +13,7 @@ import csharp
from Callable c, int n from Callable c, int n
where c.isSourceDeclaration() where c.isSourceDeclaration()
and n = count(Stmt s | s.getEnclosingCallable() = c and n = count(Stmt s | s.getEnclosingCallable() = c
and s != c.getAChild()) // we do not count the top-level block and s != c.getAChild()) // we do not count the top-level block
select c, n select c, n
order by n desc order by n desc

View File

@@ -13,4 +13,4 @@ import csharp
from Callable f, int loc from Callable f, int loc
where f.isSourceDeclaration() and loc = f.getNumberOfLines() and loc > 0 where f.isSourceDeclaration() and loc = f.getNumberOfLines() and loc > 0
select f, 100.0 * ((float)f.getNumberOfLinesOfComments() / (float)loc) select f, 100.0 * ((float)f.getNumberOfLinesOfComments() / (float)loc)

View File

@@ -12,4 +12,4 @@ public void printCharacterCodes(string[] strings)
} }
} }
} }
} }

View File

@@ -16,4 +16,4 @@ public static void Main(string[] args)
PrintAllCharInts(s); PrintAllCharInts(s);
} }
} }
} }

View File

@@ -18,4 +18,4 @@ int f(int i, int j) {
} }
return result; return result;
// end // end
} }

View File

@@ -10,14 +10,14 @@
* @tags maintainability * @tags maintainability
* documentation * documentation
*/ */
import csharp import csharp
from SourceFile f, int n from SourceFile f, int n
where n = count(CommentLine line | where n = count(CommentLine line |
exists(CommentBlock block | exists(CommentBlock block |
block.getLocation().getFile() = f and block.getLocation().getFile() = f and
line = block.getAProbableCodeLine()) line = block.getAProbableCodeLine())
) )
select f, n select f, n
order by n desc order by n desc

View File

@@ -15,10 +15,10 @@ import external.CodeDuplication
from SourceFile f, int n from SourceFile f, int n
where n = count(int line | where n = count(int line |
exists(DuplicateBlock d | d.sourceFile() = f | exists(DuplicateBlock d | d.sourceFile() = f |
line in [d.sourceStartLine()..d.sourceEndLine()] and line in [d.sourceStartLine()..d.sourceEndLine()] and
not whitelistedLineForDuplication(f, line) not whitelistedLineForDuplication(f, line)
) )
) )
select f, n select f, n
order by n desc order by n desc

View File

@@ -15,4 +15,4 @@ import semmle.code.csharp.frameworks.Test
from SourceFile f, int n from SourceFile f, int n
where n = strictcount(TestMethod test | test.fromSource() and test.getFile() = f) where n = strictcount(TestMethod test | test.fromSource() and test.getFile() = f)
select f, n select f, n
order by n desc order by n desc

View File

@@ -15,16 +15,16 @@ import semmle.code.csharp.metrics.Coupling
/* Self-containedness on file level */ /* Self-containedness on file level */
from File f, float selfContaindness, int efferentSourceCoupling, int efferentCoupling from File f, float selfContaindness, int efferentSourceCoupling, int efferentCoupling
where efferentSourceCoupling = count(File g| where efferentSourceCoupling = count(File g|
exists(RefType c| c.fromSource() and c.getFile() = g and exists(RefType c| c.fromSource() and c.getFile() = g and
exists(RefType d| d.fromSource() and d.getFile()= f and depends(d,c)) exists(RefType d| d.fromSource() and d.getFile()= f and depends(d,c))
) )
) )
and efferentCoupling = count(File g| and efferentCoupling = count(File g|
exists(RefType c| c.getFile() = g and exists(RefType c| c.getFile() = g and
exists(RefType d| d.fromSource() and d.getFile() = f and depends(d,c)) exists(RefType d| d.fromSource() and d.getFile() = f and depends(d,c))
) )
) )
and if efferentCoupling = 0 then selfContaindness = 100 else and if efferentCoupling = 0 then selfContaindness = 100 else
selfContaindness = 100*(float)efferentSourceCoupling/efferentCoupling selfContaindness = 100*(float)efferentSourceCoupling/efferentCoupling

View File

@@ -11,7 +11,7 @@ import csharp
import external.VCS import external.VCS
int committedFiles(Commit commit) { int committedFiles(Commit commit) {
result = count(commit.getAnAffectedFile()) result = count(commit.getAnAffectedFile())
} }
from File f from File f

View File

@@ -11,16 +11,16 @@ import csharp
import external.VCS import external.VCS
predicate inRange(Commit first, Commit second) { predicate inRange(Commit first, Commit second) {
first.getAnAffectedFile() = second.getAnAffectedFile() and first.getAnAffectedFile() = second.getAnAffectedFile() and
first != second and first != second and
exists(int n | n = first.getDate().daysTo(second.getDate()) and exists(int n | n = first.getDate().daysTo(second.getDate()) and
n >= 0 and n < 5) n >= 0 and n < 5)
} }
int recommitsForFile(File f) { int recommitsForFile(File f) {
result = count(Commit recommit | result = count(Commit recommit |
f = recommit.getAnAffectedFile() and f = recommit.getAnAffectedFile() and
exists(Commit prev | inRange(prev, recommit))) exists(Commit prev | inRange(prev, recommit)))
} }
from File f from File f

View File

@@ -13,4 +13,4 @@ import external.VCS
from File f, int n from File f, int n
where n = count(Commit e | e.getAnAffectedFile() = f and e.daysToNow() <= 180 and not artificialChange(e)) where n = count(Commit e | e.getAnAffectedFile() = f and e.daysToNow() <= 180 and not artificialChange(e))
select f, n select f, n
order by n desc order by n desc

View File

@@ -12,4 +12,4 @@ abstract class ShortRedBook : RedBook { /* ... */ }
abstract class LongBlueBook : BlueBook { /* ... */ } abstract class LongBlueBook : BlueBook { /* ... */ }
abstract class ShortBlueBook : BlueBook { /* ... */ } abstract class ShortBlueBook : BlueBook { /* ... */ }
class ShortBlueNovel : ShortBlueBook { /* ... */ } class ShortBlueNovel : ShortBlueBook { /* ... */ }
// ... // ...

View File

@@ -14,4 +14,4 @@ import csharp
from ValueOrRefType t from ValueOrRefType t
where t.isSourceDeclaration() where t.isSourceDeclaration()
select t, t.getInheritanceDepth() as n select t, t.getInheritanceDepth() as n
order by n desc order by n desc

View File

@@ -15,4 +15,4 @@ class Book
{ {
// ... // ...
} }
} }

View File

@@ -33,4 +33,4 @@ class TLackOfCohesionCK
var5 = 1; var5 = 1;
Console.WriteLine(var5); Console.WriteLine(var5);
} }
} }

View File

@@ -33,4 +33,4 @@ class TLackOfCohesionCK
var5 = 1; var5 = 1;
Console.WriteLine(var5); Console.WriteLine(var5);
} }
} }

View File

@@ -22,4 +22,4 @@ class HTTPRequest
HTTPRequestResponseEndEvent(this, new HTTPRequestResponseEndArgs()); HTTPRequestResponseEndEvent(this, new HTTPRequestResponseEndArgs());
HTTPRequestResponseProcessedEvent(this, new HTTPRequestResponseProcessedArgs()); HTTPRequestResponseProcessedEvent(this, new HTTPRequestResponseProcessedArgs());
} }
} }

View File

@@ -20,4 +20,4 @@ class HTTPRequest
HTTPRequestStateChangeEvent(this, new HTTPRequestStateChangeArgs("responseend")); HTTPRequestStateChangeEvent(this, new HTTPRequestStateChangeArgs("responseend"));
HTTPRequestStateChangeEvent(this, new HTTPRequestStateChangeArgs("responseprocessed")); HTTPRequestStateChangeEvent(this, new HTTPRequestStateChangeArgs("responseprocessed"));
} }
} }

View File

@@ -9,4 +9,4 @@ class Person
private string town; private string town;
private string postcode; private string postcode;
// ... // ...
} }

View File

@@ -19,4 +19,4 @@ class Address
private string town; private string town;
private string postcode; private string postcode;
// ... // ...
} }

View File

@@ -9,4 +9,4 @@ class Person
private string town; private string town;
private string postcode; private string postcode;
// ... // ...
} }

View File

@@ -11,10 +11,10 @@ import csharp
from ValueOrRefType t, int n from ValueOrRefType t, int n
where where
t.isSourceDeclaration() t.isSourceDeclaration()
and n = count(Field f | and n = count(Field f |
f.getDeclaringType() = t f.getDeclaringType() = t
and not(f instanceof MemberConstant) and not(f instanceof MemberConstant)
) )
select t, n select t, n
order by n desc order by n desc

View File

@@ -19,4 +19,4 @@ class Address
private string town; private string town;
private string postcode; private string postcode;
// ... // ...
} }

View File

@@ -44,4 +44,4 @@ class Person
} }
} }
// more properties... // more properties...
} }

View File

@@ -59,4 +59,4 @@ class Name
_firstName = firstUC + value.Substring(1); _firstName = firstUC + value.Substring(1);
} }
} }
} }

View File

@@ -11,8 +11,8 @@
import csharp import csharp
from ValueOrRefType t, int n from ValueOrRefType t, int n
where t.isSourceDeclaration() where t.isSourceDeclaration()
and n = count(Stmt s | s.getEnclosingCallable().getDeclaringType() = t and n = count(Stmt s | s.getEnclosingCallable().getDeclaringType() = t
and s != s.getEnclosingCallable().getAChild()) // we do not count the top-level block and s != s.getEnclosingCallable().getAChild()) // we do not count the top-level block
select t, n select t, n
order by n desc order by n desc

View File

@@ -6,9 +6,9 @@ public partial class UnmanagedCodeExample : Form
{ {
[DllImport("User32.dll")] [DllImport("User32.dll")]
public static extern int MessageBox(int h, string m, string c, int type); // violation public static extern int MessageBox(int h, string m, string c, int type); // violation
private void btnSayHello_Click(object sender, EventArgs e) private void btnSayHello_Click(object sender, EventArgs e)
{ {
MessageBox(0, "Hello World", "Title", 0); MessageBox(0, "Hello World", "Title", 0);
} }
} }

View File

@@ -7,4 +7,4 @@ public partial class ManagedCodeExample : Form
{ {
MessageBox.Show("Hello World", "Title"); MessageBox.Show("Hello World", "Title");
} }
} }

View File

@@ -1,15 +1,15 @@
using System; using System;
class NestedLoopsSameVariable class NestedLoopsSameVariable
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
for (int j = 0; j < 2; i++) for (int j = 0; j < 2; i++)
{ {
Console.WriteLine(i + " " + j); Console.WriteLine(i + " " + j);
} }
} }
} }
} }

View File

@@ -1,100 +1,100 @@
using System; using System;
class Test class Test
{ {
void SameCondition() void SameCondition()
{ {
for (int i=0; i<10; ++i) for (int i=0; i<10; ++i)
{ {
// GOOD: Same condition // GOOD: Same condition
for (; i<10; ++i) for (; i<10; ++i)
{ {
Console.WriteLine(i); Console.WriteLine(i);
} }
} }
} }
void DifferentCondition1() void DifferentCondition1()
{ {
for (int i=0; i<10; ++i) for (int i=0; i<10; ++i)
{ {
// BAD: considered to be a different condition // BAD: considered to be a different condition
for (; 10>i; ++i) for (; 10>i; ++i)
{ {
Console.WriteLine(i); Console.WriteLine(i);
} }
} }
} }
void DifferentCondition2() void DifferentCondition2()
{ {
for (int i=0; i<10; ++i) for (int i=0; i<10; ++i)
{ {
// BAD: different condition // BAD: different condition
for (; i<9; ++i) for (; i<9; ++i)
{ {
Console.WriteLine(i); Console.WriteLine(i);
} }
} }
} }
void DifferentConditions3() void DifferentConditions3()
{ {
for (int i=0; i<10; ++i) for (int i=0; i<10; ++i)
{ {
// BAD: different condition // BAD: different condition
for (; i<=10; ++i) for (; i<=10; ++i)
{ {
Console.WriteLine(i); Console.WriteLine(i);
} }
} }
} }
void UseAfterInnerLoop() void UseAfterInnerLoop()
{ {
for (int i=0; i<10; ++i) for (int i=0; i<10; ++i)
{ {
for (; i<10; ++i) for (; i<10; ++i)
{ {
} }
// BAD: i is not guarded // BAD: i is not guarded
Console.WriteLine(i); Console.WriteLine(i);
} }
} }
void GuardedAfterInnerLoop() void GuardedAfterInnerLoop()
{ {
for (int i=0; i<10; ++i) for (int i=0; i<10; ++i)
{ {
// GOOD: same condition // GOOD: same condition
for (; i<10; ++i) for (; i<10; ++i)
{ {
} }
if (10 > i) if (10 > i)
{ {
// GOOD: i is guarded // GOOD: i is guarded
Console.WriteLine(i); Console.WriteLine(i);
} }
} }
} }
void GuardedByContinue() void GuardedByContinue()
{ {
for (int i=0; i<10; ++i) for (int i=0; i<10; ++i)
{ {
// GOOD: same condition // GOOD: same condition
for (; i<10; ++i) for (; i<10; ++i)
{ {
} }
if (10 <= i) continue; if (10 <= i) continue;
// GOOD: i is guarded // GOOD: i is guarded
Console.WriteLine(i); Console.WriteLine(i);
} }
} }
} }