Skip to content

Commit

Permalink
fixed position reported for Dynamic violations (#489)
Browse files Browse the repository at this point in the history
* fixed position reported for Dynamic violations
* changed implementation of Dynamic check to use tokentree
* moved to Haxe 4.0.2
  • Loading branch information
AlexHaxe authored Nov 24, 2019
1 parent 4befddc commit 70ba493
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 62 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/checkstyle-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
haxe-version: ['3.4.7', '4.0.0', 'nightly']
haxe-version: ['3.4.7', '4.0.2', 'nightly']
env:
CC_TEST_REPORTER_ID: 1dff6f89d7179dff5db635c6b4fe64acdd5694c9ed44d7da5f12f0f7d3d163b7
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
Expand All @@ -26,7 +26,7 @@ jobs:
with:
node-version: 10
- name: Installing codeclimate client
if: matrix.haxe-version == '4.0.0'
if: matrix.haxe-version == '4.0.2'
run: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
Expand Down Expand Up @@ -68,13 +68,13 @@ jobs:
- name: Run Java tests
run: npx haxe testJava.hxml
- name: Format and upload codeclimate coverage
if: success() && matrix.haxe-version == '4.0.0'
if: success() && matrix.haxe-version == '4.0.2'
run: |
( \
cd src; \
../cc-test-reporter format-coverage -t lcov ../lcov.info; \
../cc-test-reporter upload-coverage; \
)
- name: Upload results to codecov
if: success() && matrix.haxe-version == '4.0.0'
if: success() && matrix.haxe-version == '4.0.2'
run: bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports"
2 changes: 1 addition & 1 deletion .haxerc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "4.0.0",
"version": "4.0.2",
"resolveLibs": "scoped"
}
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ install:
- npm install
- if [[ "$HAXE_VERSION" == "haxe347" ]]; then mv haxe_libraries haxe4_libraries; mv haxe3_libraries haxe_libraries; fi
- if [[ "$HAXE_VERSION" == "haxe347" ]]; then npx lix download haxe 3.4.7; npx lix use haxe 3.4.7; fi
- if [[ "$HAXE_VERSION" == "haxe4" ]]; then npx lix download haxe 4.0.0; npx lix use haxe 4.0.0; fi
- if [[ "$HAXE_VERSION" == "haxe4" ]]; then npx lix download haxe 4.0.2; npx lix use haxe 4.0.2; fi
- if [[ "$HAXE_VERSION" == "nightly" ]]; then npx lix download haxe nightly; npx lix use haxe nightly; fi
- npx lix download
- npx haxe -version
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
- Changed default value for `max` in `FileLengthCheck` to 1000 ([#486](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/486))
- Changed `MethodLength` check to use tokentree ([#486](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/486))
- Changed reported position for `FieldDocComment` and `MethodLength` to only include function signature ([#487](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/487))
- Changed `Dynamic` check implementation to tokentree, now only reports token location ([#489](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/489))
- Fixed range exclusion to allow excluding construtor (`new`) ([#479](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/479))
- Fixed reported positions for `FieldDocComment`, `MethodLength`, `ParameterNumber`, `RedundantModifier` and `ReturnCount` checks ([#488](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/488))
- Refactored build system to use lix ([#478](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/478))
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ haxe buildCpp.hxml # for C++ version
```

Compiling with Haxe 3

```bash
git clone https://github.com/HaxeCheckstyle/haxe-checkstyle.git
mv haxe_libraries haxe4_libraries
Expand Down
6 changes: 3 additions & 3 deletions src/checkstyle/Checker.hx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package checkstyle;

import haxeparser.HaxeParser;
import haxeparser.HaxeLexer;
import sys.io.File;
import checkstyle.checks.Check;
import checkstyle.config.ExcludeManager;
import checkstyle.config.ExcludeRange;
import checkstyle.reporter.ReporterManager;
import haxeparser.HaxeLexer;
import haxeparser.HaxeParser;
import sys.io.File;
import tokentree.TokenTreeBuilder;

class Checker {
Expand Down
10 changes: 5 additions & 5 deletions src/checkstyle/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ package checkstyle;

import checkstyle.ChecksInfo;
import checkstyle.checks.Check;
import checkstyle.config.ConfigParser;
import checkstyle.config.CheckConfig;
import checkstyle.config.ConfigParser;
import checkstyle.config.ExcludeManager;
import checkstyle.detect.DetectCodingStyle;
import checkstyle.reporter.CodeClimateReporter;
import checkstyle.reporter.ExitCodeReporter;
import checkstyle.reporter.IReporter;
import checkstyle.reporter.JSONReporter;
import checkstyle.reporter.ProgressReporter;
import checkstyle.reporter.ReporterManager;
import checkstyle.reporter.TextReporter;
import checkstyle.reporter.XMLReporter;
import checkstyle.reporter.CodeClimateReporter;
import checkstyle.reporter.ExitCodeReporter;
import checkstyle.reporter.ReporterManager;
import checkstyle.utils.ConfigUtils;
import haxe.CallStack;
import haxe.Json;
import haxe.io.Path;
import hxargs.Args;
import sys.FileSystem;
import sys.io.File;
import haxe.io.Path;

class Main {
static var DEFAULT_CONFIG:String = "checkstyle.json";
Expand Down
32 changes: 12 additions & 20 deletions src/checkstyle/checks/type/DynamicCheck.hx
Original file line number Diff line number Diff line change
@@ -1,37 +1,29 @@
package checkstyle.checks.type;

import checkstyle.utils.ComplexTypeUtils;

/**
Checks for use of Dynamic type anywhere in the code.
**/
@name("Dynamic")
@desc("Checks for use of Dynamic type anywhere in the code.")
class DynamicCheck extends Check {
public function new() {
super(AST);
super(TOKEN);
categories = [Category.CLARITY, Category.BUG_RISK, Category.COMPLEXITY];
points = 3;
}

override function actualRun() {
if (checker.ast == null) return;
ComplexTypeUtils.walkFile(checker.ast, callbackComplexType);
}

function callbackComplexType(t:ComplexType, name:String, pos:Position) {
if (t == null) return;
switch (t) {
case TPath(p):
if (p.name != "Dynamic") return;
if (isPosSuppressed(pos)) return;
error(name, pos);
default:
}
}

function error(name:String, pos:Position) {
logPos('"${name}" type is "Dynamic"', pos);
var root:TokenTree = checker.getTokenTree();
root.filterCallback(function(token:TokenTree, index:Int):FilterResult {
switch token.tok {
case Const(CIdent("Dynamic")):
if (isPosSuppressed(token.pos)) return SKIP_SUBTREE;
logPos('Avoid using "Dynamic" as type', token.pos);
return SKIP_SUBTREE;
default:
return GO_DEEPER;
}
});
}

override public function detectableInstances():DetectableInstances {
Expand Down
12 changes: 6 additions & 6 deletions src/checkstyle/import.hx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package checkstyle;

import haxe.io.Bytes;
import haxe.macro.Expr;
import haxeparser.Data;
import checkstyle.Checker.LinePos;
import checkstyle.SeverityLevel;
import checkstyle.detect.DetectableInstances;
import checkstyle.utils.ErrorUtils;
import haxe.io.Bytes;
import haxe.macro.Expr;
import haxeparser.Data;
import tokentree.TokenTree;
import tokentree.TokenTreeAccessHelper;
import tokentree.utils.TokenTreeCheckUtils;

using StringTools;
using checkstyle.utils.ArrayUtils;
using checkstyle.utils.FieldUtils;
using checkstyle.utils.ExprUtils;
using checkstyle.utils.FieldUtils;
using checkstyle.utils.StringUtils;
using tokentree.TokenTreeAccessHelper;
using StringTools;
using tokentree.TokenTreeAccessHelper;
8 changes: 4 additions & 4 deletions test/TestMain.hx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import haxe.EntryPoint;
import massive.munit.TestRunner;
import mcover.coverage.MCoverage;
import mcover.coverage.munit.client.MCoverPrintClient;
#if (neko || cpp || hl)
import haxe.EntryPoint;
#end
#if codecov_json
import mcover.coverage.client.CodecovJsonPrintClient;
#else
import mcover.coverage.client.LcovPrintClient;
#end
import mcover.coverage.MCoverage;

using StringTools;

class TestMain {
public function new() {
Expand Down
4 changes: 2 additions & 2 deletions test/checkstyle/checks/CheckTestCase.hx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package checkstyle.checks;

import byte.ByteData;
import checkstyle.CheckMessage;
import checkstyle.CheckFile;
import checkstyle.CheckMessage;
import checkstyle.Checker;
import checkstyle.reporter.IReporter;
import checkstyle.reporter.ReporterManager;
import checkstyle.Checker;

class CheckTestCase<T:String> {
static inline var FILE_NAME:String = "Test.hx";
Expand Down
14 changes: 8 additions & 6 deletions test/checkstyle/checks/type/DynamicCheckTest.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package checkstyle.checks.type;

class DynamicCheckTest extends CheckTestCase<DynamicCheckTests> {
public static inline var AVOID_USING_DYNAMIC_AS_TYPE:String = 'Avoid using "Dynamic" as type';

@Test
public function testNoDynamic() {
var check = new DynamicCheck();
Expand All @@ -10,12 +12,12 @@ class DynamicCheckTest extends CheckTestCase<DynamicCheckTests> {
@Test
public function testDetectDynamic() {
var check = new DynamicCheck();
assertMsg(check, TEST1, '"Count" type is "Dynamic"');
assertMsg(check, TEST2, '"test" type is "Dynamic"');
assertMsg(check, TEST3, '"Count" type is "Dynamic"');
assertMsg(check, TEST4, '"param" type is "Dynamic"');
assertMsg(check, TEST5, '"test" type is "Dynamic"');
assertMsg(check, TEST6, '"Test" type is "Dynamic"');
assertMsg(check, TEST1, AVOID_USING_DYNAMIC_AS_TYPE);
assertMsg(check, TEST2, AVOID_USING_DYNAMIC_AS_TYPE);
assertMsg(check, TEST3, AVOID_USING_DYNAMIC_AS_TYPE);
assertMsg(check, TEST4, AVOID_USING_DYNAMIC_AS_TYPE);
assertMsg(check, TEST5, AVOID_USING_DYNAMIC_AS_TYPE);
assertMsg(check, TEST6, AVOID_USING_DYNAMIC_AS_TYPE);

assertNoMsg(check, ISSUE_43);
}
Expand Down
6 changes: 3 additions & 3 deletions test/checkstyle/config/ExcludeManagerTest.hx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package checkstyle.config;

import checkstyle.checks.CheckTestCase;
import checkstyle.checks.type.DynamicCheck;
import checkstyle.checks.type.ReturnCheck;
import checkstyle.checks.CheckTestCase;

class ExcludeManagerTest extends CheckTestCase<ExcludeManagerTests> {
static inline var LOCAL_PATH:String = "./";
Expand Down Expand Up @@ -65,7 +65,7 @@ class ExcludeManagerTest extends CheckTestCase<ExcludeManagerTests> {
configParser.parseExcludes(cast {
version: 1,
path: ExcludePath.RELATIVE_TO_PROJECT,
Dynamic: ["src/checkstyle/checks/Check$", "test/checkstyle/checks/Check$"]
"Dynamic": ["src/checkstyle/checks/Check$", "test/checkstyle/checks/Check$"]
});

Assert.isTrue(ExcludeManager.isExcludedFromCheck(CHECK_FILE_NAME, DYNAMIC));
Expand All @@ -86,7 +86,7 @@ class ExcludeManagerTest extends CheckTestCase<ExcludeManagerTests> {
configParser.parseExcludes(cast {
version: 1,
path: ExcludePath.RELATIVE_TO_PROJECT,
Dynamic: [
"Dynamic": [
"src/checkstyle/checks/ChecksInfo$:10",
"src/checkstyle/checks/ChecksInfo$:14-16",
"src/checkstyle/checks/ChecksInfo$:usesDynamic",
Expand Down
12 changes: 5 additions & 7 deletions test/checkstyle/detect/DetectCodingStyleTest.hx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package checkstyle.detect;

import byte.ByteData;
import checkstyle.config.CheckConfig;
import checkstyle.CheckFile;
import checkstyle.SeverityLevel;
import checkstyle.checks.block.BlockBreakingConditionalCheck;
Expand All @@ -20,13 +19,13 @@ 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.DocCommentStyleCheck;
import checkstyle.checks.comments.FieldDocCommentCheck;
import checkstyle.checks.comments.TODOCommentCheck;
import checkstyle.checks.comments.TypeDocCommentCheck;
import checkstyle.checks.design.EmptyPackageCheck;
import checkstyle.checks.design.InterfaceCheck;
import checkstyle.checks.design.UnnecessaryConstructorCheck;
import checkstyle.checks.imports.AvoidStarImportCheck;
import checkstyle.checks.imports.UnusedImportCheck;
import checkstyle.checks.literal.StringLiteralCheck;
Expand All @@ -48,18 +47,17 @@ import checkstyle.checks.type.TypeCheck;
import checkstyle.checks.whitespace.ArrayAccessCheck;
import checkstyle.checks.whitespace.EmptyLinesCheck;
import checkstyle.checks.whitespace.ExtendedEmptyLinesCheck;
import checkstyle.checks.whitespace.ExtendedEmptyLinesCheck.EmptyLinesPolicy;
import checkstyle.checks.whitespace.IndentationCharacterCheck;
import checkstyle.checks.whitespace.IndentationCheck;
import checkstyle.checks.whitespace.OperatorWhitespaceCheck;
import checkstyle.checks.whitespace.OperatorWrapCheck;
import checkstyle.checks.whitespace.SeparatorWrapCheck;
import checkstyle.checks.whitespace.SeparatorWhitespaceCheck;
import checkstyle.checks.whitespace.SeparatorWrapCheck;
import checkstyle.checks.whitespace.SpacingCheck;
import checkstyle.checks.whitespace.SpacingCheck.SpacingPolicy;
import checkstyle.checks.whitespace.TrailingWhitespaceCheck;
import checkstyle.checks.whitespace.WhitespaceCheckBase.WhitespacePolicy;
import checkstyle.checks.whitespace.WrapCheckBase.WrapCheckBaseOption;
import checkstyle.config.CheckConfig;

class DetectCodingStyleTest {
// checkstyle.checks.block
Expand Down

0 comments on commit 70ba493

Please sign in to comment.