diff --git a/CHANGES.md b/CHANGES.md index 39a14b91..cc3735a8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,7 +1,7 @@ ## dev branch / next version (2.x.x) - New command line option `-show-parser-errors` to include parser errors into checkstyle results (default: off) [#413](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/413) -- Added more checks for automatic coding style detection [#414](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/414) +- Added more checks for automatic coding style detection [#414](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/414) + [#417](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/417) - Fixed handling of `Arrow` in type names in TokenTree [#413](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/413) - Fixed handling of `Dot` after `KwdNew` in TokenTree [#413](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/413) - Fixed line number reported for MethodCount check [#415](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/415) diff --git a/src/checkstyle/checks/coding/HiddenFieldCheck.hx b/src/checkstyle/checks/coding/HiddenFieldCheck.hx index cb6ece24..3f4867d5 100644 --- a/src/checkstyle/checks/coding/HiddenFieldCheck.hx +++ b/src/checkstyle/checks/coding/HiddenFieldCheck.hx @@ -128,4 +128,18 @@ class HiddenFieldCheck extends Check { } return memberNames; } + + override public function detectableInstances():DetectableInstances { + return [{ + fixed: [], + properties: [{ + propertyName: "ignoreConstructorParameter", + values: [true, false] + }, + { + propertyName: "ignoreSetter", + values: [true, false] + }] + }]; + } } \ No newline at end of file diff --git a/src/checkstyle/checks/coding/InnerAssignmentCheck.hx b/src/checkstyle/checks/coding/InnerAssignmentCheck.hx index aa102b18..d5812475 100644 --- a/src/checkstyle/checks/coding/InnerAssignmentCheck.hx +++ b/src/checkstyle/checks/coding/InnerAssignmentCheck.hx @@ -105,4 +105,14 @@ class InnerAssignmentCheck extends Check { return false; } + + override public function detectableInstances():DetectableInstances { + return [{ + fixed: [], + properties: [{ + propertyName: "ignoreReturnAssignments", + values: [false, true] + }] + }]; + } } \ No newline at end of file diff --git a/src/checkstyle/checks/coding/NestedForDepthCheck.hx b/src/checkstyle/checks/coding/NestedForDepthCheck.hx index 53bff309..4b31b5f2 100644 --- a/src/checkstyle/checks/coding/NestedForDepthCheck.hx +++ b/src/checkstyle/checks/coding/NestedForDepthCheck.hx @@ -51,4 +51,14 @@ class NestedForDepthCheck extends Check { function warnNestedForDepth(depth:Int, pos:Position) { logPos('Nested for depth is $depth (max allowed is ${max})', pos); } + + override public function detectableInstances():DetectableInstances { + return [{ + fixed: [], + properties: [{ + propertyName: "max", + values: [for (i in 1...5) i] + }] + }]; + } } \ No newline at end of file diff --git a/src/checkstyle/checks/coding/NestedIfDepthCheck.hx b/src/checkstyle/checks/coding/NestedIfDepthCheck.hx index 3c7cd60d..04a419a9 100644 --- a/src/checkstyle/checks/coding/NestedIfDepthCheck.hx +++ b/src/checkstyle/checks/coding/NestedIfDepthCheck.hx @@ -50,4 +50,14 @@ class NestedIfDepthCheck extends Check { function warnNestedIfDepth(depth:Int, pos:Position) { logPos('Nested if-else depth is $depth (max allowed is ${max})', pos); } + + override public function detectableInstances():DetectableInstances { + return [{ + fixed: [], + properties: [{ + propertyName: "max", + values: [for (i in 1...10) i] + }] + }]; + } } \ No newline at end of file diff --git a/src/checkstyle/checks/coding/NestedTryDepthCheck.hx b/src/checkstyle/checks/coding/NestedTryDepthCheck.hx index ebb09d0f..724eb417 100644 --- a/src/checkstyle/checks/coding/NestedTryDepthCheck.hx +++ b/src/checkstyle/checks/coding/NestedTryDepthCheck.hx @@ -56,4 +56,14 @@ class NestedTryDepthCheck extends Check { function warnNestedTryDepth(depth:Int, pos:Position) { logPos('Nested try depth is $depth (max allowed is ${max})', pos); } + + override public function detectableInstances():DetectableInstances { + return [{ + fixed: [], + properties: [{ + propertyName: "max", + values: [for (i in 1...5) i] + }] + }]; + } } \ No newline at end of file diff --git a/src/checkstyle/checks/coding/NullableParameterCheck.hx b/src/checkstyle/checks/coding/NullableParameterCheck.hx index a8362bd4..4e63a75d 100644 --- a/src/checkstyle/checks/coding/NullableParameterCheck.hx +++ b/src/checkstyle/checks/coding/NullableParameterCheck.hx @@ -39,6 +39,16 @@ class NullableParameterCheck extends Check { function formatArguments(opt:Bool, name:String, nullDefault:Bool):String { return '"' + (opt ? "?" : "") + name + (nullDefault ? " = null" : "") + '"'; } + + override public function detectableInstances():DetectableInstances { + return [{ + fixed: [], + properties: [{ + propertyName: "option", + values: [QUESTION_MARK, NULL_DEFAULT] + }] + }]; + } } @:enum diff --git a/src/checkstyle/checks/coding/ReturnCountCheck.hx b/src/checkstyle/checks/coding/ReturnCountCheck.hx index c2aa6b1a..d3490cfa 100644 --- a/src/checkstyle/checks/coding/ReturnCountCheck.hx +++ b/src/checkstyle/checks/coding/ReturnCountCheck.hx @@ -45,4 +45,14 @@ class ReturnCountCheck extends Check { default: GO_DEEPER; } } + + override public function detectableInstances():DetectableInstances { + return [{ + fixed: [], + properties: [{ + propertyName: "max", + values: [for (i in 2...20) i] + }] + }]; + } } \ No newline at end of file diff --git a/src/checkstyle/checks/coding/TraceCheck.hx b/src/checkstyle/checks/coding/TraceCheck.hx index b4a90acd..78d7b545 100644 --- a/src/checkstyle/checks/coding/TraceCheck.hx +++ b/src/checkstyle/checks/coding/TraceCheck.hx @@ -34,7 +34,7 @@ class TraceCheck extends Check { fixed: [], properties: [{ propertyName: "severity", - values: ["INFO"] + values: [SeverityLevel.INFO] }] }]; } diff --git a/src/checkstyle/checks/coding/UnusedLocalVarCheck.hx b/src/checkstyle/checks/coding/UnusedLocalVarCheck.hx index 557670cf..aba4ce17 100644 --- a/src/checkstyle/checks/coding/UnusedLocalVarCheck.hx +++ b/src/checkstyle/checks/coding/UnusedLocalVarCheck.hx @@ -97,4 +97,14 @@ class UnusedLocalVarCheck extends Check { } return GO_DEEPER; } + + override public function detectableInstances():DetectableInstances { + return [{ + fixed: [], + properties: [{ + propertyName: "severity", + values: [SeverityLevel.INFO] + }] + }]; + } } \ No newline at end of file diff --git a/src/checkstyle/checks/design/EmptyPackageCheck.hx b/src/checkstyle/checks/design/EmptyPackageCheck.hx index afe3c44a..c4bb175f 100644 --- a/src/checkstyle/checks/design/EmptyPackageCheck.hx +++ b/src/checkstyle/checks/design/EmptyPackageCheck.hx @@ -26,4 +26,14 @@ class EmptyPackageCheck extends Check { if (firstChild.is(Semicolon)) logRange("Found empty package", entry.pos.min, firstChild.pos.max); } } + + override public function detectableInstances():DetectableInstances { + return [{ + fixed: [], + properties: [{ + propertyName: "enforceEmptyPackage", + values: [true, false] + }] + }]; + } } \ No newline at end of file diff --git a/src/checkstyle/checks/design/InterfaceCheck.hx b/src/checkstyle/checks/design/InterfaceCheck.hx index 17223983..4e8f11c3 100644 --- a/src/checkstyle/checks/design/InterfaceCheck.hx +++ b/src/checkstyle/checks/design/InterfaceCheck.hx @@ -30,4 +30,18 @@ class InterfaceCheck extends Check { if (!allowProperties && vars.length > 0) logPos("Properties are not allowed in interfaces", intr.pos); } } + + override public function detectableInstances():DetectableInstances { + return [{ + fixed: [], + properties: [{ + propertyName: "allowMarkerInterfaces", + values: [true, false] + }, + { + propertyName: "allowProperties", + values: [true, false] + }] + }]; + } } \ No newline at end of file diff --git a/src/checkstyle/checks/design/UnnecessaryConstructorCheck.hx b/src/checkstyle/checks/design/UnnecessaryConstructorCheck.hx index fe6d0d45..ea77e441 100644 --- a/src/checkstyle/checks/design/UnnecessaryConstructorCheck.hx +++ b/src/checkstyle/checks/design/UnnecessaryConstructorCheck.hx @@ -53,4 +53,14 @@ class UnnecessaryConstructorCheck extends Check { } return false; } + + override public function detectableInstances():DetectableInstances { + return [{ + fixed: [], + properties: [{ + propertyName: "severity", + values: [SeverityLevel.INFO] + }] + }]; + } } \ No newline at end of file diff --git a/src/checkstyle/checks/imports/AvoidStarImportCheck.hx b/src/checkstyle/checks/imports/AvoidStarImportCheck.hx index 434fbe7c..162af094 100644 --- a/src/checkstyle/checks/imports/AvoidStarImportCheck.hx +++ b/src/checkstyle/checks/imports/AvoidStarImportCheck.hx @@ -28,7 +28,7 @@ class AvoidStarImportCheck extends Check { fixed: [], properties: [{ propertyName: "severity", - values: ["INFO"] + values: [SeverityLevel.INFO] }] }]; } diff --git a/src/checkstyle/checks/imports/UnusedImportCheck.hx b/src/checkstyle/checks/imports/UnusedImportCheck.hx index 7e314260..728b17d6 100644 --- a/src/checkstyle/checks/imports/UnusedImportCheck.hx +++ b/src/checkstyle/checks/imports/UnusedImportCheck.hx @@ -181,4 +181,14 @@ class UnusedImportCheck extends Check { } return typeName == identName; } + + override public function detectableInstances():DetectableInstances { + return [{ + fixed: [], + properties: [{ + propertyName: "severity", + values: [SeverityLevel.INFO] + }] + }]; + } } \ No newline at end of file diff --git a/src/checkstyle/checks/type/AnonymousCheck.hx b/src/checkstyle/checks/type/AnonymousCheck.hx index 3039cde5..99536255 100644 --- a/src/checkstyle/checks/type/AnonymousCheck.hx +++ b/src/checkstyle/checks/type/AnonymousCheck.hx @@ -50,7 +50,7 @@ class AnonymousCheck extends Check { fixed: [], properties: [{ propertyName: "severity", - values: ["INFO"] + values: [SeverityLevel.INFO] }] }]; } diff --git a/src/checkstyle/checks/type/DynamicCheck.hx b/src/checkstyle/checks/type/DynamicCheck.hx index 847a10f7..0ad14e99 100644 --- a/src/checkstyle/checks/type/DynamicCheck.hx +++ b/src/checkstyle/checks/type/DynamicCheck.hx @@ -35,7 +35,7 @@ class DynamicCheck extends Check { fixed: [], properties: [{ propertyName: "severity", - values: ["INFO"] + values: [SeverityLevel.INFO] }] }]; } diff --git a/src/checkstyle/checks/type/TypeCheck.hx b/src/checkstyle/checks/type/TypeCheck.hx index a650da31..3a37d856 100644 --- a/src/checkstyle/checks/type/TypeCheck.hx +++ b/src/checkstyle/checks/type/TypeCheck.hx @@ -33,7 +33,7 @@ class TypeCheck extends Check { fixed: [], properties: [{ propertyName: "severity", - values: ["INFO"] + values: [SeverityLevel.INFO] }] }]; } diff --git a/src/checkstyle/detect/DetectCodingStyle.hx b/src/checkstyle/detect/DetectCodingStyle.hx index 581a5bdb..f9b06d56 100644 --- a/src/checkstyle/detect/DetectCodingStyle.hx +++ b/src/checkstyle/detect/DetectCodingStyle.hx @@ -5,11 +5,13 @@ import checkstyle.Checker; import checkstyle.checks.Check; import checkstyle.utils.ConfigUtils; import checkstyle.reporter.ReporterManager; +import haxe.ds.ArraySort; class DetectCodingStyle { public static function detectCodingStyle(checks:Array, fileList:Array):Array { var detectedChecks:Array = []; + ArraySort.sort(checks, ConfigUtils.checkSort); for (check in checks) detectCheck(check, detectedChecks, fileList); return detectedChecks; diff --git a/src/checkstyle/utils/ConfigUtils.hx b/src/checkstyle/utils/ConfigUtils.hx index b7f29ebb..65f5ca2d 100644 --- a/src/checkstyle/utils/ConfigUtils.hx +++ b/src/checkstyle/utils/ConfigUtils.hx @@ -42,12 +42,18 @@ class ConfigUtils { file.close(); } - public static function checkConfigSort(a:CheckConfig, b:CheckConfig):Int { + public static function checkConfigSort(a:CheckConfig, b:CheckConfig):Int { if (a.type == b.type) return 0; if (a.type < b.type) return -1; return 1; } + public static function checkSort(a:Check, b:Check):Int { + if (a.getModuleName() == b.getModuleName()) return 0; + if (a.getModuleName() < b.getModuleName()) return -1; + return 1; + } + public static function makeCheckConfig(check:Check):CheckConfig { var propsNotAllowed:Array = [ "moduleName", "severity", "type", "categories", diff --git a/test/detect/DetectCodingStyleTest.hx b/test/detect/DetectCodingStyleTest.hx index 4a62eb08..b2e052a9 100644 --- a/test/detect/DetectCodingStyleTest.hx +++ b/test/detect/DetectCodingStyleTest.hx @@ -8,9 +8,21 @@ import checkstyle.SeverityLevel; import checkstyle.checks.block.ConditionalCompilationCheck; import checkstyle.checks.block.LeftCurlyCheck; import checkstyle.checks.block.RightCurlyCheck; +import checkstyle.checks.coding.HiddenFieldCheck; +import checkstyle.checks.coding.InnerAssignmentCheck; +import checkstyle.checks.coding.NestedForDepthCheck; +import checkstyle.checks.coding.NestedIfDepthCheck; +import checkstyle.checks.coding.NestedTryDepthCheck; +import checkstyle.checks.coding.NullableParameterCheck; +import checkstyle.checks.coding.ReturnCountCheck; import checkstyle.checks.coding.TraceCheck; +import checkstyle.checks.coding.UnusedLocalVarCheck; +import checkstyle.checks.design.EmptyPackageCheck; +import checkstyle.checks.design.InterfaceCheck; +import checkstyle.checks.design.UnnecessaryConstructorCheck; import checkstyle.checks.comments.TODOCommentCheck; import checkstyle.checks.imports.AvoidStarImportCheck; +import checkstyle.checks.imports.UnusedImportCheck; import checkstyle.checks.literal.StringLiteralCheck; import checkstyle.checks.metrics.CyclomaticComplexityCheck; import checkstyle.checks.modifier.RedundantModifierCheck; @@ -78,6 +90,68 @@ class DetectCodingStyleTest { } // checkstyle.checks.coding + @Test + public function testDetectHiddenField() { + var detectedChecks:Array = DetectCodingStyle.detectCodingStyle([new HiddenFieldCheck()], [buildCheckFile(SAMPLE_CODING_STYLE)]); + Assert.areEqual(1, detectedChecks.length); + Assert.areEqual("HiddenField", detectedChecks[0].type); + var props = cast detectedChecks[0].props; + Assert.isFalse(props.ignoreSetter); + Assert.isTrue(props.ignoreConstructorParameter); + } + + @Test + public function testDetectInnerAssignment() { + var detectedChecks:Array = DetectCodingStyle.detectCodingStyle([new InnerAssignmentCheck()], [buildCheckFile(SAMPLE_CODING_STYLE)]); + // ignored not enough data points + Assert.areEqual(0, detectedChecks.length); + } + + @Test + public function testDetectNestedForDepth() { + var detectedChecks:Array = DetectCodingStyle.detectCodingStyle([new NestedForDepthCheck()], [buildCheckFile(SAMPLE_CODING_STYLE)]); + Assert.areEqual(1, detectedChecks.length); + Assert.areEqual("NestedForDepth", detectedChecks[0].type); + var props = cast detectedChecks[0].props; + Assert.areEqual(2, props.max); + } + + @Test + public function testDetectNestedIfDepth() { + var detectedChecks:Array = DetectCodingStyle.detectCodingStyle([new NestedIfDepthCheck()], [buildCheckFile(SAMPLE_CODING_STYLE)]); + Assert.areEqual(1, detectedChecks.length); + Assert.areEqual("NestedIfDepth", detectedChecks[0].type); + var props = cast detectedChecks[0].props; + Assert.areEqual(2, props.max); + } + + @Test + public function testDetectNestedTryDepth() { + var detectedChecks:Array = DetectCodingStyle.detectCodingStyle([new NestedTryDepthCheck()], [buildCheckFile(SAMPLE_CODING_STYLE)]); + Assert.areEqual(1, detectedChecks.length); + Assert.areEqual("NestedTryDepth", detectedChecks[0].type); + var props = cast detectedChecks[0].props; + Assert.areEqual(2, props.max); + } + + @Test + public function testDetectNullableParameter() { + var detectedChecks:Array = DetectCodingStyle.detectCodingStyle([new NullableParameterCheck()], [buildCheckFile(SAMPLE_CODING_STYLE)]); + Assert.areEqual(1, detectedChecks.length); + Assert.areEqual("NullableParameter", detectedChecks[0].type); + var props = cast detectedChecks[0].props; + Assert.areEqual("questionMark", props.option); + } + + @Test + public function testDetectReturnCount() { + var detectedChecks:Array = DetectCodingStyle.detectCodingStyle([new ReturnCountCheck()], [buildCheckFile(SAMPLE_CODING_STYLE)]); + Assert.areEqual(1, detectedChecks.length); + Assert.areEqual("ReturnCount", detectedChecks[0].type); + var props = cast detectedChecks[0].props; + Assert.areEqual(10, props.max); + } + @Test public function testDetectTrace() { var detectedChecks:Array = DetectCodingStyle.detectCodingStyle([new TraceCheck()], [buildCheckFile(SAMPLE_CODING_STYLE)]); @@ -85,6 +159,13 @@ class DetectCodingStyleTest { Assert.areEqual("Trace", detectedChecks[0].type); } + @Test + public function testDetectUnusedLocalVar() { + var detectedChecks:Array = DetectCodingStyle.detectCodingStyle([new UnusedLocalVarCheck()], [buildCheckFile(SAMPLE_CODING_STYLE)]); + Assert.areEqual(1, detectedChecks.length); + Assert.areEqual("UnusedLocalVar", detectedChecks[0].type); + } + // checkstyle.checks.comments @Test public function testDetectTODOComment() { @@ -93,6 +174,33 @@ class DetectCodingStyleTest { Assert.areEqual("TODOComment", detectedChecks[0].type); } + // checkstyle.checks.design + @Test + public function testDetectEmptyPackage() { + var detectedChecks:Array = DetectCodingStyle.detectCodingStyle([new EmptyPackageCheck()], [buildCheckFile(SAMPLE_CODING_STYLE)]); + Assert.areEqual(1, detectedChecks.length); + Assert.areEqual("EmptyPackage", detectedChecks[0].type); + var props = cast detectedChecks[0].props; + Assert.isTrue(props.enforceEmptyPackage); + } + + @Test + public function testDetectInterface() { + var detectedChecks:Array = DetectCodingStyle.detectCodingStyle([new InterfaceCheck()], [buildCheckFile(SAMPLE_CODING_STYLE)]); + Assert.areEqual(1, detectedChecks.length); + Assert.areEqual("Interface", detectedChecks[0].type); + var props = cast detectedChecks[0].props; + Assert.isFalse(props.allowProperties); + Assert.isTrue(props.allowMarkerInterfaces); + } + + @Test + public function testDetectUnnecessaryConstructor() { + var detectedChecks:Array = DetectCodingStyle.detectCodingStyle([new UnnecessaryConstructorCheck()], [buildCheckFile(SAMPLE_CODING_STYLE)]); + Assert.areEqual(1, detectedChecks.length); + Assert.areEqual("UnnecessaryConstructor", detectedChecks[0].type); + } + // checkstyle.checks.imports @Test public function testDetectAvoidStarImport() { @@ -101,6 +209,13 @@ class DetectCodingStyleTest { Assert.areEqual("AvoidStarImport", detectedChecks[0].type); } + @Test + public function testDetectUnusedImport() { + var detectedChecks:Array = DetectCodingStyle.detectCodingStyle([new UnusedImportCheck()], [buildCheckFile(SAMPLE_CODING_STYLE)]); + Assert.areEqual(1, detectedChecks.length); + Assert.areEqual("UnusedImport", detectedChecks[0].type); + } + // checkstyle.checks.literal @Test public function testDetectStringLiteral() { @@ -158,8 +273,10 @@ class DetectCodingStyleTest { @Test public function testDetectLineLength() { var detectedChecks:Array = DetectCodingStyle.detectCodingStyle([new LineLengthCheck()], [buildCheckFile(SAMPLE_CODING_STYLE)]); - // ignored not enough data points - Assert.areEqual(0, detectedChecks.length); + Assert.areEqual(1, detectedChecks.length); + Assert.areEqual("LineLength", detectedChecks[0].type); + var props = cast detectedChecks[0].props; + Assert.areEqual(100, props.max); } @Test @@ -172,8 +289,11 @@ class DetectCodingStyleTest { @Test public function testDetectMethodLength() { var detectedChecks:Array = DetectCodingStyle.detectCodingStyle([new MethodLengthCheck()], [buildCheckFile(SAMPLE_CODING_STYLE)]); - // ignored not enough data points - Assert.areEqual(0, detectedChecks.length); + Assert.areEqual(1, detectedChecks.length); + Assert.areEqual("MethodLength", detectedChecks[0].type); + var props = cast detectedChecks[0].props; + Assert.areEqual(35, props.max); + Assert.isFalse(props.countEmpty); } @Test @@ -280,7 +400,7 @@ class DetectCodingStyleTest { Assert.areEqual(WhitespacePolicy.IGNORE, props.functionArgPolicy); Assert.areEqual(WhitespacePolicy.IGNORE, props.bitwiseOpPolicy); Assert.areEqual(WhitespacePolicy.AROUND, props.arithmeticOpPolicy); - Assert.areEqual(WhitespacePolicy.IGNORE, props.compareOpPolicy); + Assert.areEqual(WhitespacePolicy.AROUND, props.compareOpPolicy); Assert.areEqual(WhitespacePolicy.IGNORE, props.arrowPolicy); } @@ -301,7 +421,7 @@ class DetectCodingStyleTest { var props = cast detectedChecks[0].props; Assert.areEqual("after", props.commaPolicy); Assert.areEqual("after", props.semicolonPolicy); - Assert.areEqual("none", props.dotPolicy); + Assert.areEqual("before", props.dotPolicy); } @Test @@ -319,12 +439,12 @@ class DetectCodingStyleTest { Assert.areEqual(1, detectedChecks.length); Assert.areEqual("Spacing", detectedChecks[0].type); var props = cast detectedChecks[0].props; - Assert.areEqual(SpacingPolicy.ANY, props.spaceIfCondition); + Assert.areEqual(SpacingPolicy.SHOULD, props.spaceIfCondition); Assert.isFalse(props.spaceAroundBinop); - Assert.areEqual(SpacingPolicy.ANY, props.spaceForLoop); + Assert.areEqual(SpacingPolicy.SHOULD, props.spaceForLoop); Assert.isFalse(props.ignoreRangeOperator); - Assert.areEqual(SpacingPolicy.ANY, props.spaceWhileLoop); - Assert.areEqual(SpacingPolicy.ANY, props.spaceCatch); + Assert.areEqual(SpacingPolicy.SHOULD, props.spaceWhileLoop); + Assert.areEqual(SpacingPolicy.SHOULD_NOT, props.spaceCatch); Assert.areEqual(SpacingPolicy.SHOULD, props.spaceSwitchCase); Assert.isFalse(props.noSpaceAroundUnop); } @@ -344,12 +464,14 @@ class DetectCodingStyleTest { @:enum abstract DetectCodingStyleTests(String) to String { var SAMPLE_CODING_STYLE = " -package checkstyle.test; +package; import checkstyle.checks.Check; class Test { static inline var INDENTATION_CHARACTER_CHECK_TEST:Int = 100; + var param1:Int; + public function new(param1:Int, param2:String) {} public function test(param1:Int, param2:String) { @@ -360,29 +482,22 @@ class Test { ]; var x = values [ 1 ] + values [ 2 ]; - #if php - // comment - doSomething() - .withData(data); - #end - - #if true doNothing(); #end } - function test2(p1:Int, p2:String, p3:String, p4:Int, p5:String, p6:String) { + function test2(p1:Int, p2:String, p3:String, p4:Int = 1, ?p5:String, p6:String) { // comment } function test3() { switch (value) { - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - case 8: - case 9: + case 1: return; + case 2: return; + case 3: return; + case 4: return; + case 5: return; + case 6: return; + case 7: return; + case 8: return; + case 9: return; } return; } @@ -392,14 +507,50 @@ class Test { } function test5() { + if (value == 1) { + if (true) { + if (false) { + doSomething(); + } + } + } + for (i in items) { + for (j in items) { + while ((a = b) > 1) { + run(i, j); + } + } + } + try { + try { + try { + doSomethingRisky(); + } + catch(e) { + tryAgain(); + } + } + catch(e) { + tryAgain(); + } + } + catch(e) { + giveUp(); + } return 1; } + + function test6() { + if ((a = b) > 0) return; + } } interface ITest { public function test(); } +interface IMarker {} + typedef Test2 = { var name:String; @@ -407,5 +558,20 @@ typedef Test2 = } typedef Test2 = {} + +class Test { + public function new() { + return b = c; + } + public function test(param1:Int, param2:String) { + #if php + // comment + doSomething() + .withData(data); + #end + + #if true doNothing(); #end + } +} "; } \ No newline at end of file