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

added more checks to automatic coding style detection #417

Merged
merged 2 commits into from
May 13, 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
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
14 changes: 14 additions & 0 deletions src/checkstyle/checks/coding/HiddenFieldCheck.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}]
}];
}
}
10 changes: 10 additions & 0 deletions src/checkstyle/checks/coding/InnerAssignmentCheck.hx
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,14 @@ class InnerAssignmentCheck extends Check {

return false;
}

override public function detectableInstances():DetectableInstances {
return [{
fixed: [],
properties: [{
propertyName: "ignoreReturnAssignments",
values: [false, true]
}]
}];
}
}
10 changes: 10 additions & 0 deletions src/checkstyle/checks/coding/NestedForDepthCheck.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}]
}];
}
}
10 changes: 10 additions & 0 deletions src/checkstyle/checks/coding/NestedIfDepthCheck.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}]
}];
}
}
10 changes: 10 additions & 0 deletions src/checkstyle/checks/coding/NestedTryDepthCheck.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}]
}];
}
}
10 changes: 10 additions & 0 deletions src/checkstyle/checks/coding/NullableParameterCheck.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/checkstyle/checks/coding/ReturnCountCheck.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}]
}];
}
}
2 changes: 1 addition & 1 deletion src/checkstyle/checks/coding/TraceCheck.hx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class TraceCheck extends Check {
fixed: [],
properties: [{
propertyName: "severity",
values: ["INFO"]
values: [SeverityLevel.INFO]
}]
}];
}
Expand Down
10 changes: 10 additions & 0 deletions src/checkstyle/checks/coding/UnusedLocalVarCheck.hx
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,14 @@ class UnusedLocalVarCheck extends Check {
}
return GO_DEEPER;
}

override public function detectableInstances():DetectableInstances {
return [{
fixed: [],
properties: [{
propertyName: "severity",
values: [SeverityLevel.INFO]
}]
}];
}
}
10 changes: 10 additions & 0 deletions src/checkstyle/checks/design/EmptyPackageCheck.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}]
}];
}
}
14 changes: 14 additions & 0 deletions src/checkstyle/checks/design/InterfaceCheck.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}]
}];
}
}
10 changes: 10 additions & 0 deletions src/checkstyle/checks/design/UnnecessaryConstructorCheck.hx
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,14 @@ class UnnecessaryConstructorCheck extends Check {
}
return false;
}

override public function detectableInstances():DetectableInstances {
return [{
fixed: [],
properties: [{
propertyName: "severity",
values: [SeverityLevel.INFO]
}]
}];
}
}
2 changes: 1 addition & 1 deletion src/checkstyle/checks/imports/AvoidStarImportCheck.hx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AvoidStarImportCheck extends Check {
fixed: [],
properties: [{
propertyName: "severity",
values: ["INFO"]
values: [SeverityLevel.INFO]
}]
}];
}
Expand Down
10 changes: 10 additions & 0 deletions src/checkstyle/checks/imports/UnusedImportCheck.hx
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,14 @@ class UnusedImportCheck extends Check {
}
return typeName == identName;
}

override public function detectableInstances():DetectableInstances {
return [{
fixed: [],
properties: [{
propertyName: "severity",
values: [SeverityLevel.INFO]
}]
}];
}
}
2 changes: 1 addition & 1 deletion src/checkstyle/checks/type/AnonymousCheck.hx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class AnonymousCheck extends Check {
fixed: [],
properties: [{
propertyName: "severity",
values: ["INFO"]
values: [SeverityLevel.INFO]
}]
}];
}
Expand Down
2 changes: 1 addition & 1 deletion src/checkstyle/checks/type/DynamicCheck.hx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class DynamicCheck extends Check {
fixed: [],
properties: [{
propertyName: "severity",
values: ["INFO"]
values: [SeverityLevel.INFO]
}]
}];
}
Expand Down
2 changes: 1 addition & 1 deletion src/checkstyle/checks/type/TypeCheck.hx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class TypeCheck extends Check {
fixed: [],
properties: [{
propertyName: "severity",
values: ["INFO"]
values: [SeverityLevel.INFO]
}]
}];
}
Expand Down
2 changes: 2 additions & 0 deletions src/checkstyle/detect/DetectCodingStyle.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Check>, fileList:Array<CheckFile>):Array<CheckConfig> {
var detectedChecks:Array<CheckConfig> = [];
ArraySort.sort(checks, ConfigUtils.checkSort);
for (check in checks) detectCheck(check, detectedChecks, fileList);

return detectedChecks;
Expand Down
8 changes: 7 additions & 1 deletion src/checkstyle/utils/ConfigUtils.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = [
"moduleName", "severity", "type", "categories",
Expand Down
Loading