Skip to content

Commit 26f3e3b

Browse files
authored
added more detectable checks (#410)
* added more detectable checks * fixed sort order of detected checks
1 parent 7bd1ccd commit 26f3e3b

File tree

8 files changed

+102
-2
lines changed

8 files changed

+102
-2
lines changed

CHANGES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## dev branch / next version (2.x.x)
22
- New `extendsConfigPath` field to config files fixes [#401](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/401) ([#407](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/407) + [#408](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/408))
3-
- New experimental command line option `-detect <filename>` to generate a checkstyle configuration file based on a source folder [#409](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/409)
3+
- New experimental command line option `-detect <filename>` to generate a checkstyle configuration file based on a source folder [#409](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/409) + [#410](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/410)
4+
- Fixed sort order of detected checkstyle configuration [#410](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/410)
45
- Refactored indentation check messages [#409](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/409)
56

67
## version 2.2.2

src/checkstyle/checks/coding/TraceCheck.hx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,14 @@ class TraceCheck extends Check {
2828
default: false;
2929
}
3030
}
31+
32+
override public function detectableInstances():DetectableInstances {
33+
return [{
34+
fixed: [],
35+
properties: [{
36+
propertyName: "severity",
37+
values: ["INFO"]
38+
}]
39+
}];
40+
}
3141
}

src/checkstyle/checks/comments/TODOCommentCheck.hx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,14 @@ class TODOCommentCheck extends Check {
2424
}
2525
}
2626
}
27+
28+
override public function detectableInstances():DetectableInstances {
29+
return [{
30+
fixed: [],
31+
properties: [{
32+
propertyName: "format",
33+
values: ["^\\s*(TODO|FIXME|HACK|XXX|BUG)"]
34+
}]
35+
}];
36+
}
2737
}

src/checkstyle/checks/imports/AvoidStarImportCheck.hx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,14 @@ class AvoidStarImportCheck extends Check {
2222
logPos('Using the ".*" form of import should be avoided', entry.pos);
2323
}
2424
}
25+
26+
override public function detectableInstances():DetectableInstances {
27+
return [{
28+
fixed: [],
29+
properties: [{
30+
propertyName: "severity",
31+
values: ["INFO"]
32+
}]
33+
}];
34+
}
2535
}

src/checkstyle/checks/type/TypeCheck.hx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package checkstyle.checks.type;
22

33
@name("Type")
4-
@desc("Checks of type is specified or not for member variables.")
4+
@desc("Checks if type is specified or not for member variables.")
55
class TypeCheck extends Check {
66

77
public var ignoreEnumAbstractValues:Bool;
@@ -27,4 +27,14 @@ class TypeCheck extends Check {
2727
function error(name:String, pos:Position) {
2828
logPos('Variable "${name}" type not specified', pos);
2929
}
30+
31+
override public function detectableInstances():DetectableInstances {
32+
return [{
33+
fixed: [],
34+
properties: [{
35+
propertyName: "severity",
36+
values: ["INFO"]
37+
}]
38+
}];
39+
}
3040
}

src/checkstyle/checks/whitespace/TrailingWhitespaceCheck.hx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,14 @@ class TrailingWhitespaceCheck extends LineCheckBase {
2121
if (re.match(endText)) log("Trailing whitespace", i + 1, line.length);
2222
}
2323
}
24+
25+
override public function detectableInstances():DetectableInstances {
26+
return [{
27+
fixed: [],
28+
properties: [{
29+
propertyName: "severity",
30+
values: ["INFO"]
31+
}]
32+
}];
33+
}
2434
}

src/checkstyle/utils/ConfigUtils.hx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import checkstyle.Checker;
55
import checkstyle.checks.Check;
66

77
import haxe.Json;
8+
import haxe.ds.ArraySort;
89
import sys.io.File;
910

1011
class ConfigUtils {
@@ -24,6 +25,7 @@ class ConfigUtils {
2425
public static function saveConfig(checker:Checker, path:String) {
2526
var config = getEmptyConfig();
2627
for (check in checker.checks) config.checks.push(makeCheckConfig(check));
28+
ArraySort.sort(config.checks, checkConfigSort);
2729

2830
var file = File.write(path, false);
2931
file.writeString(Json.stringify(config, null, "\t"));
@@ -33,12 +35,19 @@ class ConfigUtils {
3335
public static function saveCheckConfigList(list:Array<CheckConfig>, path:String) {
3436
var config = getEmptyConfig();
3537
config.checks = list;
38+
ArraySort.sort(config.checks, checkConfigSort);
3639

3740
var file = File.write(path, false);
3841
file.writeString(Json.stringify(config, null, "\t"));
3942
file.close();
4043
}
4144

45+
public static function checkConfigSort(a:CheckConfig, b:CheckConfig):Int {
46+
if (a.type == b.type) return 0;
47+
if (a.type < b.type) return -1;
48+
return 1;
49+
}
50+
4251
public static function makeCheckConfig(check:Check):CheckConfig {
4352
var propsNotAllowed:Array<String> = [
4453
"moduleName", "severity", "type", "categories",

test/detect/DetectCodingStyleTest.hx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@ import checkstyle.CheckFile;
77
import checkstyle.checks.block.ConditionalCompilationCheck;
88
import checkstyle.checks.block.LeftCurlyCheck;
99
import checkstyle.checks.block.RightCurlyCheck;
10+
import checkstyle.checks.coding.TraceCheck;
11+
import checkstyle.checks.comments.TODOCommentCheck;
12+
import checkstyle.checks.imports.AvoidStarImportCheck;
1013
import checkstyle.checks.modifier.RedundantModifierCheck;
1114
import checkstyle.checks.naming.ConstantNameCheck;
15+
import checkstyle.checks.type.TypeCheck;
1216
import checkstyle.checks.whitespace.IndentationCharacterCheck;
1317
import checkstyle.checks.whitespace.IndentationCheck;
1418
import checkstyle.checks.whitespace.SeparatorWrapCheck;
19+
import checkstyle.checks.whitespace.TrailingWhitespaceCheck;
1520
import checkstyle.detect.DetectCodingStyle;
1621

1722
import massive.munit.Assert;
@@ -101,6 +106,41 @@ class DetectCodingStyleTest {
101106
Assert.areEqual("^[A-Z][A-Z0-9]*(_[A-Z0-9_]+)*$", props.format);
102107
}
103108

109+
@Test
110+
public function testDetectTrace() {
111+
var detectedChecks:Array<CheckConfig> = DetectCodingStyle.detectCodingStyle([new TraceCheck()], [buildCheckFile(SAMPLE_CODING_STYLE)]);
112+
Assert.areEqual(1, detectedChecks.length);
113+
Assert.areEqual("Trace", detectedChecks[0].type);
114+
}
115+
116+
@Test
117+
public function testDetectTODOComment() {
118+
var detectedChecks:Array<CheckConfig> = DetectCodingStyle.detectCodingStyle([new TODOCommentCheck()], [buildCheckFile(SAMPLE_CODING_STYLE)]);
119+
Assert.areEqual(1, detectedChecks.length);
120+
Assert.areEqual("TODOComment", detectedChecks[0].type);
121+
}
122+
123+
@Test
124+
public function testDetectAvoidStarImport() {
125+
var detectedChecks:Array<CheckConfig> = DetectCodingStyle.detectCodingStyle([new AvoidStarImportCheck()], [buildCheckFile(SAMPLE_CODING_STYLE)]);
126+
Assert.areEqual(1, detectedChecks.length);
127+
Assert.areEqual("AvoidStarImport", detectedChecks[0].type);
128+
}
129+
130+
@Test
131+
public function testDetectType() {
132+
var detectedChecks:Array<CheckConfig> = DetectCodingStyle.detectCodingStyle([new TypeCheck()], [buildCheckFile(SAMPLE_CODING_STYLE)]);
133+
Assert.areEqual(1, detectedChecks.length);
134+
Assert.areEqual("Type", detectedChecks[0].type);
135+
}
136+
137+
@Test
138+
public function testDetectTrailingWhitespace() {
139+
var detectedChecks:Array<CheckConfig> = DetectCodingStyle.detectCodingStyle([new TrailingWhitespaceCheck()], [buildCheckFile(SAMPLE_CODING_STYLE)]);
140+
Assert.areEqual(1, detectedChecks.length);
141+
Assert.areEqual("TrailingWhitespace", detectedChecks[0].type);
142+
}
143+
104144
function buildCheckFile(src:String):CheckFile {
105145
return {name:"Test.hx", content:ByteData.ofString(src), index:0};
106146
}

0 commit comments

Comments
 (0)