Skip to content

Commit 70ba493

Browse files
authored
fixed position reported for Dynamic violations (#489)
* fixed position reported for Dynamic violations * changed implementation of Dynamic check to use tokentree * moved to Haxe 4.0.2
1 parent 4befddc commit 70ba493

File tree

14 files changed

+56
-62
lines changed

14 files changed

+56
-62
lines changed

.github/workflows/checkstyle-linux.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
strategy:
1717
matrix:
18-
haxe-version: ['3.4.7', '4.0.0', 'nightly']
18+
haxe-version: ['3.4.7', '4.0.2', 'nightly']
1919
env:
2020
CC_TEST_REPORTER_ID: 1dff6f89d7179dff5db635c6b4fe64acdd5694c9ed44d7da5f12f0f7d3d163b7
2121
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
@@ -26,7 +26,7 @@ jobs:
2626
with:
2727
node-version: 10
2828
- name: Installing codeclimate client
29-
if: matrix.haxe-version == '4.0.0'
29+
if: matrix.haxe-version == '4.0.2'
3030
run: |
3131
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
3232
chmod +x ./cc-test-reporter
@@ -68,13 +68,13 @@ jobs:
6868
- name: Run Java tests
6969
run: npx haxe testJava.hxml
7070
- name: Format and upload codeclimate coverage
71-
if: success() && matrix.haxe-version == '4.0.0'
71+
if: success() && matrix.haxe-version == '4.0.2'
7272
run: |
7373
( \
7474
cd src; \
7575
../cc-test-reporter format-coverage -t lcov ../lcov.info; \
7676
../cc-test-reporter upload-coverage; \
7777
)
7878
- name: Upload results to codecov
79-
if: success() && matrix.haxe-version == '4.0.0'
79+
if: success() && matrix.haxe-version == '4.0.2'
8080
run: bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports"

.haxerc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"version": "4.0.0",
2+
"version": "4.0.2",
33
"resolveLibs": "scoped"
44
}

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ install:
1717
- npm install
1818
- if [[ "$HAXE_VERSION" == "haxe347" ]]; then mv haxe_libraries haxe4_libraries; mv haxe3_libraries haxe_libraries; fi
1919
- if [[ "$HAXE_VERSION" == "haxe347" ]]; then npx lix download haxe 3.4.7; npx lix use haxe 3.4.7; fi
20-
- if [[ "$HAXE_VERSION" == "haxe4" ]]; then npx lix download haxe 4.0.0; npx lix use haxe 4.0.0; fi
20+
- if [[ "$HAXE_VERSION" == "haxe4" ]]; then npx lix download haxe 4.0.2; npx lix use haxe 4.0.2; fi
2121
- if [[ "$HAXE_VERSION" == "nightly" ]]; then npx lix download haxe nightly; npx lix use haxe nightly; fi
2222
- npx lix download
2323
- npx haxe -version

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- Changed default value for `max` in `FileLengthCheck` to 1000 ([#486](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/486))
1717
- Changed `MethodLength` check to use tokentree ([#486](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/486))
1818
- Changed reported position for `FieldDocComment` and `MethodLength` to only include function signature ([#487](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/487))
19+
- Changed `Dynamic` check implementation to tokentree, now only reports token location ([#489](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/489))
1920
- Fixed range exclusion to allow excluding construtor (`new`) ([#479](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/479))
2021
- Fixed reported positions for `FieldDocComment`, `MethodLength`, `ParameterNumber`, `RedundantModifier` and `ReturnCount` checks ([#488](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/488))
2122
- Refactored build system to use lix ([#478](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/478))

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ haxe buildCpp.hxml # for C++ version
6767
```
6868

6969
Compiling with Haxe 3
70+
7071
```bash
7172
git clone https://github.com/HaxeCheckstyle/haxe-checkstyle.git
7273
mv haxe_libraries haxe4_libraries

src/checkstyle/Checker.hx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package checkstyle;
22

3-
import haxeparser.HaxeParser;
4-
import haxeparser.HaxeLexer;
5-
import sys.io.File;
63
import checkstyle.checks.Check;
74
import checkstyle.config.ExcludeManager;
85
import checkstyle.config.ExcludeRange;
96
import checkstyle.reporter.ReporterManager;
7+
import haxeparser.HaxeLexer;
8+
import haxeparser.HaxeParser;
9+
import sys.io.File;
1010
import tokentree.TokenTreeBuilder;
1111

1212
class Checker {

src/checkstyle/Main.hx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@ package checkstyle;
22

33
import checkstyle.ChecksInfo;
44
import checkstyle.checks.Check;
5-
import checkstyle.config.ConfigParser;
65
import checkstyle.config.CheckConfig;
6+
import checkstyle.config.ConfigParser;
77
import checkstyle.config.ExcludeManager;
88
import checkstyle.detect.DetectCodingStyle;
9+
import checkstyle.reporter.CodeClimateReporter;
10+
import checkstyle.reporter.ExitCodeReporter;
911
import checkstyle.reporter.IReporter;
1012
import checkstyle.reporter.JSONReporter;
1113
import checkstyle.reporter.ProgressReporter;
14+
import checkstyle.reporter.ReporterManager;
1215
import checkstyle.reporter.TextReporter;
1316
import checkstyle.reporter.XMLReporter;
14-
import checkstyle.reporter.CodeClimateReporter;
15-
import checkstyle.reporter.ExitCodeReporter;
16-
import checkstyle.reporter.ReporterManager;
1717
import checkstyle.utils.ConfigUtils;
1818
import haxe.CallStack;
1919
import haxe.Json;
20+
import haxe.io.Path;
2021
import hxargs.Args;
2122
import sys.FileSystem;
2223
import sys.io.File;
23-
import haxe.io.Path;
2424

2525
class Main {
2626
static var DEFAULT_CONFIG:String = "checkstyle.json";

src/checkstyle/checks/type/DynamicCheck.hx

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,29 @@
11
package checkstyle.checks.type;
22

3-
import checkstyle.utils.ComplexTypeUtils;
4-
53
/**
64
Checks for use of Dynamic type anywhere in the code.
75
**/
86
@name("Dynamic")
97
@desc("Checks for use of Dynamic type anywhere in the code.")
108
class DynamicCheck extends Check {
119
public function new() {
12-
super(AST);
10+
super(TOKEN);
1311
categories = [Category.CLARITY, Category.BUG_RISK, Category.COMPLEXITY];
1412
points = 3;
1513
}
1614

1715
override function actualRun() {
18-
if (checker.ast == null) return;
19-
ComplexTypeUtils.walkFile(checker.ast, callbackComplexType);
20-
}
21-
22-
function callbackComplexType(t:ComplexType, name:String, pos:Position) {
23-
if (t == null) return;
24-
switch (t) {
25-
case TPath(p):
26-
if (p.name != "Dynamic") return;
27-
if (isPosSuppressed(pos)) return;
28-
error(name, pos);
29-
default:
30-
}
31-
}
32-
33-
function error(name:String, pos:Position) {
34-
logPos('"${name}" type is "Dynamic"', pos);
16+
var root:TokenTree = checker.getTokenTree();
17+
root.filterCallback(function(token:TokenTree, index:Int):FilterResult {
18+
switch token.tok {
19+
case Const(CIdent("Dynamic")):
20+
if (isPosSuppressed(token.pos)) return SKIP_SUBTREE;
21+
logPos('Avoid using "Dynamic" as type', token.pos);
22+
return SKIP_SUBTREE;
23+
default:
24+
return GO_DEEPER;
25+
}
26+
});
3527
}
3628

3729
override public function detectableInstances():DetectableInstances {

src/checkstyle/import.hx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
package checkstyle;
22

3-
import haxe.io.Bytes;
4-
import haxe.macro.Expr;
5-
import haxeparser.Data;
63
import checkstyle.Checker.LinePos;
74
import checkstyle.SeverityLevel;
85
import checkstyle.detect.DetectableInstances;
96
import checkstyle.utils.ErrorUtils;
7+
import haxe.io.Bytes;
8+
import haxe.macro.Expr;
9+
import haxeparser.Data;
1010
import tokentree.TokenTree;
1111
import tokentree.TokenTreeAccessHelper;
1212
import tokentree.utils.TokenTreeCheckUtils;
1313

14+
using StringTools;
1415
using checkstyle.utils.ArrayUtils;
15-
using checkstyle.utils.FieldUtils;
1616
using checkstyle.utils.ExprUtils;
17+
using checkstyle.utils.FieldUtils;
1718
using checkstyle.utils.StringUtils;
18-
using tokentree.TokenTreeAccessHelper;
19-
using StringTools;
19+
using tokentree.TokenTreeAccessHelper;

test/TestMain.hx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import haxe.EntryPoint;
21
import massive.munit.TestRunner;
2+
import mcover.coverage.MCoverage;
33
import mcover.coverage.munit.client.MCoverPrintClient;
4+
#if (neko || cpp || hl)
5+
import haxe.EntryPoint;
6+
#end
47
#if codecov_json
58
import mcover.coverage.client.CodecovJsonPrintClient;
69
#else
710
import mcover.coverage.client.LcovPrintClient;
811
#end
9-
import mcover.coverage.MCoverage;
10-
11-
using StringTools;
1212

1313
class TestMain {
1414
public function new() {

0 commit comments

Comments
 (0)