From 6b2d99b6ac6ca579bcad79fe317fd5aec5c4c82d Mon Sep 17 00:00:00 2001 From: Tom Hvitved Date: Fri, 3 Aug 2018 14:10:22 +0200 Subject: [PATCH 1/2] C#: Add script for fixing whitespaces --- csharp/fix-whitespaces.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 csharp/fix-whitespaces.sh diff --git a/csharp/fix-whitespaces.sh b/csharp/fix-whitespaces.sh new file mode 100755 index 00000000000..d18bf7453d4 --- /dev/null +++ b/csharp/fix-whitespaces.sh @@ -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" From 5d498fda72b9f0fdab540b6b8cbf634180038c47 Mon Sep 17 00:00:00 2001 From: Tom Hvitved Date: Fri, 3 Aug 2018 14:10:44 +0200 Subject: [PATCH 2/2] C#: Fix whitespaces --- .../Likely Bugs/NestedLoopsSameVariable.ql | 2 +- .../src/Likely Bugs/Statements/UseBraces.ql | 2 +- .../Callables/CCyclomaticComplexity.cs | 2 +- .../Callables/CCyclomaticComplexity.ql | 2 +- .../ql/src/Metrics/Callables/CLinesOfCode.ql | 2 +- .../src/Metrics/Callables/CLinesOfComment.ql | 2 +- .../Metrics/Callables/CNumberOfStatements.ql | 2 +- .../Callables/CPercentageOfComments.ql | 2 +- .../Callables/StatementNestingDepth.cs | 2 +- .../Callables/StatementNestingDepthFix.cs | 2 +- .../Metrics/Files/FCyclomaticComplexity.cs | 2 +- .../Metrics/Files/FLinesOfCommentedCode.ql | 8 +- .../Metrics/Files/FLinesOfDuplicatedCode.ql | 12 +- csharp/ql/src/Metrics/Files/FNumberOfTests.ql | 2 +- .../src/Metrics/Files/FSelfContainedness.ql | 12 +- .../src/Metrics/History/HNumberOfCoCommits.ql | 2 +- .../src/Metrics/History/HNumberOfReCommits.ql | 14 +- .../Metrics/History/HNumberOfRecentChanges.ql | 2 +- .../src/Metrics/RefTypes/TInheritanceDepth.cs | 2 +- .../src/Metrics/RefTypes/TInheritanceDepth.ql | 2 +- .../Metrics/RefTypes/TInheritanceDepthFix.cs | 2 +- .../src/Metrics/RefTypes/TLackOfCohesionCK.cs | 2 +- .../src/Metrics/RefTypes/TLackOfCohesionHS.cs | 2 +- .../src/Metrics/RefTypes/TNumberOfEvents.cs | 2 +- .../Metrics/RefTypes/TNumberOfEventsFix.cs | 2 +- .../src/Metrics/RefTypes/TNumberOfFields.cs | 2 +- .../Metrics/RefTypes/TNumberOfFieldsFix.cs | 2 +- .../RefTypes/TNumberOfNonConstFields.cs | 2 +- .../RefTypes/TNumberOfNonConstFields.ql | 12 +- .../RefTypes/TNumberOfNonConstFieldsFix.cs | 2 +- .../Metrics/RefTypes/TNumberOfProperties.cs | 2 +- .../RefTypes/TNumberOfPropertiesFix.cs | 2 +- .../Metrics/RefTypes/TNumberOfStatements.ql | 4 +- .../ql/src/Metrics/RefTypes/TUnmanagedCode.cs | 4 +- .../src/Metrics/RefTypes/TUnmanagedCodeFix.cs | 2 +- .../NestedLoopsSameVariable.cs | 30 +-- .../NestedLoopsSameVariable/Test.cs | 200 +++++++++--------- 37 files changed, 176 insertions(+), 176 deletions(-) diff --git a/csharp/ql/src/Likely Bugs/NestedLoopsSameVariable.ql b/csharp/ql/src/Likely Bugs/NestedLoopsSameVariable.ql index 0918ca1849c..e23770cb266 100644 --- a/csharp/ql/src/Likely Bugs/NestedLoopsSameVariable.ql +++ b/csharp/ql/src/Likely Bugs/NestedLoopsSameVariable.ql @@ -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 diff --git a/csharp/ql/src/Likely Bugs/Statements/UseBraces.ql b/csharp/ql/src/Likely Bugs/Statements/UseBraces.ql index 0900ff25133..fd3348c7dcd 100755 --- a/csharp/ql/src/Likely Bugs/Statements/UseBraces.ql +++ b/csharp/ql/src/Likely Bugs/Statements/UseBraces.ql @@ -62,7 +62,7 @@ abstract class UnbracedControlStmt extends Stmt getSuccessorStmt() = result and getBlockStmt(this) = getBlockStmt(result) } - + private Location getBodyLocation() { result = getBody().getLocation() } diff --git a/csharp/ql/src/Metrics/Callables/CCyclomaticComplexity.cs b/csharp/ql/src/Metrics/Callables/CCyclomaticComplexity.cs index e59743d1691..aad2bbd2d21 100644 --- a/csharp/ql/src/Metrics/Callables/CCyclomaticComplexity.cs +++ b/csharp/ql/src/Metrics/Callables/CCyclomaticComplexity.cs @@ -14,4 +14,4 @@ public static void foo(int count) } timesLeft--; } -} \ No newline at end of file +} diff --git a/csharp/ql/src/Metrics/Callables/CCyclomaticComplexity.ql b/csharp/ql/src/Metrics/Callables/CCyclomaticComplexity.ql index bf78f5d3173..78c32ab1041 100644 --- a/csharp/ql/src/Metrics/Callables/CCyclomaticComplexity.ql +++ b/csharp/ql/src/Metrics/Callables/CCyclomaticComplexity.ql @@ -15,4 +15,4 @@ import csharp from Callable c where c.isSourceDeclaration() select c, c.getCyclomaticComplexity() as n -order by n desc \ No newline at end of file +order by n desc diff --git a/csharp/ql/src/Metrics/Callables/CLinesOfCode.ql b/csharp/ql/src/Metrics/Callables/CLinesOfCode.ql index 8c4f1539de4..8e8674adce0 100644 --- a/csharp/ql/src/Metrics/Callables/CLinesOfCode.ql +++ b/csharp/ql/src/Metrics/Callables/CLinesOfCode.ql @@ -14,4 +14,4 @@ import csharp from Callable c where c.isSourceDeclaration() select c, c.getNumberOfLinesOfCode() as n -order by n desc \ No newline at end of file +order by n desc diff --git a/csharp/ql/src/Metrics/Callables/CLinesOfComment.ql b/csharp/ql/src/Metrics/Callables/CLinesOfComment.ql index c7d7b6714e1..f2b29ee039b 100644 --- a/csharp/ql/src/Metrics/Callables/CLinesOfComment.ql +++ b/csharp/ql/src/Metrics/Callables/CLinesOfComment.ql @@ -14,4 +14,4 @@ import csharp from Callable c where c.isSourceDeclaration() select c, c.getNumberOfLinesOfComments() as n -order by n desc \ No newline at end of file +order by n desc diff --git a/csharp/ql/src/Metrics/Callables/CNumberOfStatements.ql b/csharp/ql/src/Metrics/Callables/CNumberOfStatements.ql index 97d38764670..e77cf3791e6 100644 --- a/csharp/ql/src/Metrics/Callables/CNumberOfStatements.ql +++ b/csharp/ql/src/Metrics/Callables/CNumberOfStatements.ql @@ -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 diff --git a/csharp/ql/src/Metrics/Callables/CPercentageOfComments.ql b/csharp/ql/src/Metrics/Callables/CPercentageOfComments.ql index 51aa87bee31..75ea0cd7408 100644 --- a/csharp/ql/src/Metrics/Callables/CPercentageOfComments.ql +++ b/csharp/ql/src/Metrics/Callables/CPercentageOfComments.ql @@ -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) \ No newline at end of file +select f, 100.0 * ((float)f.getNumberOfLinesOfComments() / (float)loc) diff --git a/csharp/ql/src/Metrics/Callables/StatementNestingDepth.cs b/csharp/ql/src/Metrics/Callables/StatementNestingDepth.cs index 7fc19dee897..fe145442ade 100644 --- a/csharp/ql/src/Metrics/Callables/StatementNestingDepth.cs +++ b/csharp/ql/src/Metrics/Callables/StatementNestingDepth.cs @@ -12,4 +12,4 @@ public void printCharacterCodes(string[] strings) } } } -} \ No newline at end of file +} diff --git a/csharp/ql/src/Metrics/Callables/StatementNestingDepthFix.cs b/csharp/ql/src/Metrics/Callables/StatementNestingDepthFix.cs index da80e8afae7..103d8c2c208 100644 --- a/csharp/ql/src/Metrics/Callables/StatementNestingDepthFix.cs +++ b/csharp/ql/src/Metrics/Callables/StatementNestingDepthFix.cs @@ -16,4 +16,4 @@ public static void Main(string[] args) PrintAllCharInts(s); } } -} \ No newline at end of file +} diff --git a/csharp/ql/src/Metrics/Files/FCyclomaticComplexity.cs b/csharp/ql/src/Metrics/Files/FCyclomaticComplexity.cs index 5a09f4d78c6..0c017780cdb 100644 --- a/csharp/ql/src/Metrics/Files/FCyclomaticComplexity.cs +++ b/csharp/ql/src/Metrics/Files/FCyclomaticComplexity.cs @@ -18,4 +18,4 @@ int f(int i, int j) { } return result; // end -} \ No newline at end of file +} diff --git a/csharp/ql/src/Metrics/Files/FLinesOfCommentedCode.ql b/csharp/ql/src/Metrics/Files/FLinesOfCommentedCode.ql index fe105592d4a..c19219623d9 100644 --- a/csharp/ql/src/Metrics/Files/FLinesOfCommentedCode.ql +++ b/csharp/ql/src/Metrics/Files/FLinesOfCommentedCode.ql @@ -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 \ No newline at end of file +order by n desc diff --git a/csharp/ql/src/Metrics/Files/FLinesOfDuplicatedCode.ql b/csharp/ql/src/Metrics/Files/FLinesOfDuplicatedCode.ql index 311ab14ec34..ab4a1e9151a 100644 --- a/csharp/ql/src/Metrics/Files/FLinesOfDuplicatedCode.ql +++ b/csharp/ql/src/Metrics/Files/FLinesOfDuplicatedCode.ql @@ -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 \ No newline at end of file +order by n desc diff --git a/csharp/ql/src/Metrics/Files/FNumberOfTests.ql b/csharp/ql/src/Metrics/Files/FNumberOfTests.ql index 18977820bd9..deb12556cc3 100644 --- a/csharp/ql/src/Metrics/Files/FNumberOfTests.ql +++ b/csharp/ql/src/Metrics/Files/FNumberOfTests.ql @@ -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 \ No newline at end of file +order by n desc diff --git a/csharp/ql/src/Metrics/Files/FSelfContainedness.ql b/csharp/ql/src/Metrics/Files/FSelfContainedness.ql index 3768eb47c4b..c96ce5946ba 100644 --- a/csharp/ql/src/Metrics/Files/FSelfContainedness.ql +++ b/csharp/ql/src/Metrics/Files/FSelfContainedness.ql @@ -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 diff --git a/csharp/ql/src/Metrics/History/HNumberOfCoCommits.ql b/csharp/ql/src/Metrics/History/HNumberOfCoCommits.ql index 9d6eba12fe6..12afb811e57 100644 --- a/csharp/ql/src/Metrics/History/HNumberOfCoCommits.ql +++ b/csharp/ql/src/Metrics/History/HNumberOfCoCommits.ql @@ -11,7 +11,7 @@ import csharp import external.VCS int committedFiles(Commit commit) { - result = count(commit.getAnAffectedFile()) + result = count(commit.getAnAffectedFile()) } from File f diff --git a/csharp/ql/src/Metrics/History/HNumberOfReCommits.ql b/csharp/ql/src/Metrics/History/HNumberOfReCommits.ql index 2848b252c45..7ea70d450a7 100644 --- a/csharp/ql/src/Metrics/History/HNumberOfReCommits.ql +++ b/csharp/ql/src/Metrics/History/HNumberOfReCommits.ql @@ -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 diff --git a/csharp/ql/src/Metrics/History/HNumberOfRecentChanges.ql b/csharp/ql/src/Metrics/History/HNumberOfRecentChanges.ql index b52445ae147..7a40b773a98 100644 --- a/csharp/ql/src/Metrics/History/HNumberOfRecentChanges.ql +++ b/csharp/ql/src/Metrics/History/HNumberOfRecentChanges.ql @@ -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 \ No newline at end of file +order by n desc diff --git a/csharp/ql/src/Metrics/RefTypes/TInheritanceDepth.cs b/csharp/ql/src/Metrics/RefTypes/TInheritanceDepth.cs index 6f056dc2a3d..65a44c101c2 100644 --- a/csharp/ql/src/Metrics/RefTypes/TInheritanceDepth.cs +++ b/csharp/ql/src/Metrics/RefTypes/TInheritanceDepth.cs @@ -12,4 +12,4 @@ abstract class ShortRedBook : RedBook { /* ... */ } abstract class LongBlueBook : BlueBook { /* ... */ } abstract class ShortBlueBook : BlueBook { /* ... */ } class ShortBlueNovel : ShortBlueBook { /* ... */ } -// ... \ No newline at end of file +// ... diff --git a/csharp/ql/src/Metrics/RefTypes/TInheritanceDepth.ql b/csharp/ql/src/Metrics/RefTypes/TInheritanceDepth.ql index 87d190fd014..fb96f7edd22 100644 --- a/csharp/ql/src/Metrics/RefTypes/TInheritanceDepth.ql +++ b/csharp/ql/src/Metrics/RefTypes/TInheritanceDepth.ql @@ -14,4 +14,4 @@ import csharp from ValueOrRefType t where t.isSourceDeclaration() select t, t.getInheritanceDepth() as n -order by n desc \ No newline at end of file +order by n desc diff --git a/csharp/ql/src/Metrics/RefTypes/TInheritanceDepthFix.cs b/csharp/ql/src/Metrics/RefTypes/TInheritanceDepthFix.cs index 51a0d44d7e1..19a1a2e6a8c 100644 --- a/csharp/ql/src/Metrics/RefTypes/TInheritanceDepthFix.cs +++ b/csharp/ql/src/Metrics/RefTypes/TInheritanceDepthFix.cs @@ -15,4 +15,4 @@ class Book { // ... } -} \ No newline at end of file +} diff --git a/csharp/ql/src/Metrics/RefTypes/TLackOfCohesionCK.cs b/csharp/ql/src/Metrics/RefTypes/TLackOfCohesionCK.cs index 4dcf1915c36..68be46c96d4 100644 --- a/csharp/ql/src/Metrics/RefTypes/TLackOfCohesionCK.cs +++ b/csharp/ql/src/Metrics/RefTypes/TLackOfCohesionCK.cs @@ -33,4 +33,4 @@ class TLackOfCohesionCK var5 = 1; Console.WriteLine(var5); } -} \ No newline at end of file +} diff --git a/csharp/ql/src/Metrics/RefTypes/TLackOfCohesionHS.cs b/csharp/ql/src/Metrics/RefTypes/TLackOfCohesionHS.cs index 4dcf1915c36..68be46c96d4 100644 --- a/csharp/ql/src/Metrics/RefTypes/TLackOfCohesionHS.cs +++ b/csharp/ql/src/Metrics/RefTypes/TLackOfCohesionHS.cs @@ -33,4 +33,4 @@ class TLackOfCohesionCK var5 = 1; Console.WriteLine(var5); } -} \ No newline at end of file +} diff --git a/csharp/ql/src/Metrics/RefTypes/TNumberOfEvents.cs b/csharp/ql/src/Metrics/RefTypes/TNumberOfEvents.cs index 96028f460d8..aa867aadc68 100644 --- a/csharp/ql/src/Metrics/RefTypes/TNumberOfEvents.cs +++ b/csharp/ql/src/Metrics/RefTypes/TNumberOfEvents.cs @@ -22,4 +22,4 @@ class HTTPRequest HTTPRequestResponseEndEvent(this, new HTTPRequestResponseEndArgs()); HTTPRequestResponseProcessedEvent(this, new HTTPRequestResponseProcessedArgs()); } -} \ No newline at end of file +} diff --git a/csharp/ql/src/Metrics/RefTypes/TNumberOfEventsFix.cs b/csharp/ql/src/Metrics/RefTypes/TNumberOfEventsFix.cs index f6e02a74fd5..ed348250090 100644 --- a/csharp/ql/src/Metrics/RefTypes/TNumberOfEventsFix.cs +++ b/csharp/ql/src/Metrics/RefTypes/TNumberOfEventsFix.cs @@ -20,4 +20,4 @@ class HTTPRequest HTTPRequestStateChangeEvent(this, new HTTPRequestStateChangeArgs("responseend")); HTTPRequestStateChangeEvent(this, new HTTPRequestStateChangeArgs("responseprocessed")); } -} \ No newline at end of file +} diff --git a/csharp/ql/src/Metrics/RefTypes/TNumberOfFields.cs b/csharp/ql/src/Metrics/RefTypes/TNumberOfFields.cs index db68633ec6a..42b33b4396d 100644 --- a/csharp/ql/src/Metrics/RefTypes/TNumberOfFields.cs +++ b/csharp/ql/src/Metrics/RefTypes/TNumberOfFields.cs @@ -9,4 +9,4 @@ class Person private string town; private string postcode; // ... -} \ No newline at end of file +} diff --git a/csharp/ql/src/Metrics/RefTypes/TNumberOfFieldsFix.cs b/csharp/ql/src/Metrics/RefTypes/TNumberOfFieldsFix.cs index 80bc230ca01..15a23c0dc4a 100644 --- a/csharp/ql/src/Metrics/RefTypes/TNumberOfFieldsFix.cs +++ b/csharp/ql/src/Metrics/RefTypes/TNumberOfFieldsFix.cs @@ -19,4 +19,4 @@ class Address private string town; private string postcode; // ... -} \ No newline at end of file +} diff --git a/csharp/ql/src/Metrics/RefTypes/TNumberOfNonConstFields.cs b/csharp/ql/src/Metrics/RefTypes/TNumberOfNonConstFields.cs index db68633ec6a..42b33b4396d 100644 --- a/csharp/ql/src/Metrics/RefTypes/TNumberOfNonConstFields.cs +++ b/csharp/ql/src/Metrics/RefTypes/TNumberOfNonConstFields.cs @@ -9,4 +9,4 @@ class Person private string town; private string postcode; // ... -} \ No newline at end of file +} diff --git a/csharp/ql/src/Metrics/RefTypes/TNumberOfNonConstFields.ql b/csharp/ql/src/Metrics/RefTypes/TNumberOfNonConstFields.ql index 888772b395d..9ffaed48f94 100644 --- a/csharp/ql/src/Metrics/RefTypes/TNumberOfNonConstFields.ql +++ b/csharp/ql/src/Metrics/RefTypes/TNumberOfNonConstFields.ql @@ -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 \ No newline at end of file +order by n desc diff --git a/csharp/ql/src/Metrics/RefTypes/TNumberOfNonConstFieldsFix.cs b/csharp/ql/src/Metrics/RefTypes/TNumberOfNonConstFieldsFix.cs index 80bc230ca01..15a23c0dc4a 100644 --- a/csharp/ql/src/Metrics/RefTypes/TNumberOfNonConstFieldsFix.cs +++ b/csharp/ql/src/Metrics/RefTypes/TNumberOfNonConstFieldsFix.cs @@ -19,4 +19,4 @@ class Address private string town; private string postcode; // ... -} \ No newline at end of file +} diff --git a/csharp/ql/src/Metrics/RefTypes/TNumberOfProperties.cs b/csharp/ql/src/Metrics/RefTypes/TNumberOfProperties.cs index 7a9998b3ffa..eb851e44046 100644 --- a/csharp/ql/src/Metrics/RefTypes/TNumberOfProperties.cs +++ b/csharp/ql/src/Metrics/RefTypes/TNumberOfProperties.cs @@ -44,4 +44,4 @@ class Person } } // more properties... -} \ No newline at end of file +} diff --git a/csharp/ql/src/Metrics/RefTypes/TNumberOfPropertiesFix.cs b/csharp/ql/src/Metrics/RefTypes/TNumberOfPropertiesFix.cs index 0f628bb8feb..fc9c1d1f0c3 100644 --- a/csharp/ql/src/Metrics/RefTypes/TNumberOfPropertiesFix.cs +++ b/csharp/ql/src/Metrics/RefTypes/TNumberOfPropertiesFix.cs @@ -59,4 +59,4 @@ class Name _firstName = firstUC + value.Substring(1); } } -} \ No newline at end of file +} diff --git a/csharp/ql/src/Metrics/RefTypes/TNumberOfStatements.ql b/csharp/ql/src/Metrics/RefTypes/TNumberOfStatements.ql index 09123e4b19d..1961b5d6288 100644 --- a/csharp/ql/src/Metrics/RefTypes/TNumberOfStatements.ql +++ b/csharp/ql/src/Metrics/RefTypes/TNumberOfStatements.ql @@ -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 diff --git a/csharp/ql/src/Metrics/RefTypes/TUnmanagedCode.cs b/csharp/ql/src/Metrics/RefTypes/TUnmanagedCode.cs index 655fd1e4ca9..be1ad368bbc 100644 --- a/csharp/ql/src/Metrics/RefTypes/TUnmanagedCode.cs +++ b/csharp/ql/src/Metrics/RefTypes/TUnmanagedCode.cs @@ -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); } -} \ No newline at end of file +} diff --git a/csharp/ql/src/Metrics/RefTypes/TUnmanagedCodeFix.cs b/csharp/ql/src/Metrics/RefTypes/TUnmanagedCodeFix.cs index ceff0cb2467..c065d2d2a26 100644 --- a/csharp/ql/src/Metrics/RefTypes/TUnmanagedCodeFix.cs +++ b/csharp/ql/src/Metrics/RefTypes/TUnmanagedCodeFix.cs @@ -7,4 +7,4 @@ public partial class ManagedCodeExample : Form { MessageBox.Show("Hello World", "Title"); } -} \ No newline at end of file +} diff --git a/csharp/ql/test/query-tests/Likely Bugs/NestedLoopsSameVariable/NestedLoopsSameVariable.cs b/csharp/ql/test/query-tests/Likely Bugs/NestedLoopsSameVariable/NestedLoopsSameVariable.cs index 19d3f0f4cde..cd01795f202 100644 --- a/csharp/ql/test/query-tests/Likely Bugs/NestedLoopsSameVariable/NestedLoopsSameVariable.cs +++ b/csharp/ql/test/query-tests/Likely Bugs/NestedLoopsSameVariable/NestedLoopsSameVariable.cs @@ -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); + } + } + } +} diff --git a/csharp/ql/test/query-tests/Likely Bugs/NestedLoopsSameVariable/Test.cs b/csharp/ql/test/query-tests/Likely Bugs/NestedLoopsSameVariable/Test.cs index 9bc334bdafb..7b08cd2c914 100644 --- a/csharp/ql/test/query-tests/Likely Bugs/NestedLoopsSameVariable/Test.cs +++ b/csharp/ql/test/query-tests/Likely Bugs/NestedLoopsSameVariable/Test.cs @@ -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); + } + } +}