Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C#: Fix whitespaces #4

Merged
merged 2 commits into from
Aug 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions csharp/fix-whitespaces.sh
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion csharp/ql/src/Likely Bugs/NestedLoopsSameVariable.ql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion csharp/ql/src/Likely Bugs/Statements/UseBraces.ql
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ abstract class UnbracedControlStmt extends Stmt
getSuccessorStmt() = result
and getBlockStmt(this) = getBlockStmt(result)
}

private Location getBodyLocation() {
result = getBody().getLocation()
}
Expand Down
2 changes: 1 addition & 1 deletion csharp/ql/src/Metrics/Callables/CCyclomaticComplexity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ public static void foo(int count)
}
timesLeft--;
}
}
}
2 changes: 1 addition & 1 deletion csharp/ql/src/Metrics/Callables/CCyclomaticComplexity.ql
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion csharp/ql/src/Metrics/Callables/CLinesOfCode.ql
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion csharp/ql/src/Metrics/Callables/CLinesOfComment.ql
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion csharp/ql/src/Metrics/Callables/CNumberOfStatements.ql
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion csharp/ql/src/Metrics/Callables/CPercentageOfComments.ql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion csharp/ql/src/Metrics/Callables/StatementNestingDepth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ public void printCharacterCodes(string[] strings)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ public static void Main(string[] args)
PrintAllCharInts(s);
}
}
}
}
2 changes: 1 addition & 1 deletion csharp/ql/src/Metrics/Files/FCyclomaticComplexity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ int f(int i, int j) {
}
return result;
// end
}
}
8 changes: 4 additions & 4 deletions csharp/ql/src/Metrics/Files/FLinesOfCommentedCode.ql
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 6 additions & 6 deletions csharp/ql/src/Metrics/Files/FLinesOfDuplicatedCode.ql
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion csharp/ql/src/Metrics/Files/FNumberOfTests.ql
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 6 additions & 6 deletions csharp/ql/src/Metrics/Files/FSelfContainedness.ql
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion csharp/ql/src/Metrics/History/HNumberOfCoCommits.ql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import csharp
import external.VCS

int committedFiles(Commit commit) {
result = count(commit.getAnAffectedFile())
result = count(commit.getAnAffectedFile())
}

from File f
Expand Down
14 changes: 7 additions & 7 deletions csharp/ql/src/Metrics/History/HNumberOfReCommits.ql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion csharp/ql/src/Metrics/History/HNumberOfRecentChanges.ql
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion csharp/ql/src/Metrics/RefTypes/TInheritanceDepth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ abstract class ShortRedBook : RedBook { /* ... */ }
abstract class LongBlueBook : BlueBook { /* ... */ }
abstract class ShortBlueBook : BlueBook { /* ... */ }
class ShortBlueNovel : ShortBlueBook { /* ... */ }
// ...
// ...
2 changes: 1 addition & 1 deletion csharp/ql/src/Metrics/RefTypes/TInheritanceDepth.ql
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion csharp/ql/src/Metrics/RefTypes/TInheritanceDepthFix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ public void read()
{
// ...
}
}
}
2 changes: 1 addition & 1 deletion csharp/ql/src/Metrics/RefTypes/TLackOfCohesionCK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ public void methodE()
var5 = 1;
Console.WriteLine(var5);
}
}
}
2 changes: 1 addition & 1 deletion csharp/ql/src/Metrics/RefTypes/TLackOfCohesionHS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ public void methodE()
var5 = 1;
Console.WriteLine(var5);
}
}
}
2 changes: 1 addition & 1 deletion csharp/ql/src/Metrics/RefTypes/TNumberOfEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ public void send()
HTTPRequestResponseEndEvent(this, new HTTPRequestResponseEndArgs());
HTTPRequestResponseProcessedEvent(this, new HTTPRequestResponseProcessedArgs());
}
}
}
2 changes: 1 addition & 1 deletion csharp/ql/src/Metrics/RefTypes/TNumberOfEventsFix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ public void send()
HTTPRequestStateChangeEvent(this, new HTTPRequestStateChangeArgs("responseend"));
HTTPRequestStateChangeEvent(this, new HTTPRequestStateChangeArgs("responseprocessed"));
}
}
}
2 changes: 1 addition & 1 deletion csharp/ql/src/Metrics/RefTypes/TNumberOfFields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ class Person
private string town;
private string postcode;
// ...
}
}
2 changes: 1 addition & 1 deletion csharp/ql/src/Metrics/RefTypes/TNumberOfFieldsFix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ class Address
private string town;
private string postcode;
// ...
}
}
2 changes: 1 addition & 1 deletion csharp/ql/src/Metrics/RefTypes/TNumberOfNonConstFields.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ class Person
private string town;
private string postcode;
// ...
}
}
12 changes: 6 additions & 6 deletions csharp/ql/src/Metrics/RefTypes/TNumberOfNonConstFields.ql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ class Address
private string town;
private string postcode;
// ...
}
}
2 changes: 1 addition & 1 deletion csharp/ql/src/Metrics/RefTypes/TNumberOfProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ public string lastName
}
}
// more properties...
}
}
2 changes: 1 addition & 1 deletion csharp/ql/src/Metrics/RefTypes/TNumberOfPropertiesFix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ public string lastName
_firstName = firstUC + value.Substring(1);
}
}
}
}
4 changes: 2 additions & 2 deletions csharp/ql/src/Metrics/RefTypes/TNumberOfStatements.ql
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions csharp/ql/src/Metrics/RefTypes/TUnmanagedCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion csharp/ql/src/Metrics/RefTypes/TUnmanagedCodeFix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ private void btnSayHello_Click(object sender, EventArgs e)
{
MessageBox.Show("Hello World", "Title");
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
Loading