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. */
class NestedForConditions extends SC::StructuralComparisonConfiguration {
NestedForConditions() { this = "Compare nested for conditions" }
override predicate candidate(Element e1, Element e2) {
exists(NestedForLoopSameVariable nested |
e1 = nested.getInnerForStmt().getCondition() and

View File

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

View File

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

View File

@@ -15,4 +15,4 @@ import csharp
from Callable c
where c.isSourceDeclaration()
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
where c.isSourceDeclaration()
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
where c.isSourceDeclaration()
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
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
select c, n
order by n desc

View File

@@ -13,4 +13,4 @@ import csharp
from Callable f, int loc
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);
}
}
}
}

View File

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

View File

@@ -10,14 +10,14 @@
* @tags maintainability
* documentation
*/
import csharp
from SourceFile f, int n
where n = count(CommentLine line |
exists(CommentBlock block |
where n = count(CommentLine line |
exists(CommentBlock block |
block.getLocation().getFile() = f and
line = block.getAProbableCodeLine())
)
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
where n = count(int line |
exists(DuplicateBlock d | d.sourceFile() = f |
line in [d.sourceStartLine()..d.sourceEndLine()] and
not whitelistedLineForDuplication(f, line)
)
)
exists(DuplicateBlock d | d.sourceFile() = f |
line in [d.sourceStartLine()..d.sourceEndLine()] and
not whitelistedLineForDuplication(f, line)
)
)
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
where n = strictcount(TestMethod test | test.fromSource() and test.getFile() = f)
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 */
from File f, float selfContaindness, int efferentSourceCoupling, int efferentCoupling
where efferentSourceCoupling = count(File g|
exists(RefType c| c.fromSource() and c.getFile() = g and
where efferentSourceCoupling = count(File g|
exists(RefType c| c.fromSource() and c.getFile() = g and
exists(RefType d| d.fromSource() and d.getFile()= f and depends(d,c))
)
)
and efferentCoupling = count(File g|
exists(RefType c| c.getFile() = g and
)
and efferentCoupling = count(File g|
exists(RefType c| c.getFile() = g and
exists(RefType d| d.fromSource() and d.getFile() = f and depends(d,c))
)
)
)
and if efferentCoupling = 0 then selfContaindness = 100 else
selfContaindness = 100*(float)efferentSourceCoupling/efferentCoupling

View File

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

View File

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

View File

@@ -13,4 +13,4 @@ import external.VCS
from File f, int n
where n = count(Commit e | e.getAnAffectedFile() = f and e.daysToNow() <= 180 and not artificialChange(e))
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 ShortBlueBook : BlueBook { /* ... */ }
class ShortBlueNovel : ShortBlueBook { /* ... */ }
// ...
// ...

View File

@@ -14,4 +14,4 @@ import csharp
from ValueOrRefType t
where t.isSourceDeclaration()
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;
Console.WriteLine(var5);
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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