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

use formatter #461

Merged
merged 3 commits into from
Sep 10, 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: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ matrix:
- haxelib install compiletime 2.6.0
- haxelib install hxargs 3.0.2
- sed -i 's/:3.3.0//' buildGlobal.hxml
allow_failures:
- haxe: development
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Version History

## dev branch / next version (2.x.x)

- Fixed enum abstract detection in MagixNumber check, fixes [#104](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/104) ([#449](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/449))
Expand All @@ -10,6 +12,7 @@
- Fixed indentation of arrow [#459](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/459)
- Fixed position change of semicolon [#460](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/460)
- Changed return block indentation [#453](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/453)
- Changed to use formatter [#461](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/461)

## version 2.4.2 (2018-07-01)

Expand Down
15 changes: 11 additions & 4 deletions checkstyle.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@
"props": {
"max": 1,
"requireEmptyLineAfterAbstract": false,
"requireEmptyLineAfterClass": false
"requireEmptyLineAfterClass": false,
"requireEmptyLineAfterInterface": false
},
"type": "EmptyLines"
},
Expand All @@ -99,16 +100,18 @@
"afterClassStaticVars",
"afterClassVars",
"betweenClassMethods",
"beginInterface"
"beforeMultiLineComment"
],
"upto": [
"betweenImports",
"anywhereInFile",
"betweenAbstractVars",
"beginClass",
"beginInterface",
"betweenClassStaticVars",
"betweenClassVars",
"betweenInterfaceFields"
"betweenInterfaceFields",
"beforeSingleLineComment"
]
},
"type": "ExtendedEmptyLines"
Expand Down Expand Up @@ -624,11 +627,15 @@
"checkstyle/checks/metrics/CyclomaticComplexityCheck"
],
"MethodLength": [
"checkstyle/checks/metrics/CyclomaticComplexityCheck",
"checkstyle/checks/whitespace/WhitespaceAfterCheck",
"checkstyle/checks/whitespace/WhitespaceAroundCheck",
"checkstyle/checks/whitespace/EmptyLinesCheck",
"checkstyle/checks/whitespace/IndentationCheck",
"checkstyle/token/walk/WalkStatement"
"checkstyle/token/walk/WalkStatement",
"checkstyle/utils/ExprUtils",
"checkstyle/utils/ComplexTypeUtils",
"checkstyle/Main"
],
"NestedForDepth": [
"TestMain"
Expand Down
45 changes: 45 additions & 0 deletions hxformat.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"sameLine": {
"caseBody": "next",
"tryCatch": "next",
"ifBody": "same",
"ifElse": "next",
"elseBody": "same",
"forBody": "same",
"whileBody": "same",
"comprehensionFor": "same"
},
"emptyLines": {
"finalNewline": false,
"interfaceEmptyLines": {
"beginType": 1
}
},
"wrapping": {
"arrayWrap": {
"rules": [
{
"conditions": [{"cond": "totalItemLength <= n", "value": 80}],
"type": "noWrap"
},
{
"conditions": [{"cond": "itemCount >= n", "value": 10}],
"type": "onePerLine"
},
{
"conditions": [{"cond": "anyItemLength >= n", "value": 30}],
"type": "onePerLine"
},
{
"conditions": [{"cond": "itemCount >= n", "value": 4}],
"type": "onePerLine"
}
]
}
},
"whitespace": {
"arrowFunctionsPolicy": "around",
"functionTypeHaxe3Policy": "around",
"functionTypeHaxe4Policy": "around"
}
}
174 changes: 92 additions & 82 deletions resources/checkstyle-schema.json

Large diffs are not rendered by default.

15 changes: 6 additions & 9 deletions src/checkstyle/Checker.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ 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 tokentree.TokenTreeBuilder;

class Checker {
Expand All @@ -23,10 +19,11 @@ class Checker {
public var checks:Array<Check>;
public var baseDefines:Array<String>;
public var defineCombinations:Array<Array<String>>;

public var linesIdx:Array<LineIds>;
public var lineSeparator:String;

var tokenTree:TokenTree;

public var asts:Array<Ast>;
public var excludesRanges:Map<String, Array<ExcludeRange>>;

Expand Down Expand Up @@ -56,13 +53,13 @@ class Checker {

for (i in 0...code.length) {
if (code.get(i) == 0x0A) {
linesIdx.push({l:last, r:i});
linesIdx.push({l: last, r: i});
last = i + 1;
left = false;
}
left = true;
}
if (left) linesIdx.push({l:last, r:code.length});
if (left) linesIdx.push({l: last, r: code.length});
}

public function getLinePos(off:Int):LinePos {
Expand All @@ -76,7 +73,7 @@ class Checker {
var center:Int = lowerBound + Math.floor((upperBound - lowerBound) / 2);
var matchLeft:Bool = linesIdx[center].l <= off;
var matchRight:Bool = linesIdx[center].r >= off;
if (matchLeft && matchRight) return { line: center, ofs: off - linesIdx[center].l };
if (matchLeft && matchRight) return {line: center, ofs: off - linesIdx[center].l};
if (matchLeft) {
lowerBound = center + 1;
continue;
Expand Down Expand Up @@ -111,7 +108,7 @@ class Checker {
return;
}
}
//default
// default
lineSeparator = "\n";
}

Expand Down
1 change: 0 additions & 1 deletion src/checkstyle/CheckerPool.hx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package checkstyle;

class CheckerPool {

var parserQueue:ParserQueue;
var templateChecker:Checker;
var threads:Array<CheckerThread>;
Expand Down
21 changes: 13 additions & 8 deletions src/checkstyle/CheckerThread.hx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ import cpp.hl.Thread;
#else
import checkstyle.utils.Thread;
#end

import checkstyle.checks.Check;

import checkstyle.config.ExcludeManager;

import checkstyle.reporter.ReporterManager;

class CheckerThread {
Expand All @@ -38,14 +35,22 @@ class CheckerThread {
checks = [];

var propsNotAllowed:Array<String> = [
"moduleName", "type", "categories",
"points", "desc", "currentState", "skipOverStringStart",
"commentStartRE", "commentBlockEndRE", "stringStartRE",
"stringInterpolatedEndRE", "stringLiteralEndRE"
"moduleName",
"type",
"categories",
"points",
"desc",
"currentState",
"skipOverStringStart",
"commentStartRE",
"commentBlockEndRE",
"stringStartRE",
"stringInterpolatedEndRE",
"stringLiteralEndRE"
];

for (check in templateChecks) {
var newCheck = Type.createInstance (Type.getClass(check), []);
var newCheck = Type.createInstance(Type.getClass(check), []);

for (prop in Reflect.fields(check)) {
if (propsNotAllowed.contains(prop)) continue;
Expand Down
1 change: 0 additions & 1 deletion src/checkstyle/ChecksInfo.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package checkstyle;
import checkstyle.checks.Check;

class ChecksInfo {

var checkInfos:Map<String, CheckInfo>;

public function new() {
Expand Down
73 changes: 48 additions & 25 deletions src/checkstyle/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import sys.io.File;
import haxe.io.Path;

class Main {

static var DEFAULT_CONFIG:String = "checkstyle.json";
static var DEFAULT_EXCLUDE_CONFIG:String = "checkstyle-exclude.json";
static var REPORT_TYPE:String = "text";
Expand Down Expand Up @@ -55,28 +54,44 @@ class Main {

function run(args:Array<String>) {
var argHandler = Args.generate([
@doc("Set source path to process (multiple allowed)") ["-s", "--source"] => function(path:String) configParser.paths.push(path),
@doc("Set config file (default: checkstyle.json)") ["-c", "--config"] => function(path:String) configPath = path,
@doc("Set exclude file (default: checkstyle-exclude.json)") ["-e", "--exclude"] => function(path:String) excludePath = path,
@doc("Set reporter (xml, json or text, default: text)") ["-r", "--reporter"] => function(name:String) REPORT_TYPE = name,
@doc("Set reporter output path") ["-p", "--path"] => function(path:String) {
@doc("Set source path to process (multiple allowed)")
["-s", "--source"] => function(path:String) configParser.paths.push(path),
@doc("Set config file (default: checkstyle.json)")
["-c", "--config"] => function(path:String) configPath = path,
@doc("Set exclude file (default: checkstyle-exclude.json)")
["-e", "--exclude"] => function(path:String) excludePath = path,
@doc("Set reporter (xml, json or text, default: text)")
["-r", "--reporter"] => function(name:String) REPORT_TYPE = name,
@doc("Set reporter output path")
["-p", "--path"] => function(path:String) {
XML_PATH = path;
JSON_PATH = path;
TEXT_PATH = path;
},
@doc("Set reporter style (XSLT)") ["-x", "--xslt"] => function(style:String) STYLE = style,
@doc("Sets the number of checker threads") ["-checkerthreads"] => function (num:Int) configParser.overrideCheckerThreads = num,
@doc("Generate a default config and exit") ["-default-config", "--default-config"] => function(path) generateDefaultConfig(path),
@doc("Try to detect your coding style (experimental)") ["-detect"] => function (path) detectCodingStyle(path),
@doc("Return number of failed checks in exitcode") ["-exitcode"] => function() EXIT_CODE = true,
@doc("List all available checks and exit") ["-list-checks", "--list-checks"] => function() listChecks(),
@doc("List all available reporters and exit") ["-list-reporters", "--list-reporters"] => function() listReporters(),
@doc("Omit styling in output summary") ["-nostyle"] => function() NO_STYLE = true,
@doc("Do not use checker threads") ["-nothreads"] => function () disableThreads = true,
@doc("Show percentage progress") ["-progress"] => function() SHOW_PROGRESS = true,
@doc("Show checks missing from active config") ["-show-missing-checks"] => function () SHOW_MISSING_CHECKS = true,
@doc("Adds error messages for files that checkstyle fails to parse") ["-show-parser-errors"] => function ()
ReporterManager.SHOW_PARSE_ERRORS = true,
@doc("Set reporter style (XSLT)")
["-x", "--xslt"] => function(style:String) STYLE = style,
@doc("Sets the number of checker threads")
["-checkerthreads"] => function(num:Int) configParser.overrideCheckerThreads = num,
@doc("Generate a default config and exit")
["-default-config", "--default-config"] => function(path) generateDefaultConfig(path),
@doc("Try to detect your coding style (experimental)")
["-detect"] => function(path) detectCodingStyle(path),
@doc("Return number of failed checks in exitcode")
["-exitcode"] => function() EXIT_CODE = true,
@doc("List all available checks and exit")
["-list-checks", "--list-checks"] => function() listChecks(),
@doc("List all available reporters and exit")
["-list-reporters", "--list-reporters"] => function() listReporters(),
@doc("Omit styling in output summary")
["-nostyle"] => function() NO_STYLE = true,
@doc("Do not use checker threads")
["-nothreads"] => function() disableThreads = true,
@doc("Show percentage progress")
["-progress"] => function() SHOW_PROGRESS = true,
@doc("Show checks missing from active config")
["-show-missing-checks"] => function() SHOW_MISSING_CHECKS = true,
@doc("Adds error messages for files that checkstyle fails to parse")
["-show-parser-errors"] => function() ReporterManager.SHOW_PARSE_ERRORS = true,
_ => function(arg:String) failWith("Unknown command: " + arg)
]);

Expand Down Expand Up @@ -120,11 +135,17 @@ class Main {
var totalChecks = configParser.getCheckCount();
var checksUsed = configParser.getUsedCheckCount();
return switch (REPORT_TYPE) {
case "xml": new XMLReporter(numFiles, totalChecks, checksUsed, XML_PATH, STYLE, NO_STYLE);
case "json": new JSONReporter(numFiles, totalChecks, checksUsed, JSON_PATH, NO_STYLE);
case "text": new TextReporter(numFiles, totalChecks, checksUsed, TEXT_PATH, NO_STYLE);
case "codeclimate": new CodeClimateReporter(numFiles, totalChecks, checksUsed, null, NO_STYLE);
default: failWith('Unknown reporter: $REPORT_TYPE'); null;
case "xml":
new XMLReporter(numFiles, totalChecks, checksUsed, XML_PATH, STYLE, NO_STYLE);
case "json":
new JSONReporter(numFiles, totalChecks, checksUsed, JSON_PATH, NO_STYLE);
case "text":
new TextReporter(numFiles, totalChecks, checksUsed, TEXT_PATH, NO_STYLE);
case "codeclimate":
new CodeClimateReporter(numFiles, totalChecks, checksUsed, null, NO_STYLE);
default:
failWith('Unknown reporter: $REPORT_TYPE');
null;
}
}

Expand Down Expand Up @@ -204,7 +225,9 @@ class Main {
files.sortStrings();

var i:Int = 0;
return [for (file in files) { name:file, content:null, index:i++ }];
return [
for (file in files) {name: file, content: null, index: i++}
];
}

function traverse(path:String, files:Array<String>) {
Expand Down
3 changes: 1 addition & 2 deletions src/checkstyle/ParserQueue.hx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import cpp.hl.Thread;
import checkstyle.utils.Mutex;
import checkstyle.utils.Thread;
#end

class ParserQueue {
static inline var SLEEP_TIME:Float = 0.1;

Expand Down Expand Up @@ -44,7 +43,7 @@ class ParserQueue {
Sys.sleep(SLEEP_TIME);
continue;
}
var file = files.shift ();
var file = files.shift();
var checker:Checker = new Checker();
checker.baseDefines = templateChecker.baseDefines;
checker.defineCombinations = templateChecker.defineCombinations;
Expand Down
12 changes: 6 additions & 6 deletions src/checkstyle/SeverityLevel.hx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package checkstyle;

/**
sets gravity of reported violations:
- IGNORE = do not report violations, violations do not appear anywhere in output
- INFO = all violations have info / lowest priority
- WARNING = all violations have warning / medium priority
- ERROR = all violations have error / highest priority
**/
sets gravity of reported violations:
- IGNORE = do not report violations, violations do not appear anywhere in output
- INFO = all violations have info / lowest priority
- WARNING = all violations have warning / medium priority
- ERROR = all violations have error / highest priority
**/
@:enum
abstract SeverityLevel(String) from String {
var INFO = "INFO";
Expand Down
Loading