Skip to content

Commit

Permalink
fixed suppression fro MethodLengthCheck
Browse files Browse the repository at this point in the history
added testcases for ConstantNameCheck
added ignoreSingleline to LeftCurlyCheck
applied new formatter
  • Loading branch information
AlexHaxe committed May 20, 2019
1 parent 7f87576 commit 4af7cff
Show file tree
Hide file tree
Showing 17 changed files with 185 additions and 91 deletions.
21 changes: 18 additions & 3 deletions checkstyle.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@
"ENUM_DEF",
"ABSTRACT_DEF",
"TYPEDEF_DEF",
"INTERFACE_DEF",
"INTERFACE_DEF",
"ARRAY_COMPREHENSION",
"FUNCTION",
"FOR",
"IF",
Expand All @@ -184,6 +185,17 @@
},
"type": "LeftCurly"
},
{
"props": {
"tokens": [
"ANON_TYPE"
],
"ignoreEmptySingleline": true,
"ignoreSingleline": true,
"option": "nl"
},
"type": "LeftCurly"
},
{
"props": {
"max": 160,
Expand Down Expand Up @@ -636,16 +648,19 @@
"checkstyle/checks/metrics/CyclomaticComplexityCheck"
],
"MethodLength": [
"checkstyle/checks/block/LeftCurlyCheck:detectableInstances",
"checkstyle/checks/metrics/CyclomaticComplexityCheck",
"checkstyle/checks/whitespace/OperatorWhitespaceCheck",
"checkstyle/checks/whitespace/OperatorWhitespaceCheck:detectableInstances",
"checkstyle/checks/whitespace/WhitespaceAfterCheck",
"checkstyle/checks/whitespace/WhitespaceAroundCheck",
"checkstyle/checks/whitespace/EmptyLinesCheck",
"checkstyle/checks/whitespace/IndentationCheck",
"checkstyle/token/walk/WalkStatement",
"checkstyle/utils/ExprUtils",
"checkstyle/utils/ComplexTypeUtils",
"checkstyle/Main"
"checkstyle/Main",
"JsonSchemaGenerator:genSchema",
"CheckstyleSchemaGenerator:checkstyleFieldsCallback"
],
"NestedForDepth": [
"TestMain"
Expand Down
1 change: 1 addition & 0 deletions hxformat.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"emptyLines": {
"finalNewline": false,
"lineCommentsBetweenFunctions":"none",
"interfaceEmptyLines": {
"beginType": 1
}
Expand Down
10 changes: 8 additions & 2 deletions resources/checkstyle-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,11 @@
"type": "object",
"description": "Checks for the placement of left curly braces (`{`) for code blocks. The policy to verify is specified using the property `option`.",
"properties": {
"ignoreSingleline": {
"type": "boolean",
"description": "allow single line blocks",
"propertyOrder": 3
},
"tokens": {
"items": {
"enum": [
Expand All @@ -1095,6 +1100,7 @@
"ABSTRACT_DEF",
"TYPEDEF_DEF",
"INTERFACE_DEF",
"ANON_TYPE",
"OBJECT_DECL",
"FUNCTION",
"FOR",
Expand All @@ -1114,7 +1120,7 @@
},
"ignoreEmptySingleline": {
"type": "boolean",
"description": "allow single line blocks",
"description": "allow empty single line blocks",
"propertyOrder": 2
},
"option": {
Expand All @@ -1136,7 +1142,7 @@
],
"type": "string",
"description": "sets gravity of reported violations:\n\t- IGNORE = do not report violations, violations do not appear anywhere in output\n\t- INFO = all violations have info / lowest priority\n\t- WARNING = all violations have warning / medium priority\n\t- ERROR = all violations have error / highest priority",
"propertyOrder": 3
"propertyOrder": 4
}
},
"additionalProperties": false
Expand Down
1 change: 1 addition & 0 deletions resources/default-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
},
{
"props": {
"ignoreSingleline": false,
"tokens": [
"CLASS_DEF",
"ENUM_DEF",
Expand Down
49 changes: 28 additions & 21 deletions schema/CheckstyleSchemaGenerator.hx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ typedef CheckName = {
#end

class CheckstyleSchemaGenerator {

macro public static function generate(type:String, id:String):Expr {
return JsonSchemaGenerator.generateWithCallback(type, id, checkstyleFieldsCallback);
}
Expand All @@ -25,26 +24,26 @@ class CheckstyleSchemaGenerator {
static function checkstyleFieldsCallback(fields:Array<ObjectDeclField>, name:String, pos:Position, refs:DynamicAccess<Expr>):Void {
switch (name) {
case "ExcludeConfig":
var checkList:Array<CheckName> = collectAllChecks(Path.join (["src", "checkstyle", "checks"]));
var checkList:Array<CheckName> = collectAllChecks(Path.join(["src", "checkstyle", "checks"]));
sortStrings(checkList);
var order:Int = fields.length;
for (check in checkList) {
var filterListType = Context.getType("checkstyle.config.ExcludeConfig.ExcludeFilterList");
fields.push({
field:check.name,
expr:JsonSchemaGenerator.genSchema(filterListType, "ExcludeFilterList", pos, null, refs, order++, null)
field: check.name,
expr: JsonSchemaGenerator.genSchema(filterListType, "ExcludeFilterList", pos, null, refs, order++, null)
});
}
case "Config.checks":
fields.pop();
fields.pop();
refs.remove("CheckConfig");
var checkExprs:Array<Expr> = [];
var checkList:Array<CheckName> = collectAllChecks(Path.join (["src", "checkstyle", "checks"]));
var checkList:Array<CheckName> = collectAllChecks(Path.join(["src", "checkstyle", "checks"]));
sortStrings(checkList);
for (check in checkList) {
if (check.name == "") continue;
var type:String = check.path.substr (4);
var type:String = check.path.substr(4);
checkExprs.push(genCheckSchema(Context.getType(type), check.name, pos, null, refs, -1));
}
fields.push({field: "type", expr: macro "array"});
Expand Down Expand Up @@ -104,7 +103,7 @@ class CheckstyleSchemaGenerator {
}
var fullPath:String = ~/[\/\\]/g.replace(Path.join([path, name]), ".");
name = name.substr(0, name.length - 5);
checks.push({name:name, path:fullPath});
checks.push({name: name, path: fullPath});
}
return checks;
}
Expand All @@ -113,7 +112,7 @@ class CheckstyleSchemaGenerator {
switch (type) {
case TInst(_.get() => cl, params):
switch [cl, params] {
case [{name:name, fields:fields}, []]:
case [{name: name, fields: fields}, []]:
if (!refs.exists(name)) {
refs[name] = null;
var classFields:Array<ObjectDeclField> = [];
Expand All @@ -122,22 +121,25 @@ class CheckstyleSchemaGenerator {
classFields.push({
field: "severity",
expr: JsonSchemaGenerator.genSchema(Context.getType("checkstyle.SeverityLevel"),
typeName + ".severity", pos, null, refs, classFields.length, null)
typeName
+ ".severity",
pos,
null,
refs,
classFields.length,
null)
});

var doc:StructInfo = {name: name, doc: getDescMeta(cl.meta)};
var props = SchemaUtils.makeObject(SchemaUtils.makeObjectDecl(classFields, null, -1, pos), doc, [], -1, pos);
var checkName:Array<Expr> = [macro '$typeName'];
var typeExpr:Expr = macro $a{checkName};
var type = SchemaUtils.makeEnum(typeExpr, doc, -1, pos);
var checkFields:Array<ObjectDeclField> = [
{field: "type", expr: type},
{field: "props", expr: props},
];
var checkFields:Array<ObjectDeclField> = [{field: "type", expr: type}, {field: "props", expr: props}];
var classExpr:Expr = SchemaUtils.makeObject(SchemaUtils.makeObjectDecl(checkFields, null, -1, pos), doc, [], -1, pos);
refs[name] = classExpr;
}
return SchemaUtils.makeObjectDecl([{ field: "@$__hx__$ref", expr: macro '#/definitions/${name}'}], null, order, pos);
return SchemaUtils.makeObjectDecl([{field: "@$__hx__$ref", expr: macro '#/definitions/${name}'}], null, order, pos);
default:
}
default:
Expand All @@ -151,21 +153,26 @@ class CheckstyleSchemaGenerator {
case FVar(_):
if (field.isPublic) {
var doc:StructInfo = SchemaUtils.makeStructInfo(field.name, field.doc);
classFields.push ({
classFields.push({
field: field.name,
expr: JsonSchemaGenerator.genSchema(field.type, typeName + "." + field.name, pos, doc, refs, classFields.length, checkstyleFieldsCallback)
expr: JsonSchemaGenerator.genSchema(field.type,
typeName
+ "."
+ field.name,
pos,
doc,
refs,
classFields.length,
checkstyleFieldsCallback)
});
}
default:
}
}
}

static function addSuperClassFields(typeName:String,
classFields:Array<ObjectDeclField>,
superClass:Null<{t:Ref<ClassType>, params:Array<Type>}>,
pos:Position,
refs:DynamicAccess<Expr>) {
static function addSuperClassFields(typeName:String, classFields:Array<ObjectDeclField>, superClass:Null<{t:Ref<ClassType>, params:Array<Type>}>,
pos:Position, refs:DynamicAccess<Expr>) {
if (superClass == null) return;
if (superClass.t.get().name == "Check") return;
addClassFields(typeName, classFields, superClass.t.get().fields.get(), pos, refs);
Expand Down
38 changes: 16 additions & 22 deletions schema/JsonSchemaGenerator.hx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ typedef ExtendedFieldsCB = Array<ObjectDeclField> -> String -> Position -> Dynam

// adapted from https://github.com/nadako/haxe-type-to-json-schema
class JsonSchemaGenerator {

macro public static function generate(type:String, id:String):Expr {
return generateWithCallback(type, id, null);
}
Expand All @@ -25,16 +24,16 @@ class JsonSchemaGenerator {

var refList:Array<ObjectDeclField> = [];
for (name in refs.keys()) {
refList.push({field:name, expr:refs.get(name)});
refList.push({field: name, expr: refs.get(name)});
}

var definitions:Expr = SchemaUtils.makeObjectDecl(refList, null, -1, Context.currentPos());
switch (main.expr) {
case EObjectDecl(fields):
fields.push ({field: "definitions", expr:definitions});
fields.push ({field: "@$__hx__$schema", expr: macro "http://json-schema.org/schema#"});
fields.push({field: "definitions", expr: definitions});
fields.push({field: "@$__hx__$schema", expr: macro "http://json-schema.org/schema#"});
if (id != null) {
fields.push ({field: "id", expr: macro '$id'});
fields.push({field: "id", expr: macro '$id'});
}
default:
}
Expand Down Expand Up @@ -71,12 +70,8 @@ class JsonSchemaGenerator {
}
}

public static function genSchema(type:Type,
typeName:String,
pos:Position,
structInfo:Null<StructInfo>,
refs:DynamicAccess<Expr>, order:Int,
extendCB:ExtendedFieldsCB):Expr {
public static function genSchema(type:Type, typeName:String, pos:Position, structInfo:Null<StructInfo>, refs:DynamicAccess<Expr>, order:Int,
extendCB:ExtendedFieldsCB):Expr {
switch (type) {
case TType(_.get() => dt, params):
return switch [dt, params] {
Expand All @@ -86,17 +81,16 @@ class JsonSchemaGenerator {
if (!refs.exists(dt.name)) {
refs[dt.name] = null;
var doc:StructInfo = SchemaUtils.makeStructInfo(dt.name, dt.doc);
var schema = genSchema(dt.type.applyTypeParameters(dt.params, params),
dt.name, dt.pos, doc, refs, -1, extendCB);
var schema = genSchema(dt.type.applyTypeParameters(dt.params, params), dt.name, dt.pos, doc, refs, -1, extendCB);
refs[dt.name] = schema;
}
return SchemaUtils.makeObjectDecl([{ field: "@$__hx__$ref", expr: macro '#/definitions/${dt.name}'}], structInfo, order, pos);
}
return SchemaUtils.makeObjectDecl([{field: "@$__hx__$ref", expr: macro '#/definitions/${dt.name}'}], structInfo, order, pos);
}

case TInst(_.get() => cl, params):
switch [cl, params] {
case [{pack: [], name: "String"}, []]:
return SchemaUtils.makeObjectDecl([{ field: "type", expr: macro "string"}], structInfo, order, pos);
return SchemaUtils.makeObjectDecl([{field: "type", expr: macro "string"}], structInfo, order, pos);
case [{pack: [], name: "Array"}, [elemType]]:
var fields:Array<ObjectDeclField> = [
{field: "type", expr: macro "array"},
Expand All @@ -117,14 +111,14 @@ class JsonSchemaGenerator {
if (extendCB != null) extendCB(fields, typeName, pos, refs);
return SchemaUtils.makeObjectDecl(fields, structInfo, order, pos);
case [{pack: [], name: "Float"}, []]:
return SchemaUtils.makeObjectDecl([{ field: "type", expr: macro "number"}], structInfo, order, pos);
return SchemaUtils.makeObjectDecl([{field: "type", expr: macro "number"}], structInfo, order, pos);
case [{pack: [], name: "Bool"}, []]:
return SchemaUtils.makeObjectDecl([{ field: "type", expr: macro "boolean"}], structInfo, order, pos);
return SchemaUtils.makeObjectDecl([{field: "type", expr: macro "boolean"}], structInfo, order, pos);
case [{pack: [], name: "Any"}, []]:
return SchemaUtils.makeObjectDecl([{ field: "type", expr: macro "object"}], structInfo, order, pos);
return SchemaUtils.makeObjectDecl([{field: "type", expr: macro "object"}], structInfo, order, pos);
default:
if (ab.meta.has(":enum")) {
if (structInfo == null ) structInfo = SchemaUtils.makeStructInfo(ab.name, ab.doc);
if (structInfo == null) structInfo = SchemaUtils.makeStructInfo(ab.name, ab.doc);
var pack:Array<String> = ab.module.split(".");
if (pack[pack.length - 1] != ab.name) pack.push(ab.name);
return SchemaUtils.makeEnum(getAbstractEnumValues(macro $p{pack}), structInfo, order, pos);
Expand All @@ -139,15 +133,15 @@ class JsonSchemaGenerator {
for (i in 0...anon.fields.length) {
var f = anon.fields[i];
var doc:StructInfo = SchemaUtils.makeStructInfo(f.name, f.doc);
props.push ({field: f.name, expr: genSchema(f.type, typeName + "." + f.name, f.pos, doc, refs, i, extendCB)});
props.push({field: f.name, expr: genSchema(f.type, typeName + "." + f.name, f.pos, doc, refs, i, extendCB)});
if (!f.meta.has(":optional")) {
required.push(f.name);
}
}
if (extendCB != null) {
extendCB(props, typeName, pos, refs);
}
return SchemaUtils.makeObject({pos: pos, expr:EObjectDecl(props)}, structInfo, required, order, pos);
return SchemaUtils.makeObject({pos: pos, expr: EObjectDecl(props)}, structInfo, required, order, pos);

default:
}
Expand Down
2 changes: 0 additions & 2 deletions schema/ObjectDeclField.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ typedef ObjectDeclField = {
var field:String;
var expr:Expr;
}

#else
typedef ObjectDeclField = haxe.macro.ObjectField;
#end

#end
1 change: 0 additions & 1 deletion schema/SchemaGenerator.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import haxe.io.Path;
import sys.io.File;

class SchemaGenerator {

public static function main() {
#if (haxe_ver < 4.0)
var exludeConfig = CheckstyleSchemaGenerator.generate("checkstyle.config.ExcludeConfig",
Expand Down
2 changes: 1 addition & 1 deletion src/checkstyle/CheckerThread.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package checkstyle;

#if ((haxe_ver >= 4.0) && (neko || macro || cpp || hl || java))
#if ((haxe_ver >= 4.0) && (neko || macro || eval || cpp || hl || java))
import sys.thread.Thread;
#elseif neko
import neko.vm.Thread;
Expand Down
2 changes: 1 addition & 1 deletion src/checkstyle/ParserQueue.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package checkstyle;

#if ((haxe_ver >= 4.0) && (neko || macro || cpp || hl || java))
#if ((haxe_ver >= 4.0) && (neko || macro || eval || cpp || hl || java))
import sys.thread.Mutex;
import sys.thread.Thread;
#elseif neko
Expand Down
Loading

0 comments on commit 4af7cff

Please sign in to comment.