diff --git a/.travis.yml b/.travis.yml index c9996f93..b0c5f25a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,3 +29,6 @@ matrix: - haxelib install hxargs 3.0.2 - haxelib install munit - sed -i 's/:3.3.0//' buildGlobal.hxml + allow_failures: + - haxe: development + diff --git a/CHANGES.md b/CHANGES.md index e7df9c72..3e966b93 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,6 @@ ## dev branch / next version (2.x.x) -- Added JSON schemas for `checkstyle.json` and `checkstyle-exclude.json` file formats [#431](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/431) +- Added JSON schemas for `checkstyle.json` and `checkstyle-exclude.json` file formats [#431](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/431) + [#432](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/432) ## version 2.4.0 (2018-06-02) diff --git a/checkstyle.json b/checkstyle.json index 72b1833b..ca35fd13 100644 --- a/checkstyle.json +++ b/checkstyle.json @@ -414,13 +414,13 @@ }, { "props": { - "spaceIfCondition": true, + "spaceIfCondition": "should", "spaceAroundBinop": true, - "spaceForLoop": true, + "spaceForLoop": "should", "ignoreRangeOperator": true, - "spaceWhileLoop": true, - "spaceCatch": true, - "spaceSwitchCase": true, + "spaceWhileLoop": "should", + "spaceCatch": "should", + "spaceSwitchCase": "should", "noSpaceAroundUnop": true }, "type": "Spacing" diff --git a/resources/checkstyle-schema.json b/resources/checkstyle-schema.json index 3743fa2b..f9c14494 100644 --- a/resources/checkstyle-schema.json +++ b/resources/checkstyle-schema.json @@ -405,6 +405,21 @@ "props": { "type": "object", "properties": { + "tokens": { + "items": { + "type": "string" + }, + "type": "array", + "propertyOrder": 0 + }, + "option": { + "enum": [ + "eol", + "nl" + ], + "type": "string", + "propertyOrder": 1 + }, "severity": { "enum": [ "INFO", @@ -413,7 +428,7 @@ "IGNORE" ], "type": "string", - "propertyOrder": 0 + "propertyOrder": 2 } }, "additionalProperties": false @@ -433,6 +448,28 @@ "props": { "type": "object", "properties": { + "ignoreExtern": { + "type": "boolean", + "propertyOrder": 2 + }, + "format": { + "type": "string", + "propertyOrder": 0 + }, + "tokens": { + "items": { + "anyOf": [ + "PUBLIC", + "PRIVATE", + "STATIC", + "NOTSTATIC", + "INLINE", + "NOTINLINE" + ] + }, + "type": "array", + "propertyOrder": 1 + }, "severity": { "enum": [ "INFO", @@ -441,7 +478,7 @@ "IGNORE" ], "type": "string", - "propertyOrder": 0 + "propertyOrder": 3 } }, "additionalProperties": false @@ -541,6 +578,28 @@ "props": { "type": "object", "properties": { + "ignoreExtern": { + "type": "boolean", + "propertyOrder": 2 + }, + "format": { + "type": "string", + "propertyOrder": 0 + }, + "tokens": { + "items": { + "anyOf": [ + "PUBLIC", + "PRIVATE", + "ENUM", + "CLASS", + "ABSTRACT", + "TYPEDEF" + ] + }, + "type": "array", + "propertyOrder": 1 + }, "severity": { "enum": [ "INFO", @@ -549,7 +608,7 @@ "IGNORE" ], "type": "string", - "propertyOrder": 0 + "propertyOrder": 3 } }, "additionalProperties": false @@ -857,6 +916,21 @@ "props": { "type": "object", "properties": { + "ignoreExtern": { + "type": "boolean", + "propertyOrder": 2 + }, + "format": { + "type": "string", + "propertyOrder": 0 + }, + "tokens": { + "items": { + "type": "string" + }, + "type": "array", + "propertyOrder": 1 + }, "severity": { "enum": [ "INFO", @@ -865,7 +939,7 @@ "IGNORE" ], "type": "string", - "propertyOrder": 0 + "propertyOrder": 3 } }, "additionalProperties": false @@ -1963,6 +2037,24 @@ "props": { "type": "object", "properties": { + "ignoreExtern": { + "type": "boolean", + "propertyOrder": 2 + }, + "format": { + "type": "string", + "propertyOrder": 0 + }, + "tokens": { + "items": { + "anyOf": [ + "INLINE", + "NOTINLINE" + ] + }, + "type": "array", + "propertyOrder": 1 + }, "severity": { "enum": [ "INFO", @@ -1971,7 +2063,7 @@ "IGNORE" ], "type": "string", - "propertyOrder": 0 + "propertyOrder": 3 } }, "additionalProperties": false @@ -2327,6 +2419,21 @@ "props": { "type": "object", "properties": { + "ignoreExtern": { + "type": "boolean", + "propertyOrder": 2 + }, + "format": { + "type": "string", + "propertyOrder": 0 + }, + "tokens": { + "items": { + "type": "string" + }, + "type": "array", + "propertyOrder": 1 + }, "severity": { "enum": [ "INFO", @@ -2335,7 +2442,7 @@ "IGNORE" ], "type": "string", - "propertyOrder": 0 + "propertyOrder": 3 } }, "additionalProperties": false @@ -2451,6 +2558,27 @@ "props": { "type": "object", "properties": { + "ignoreExtern": { + "type": "boolean", + "propertyOrder": 2 + }, + "format": { + "type": "string", + "propertyOrder": 0 + }, + "tokens": { + "items": { + "anyOf": [ + "INTERFACE", + "CLASS", + "ENUM", + "ABSTRACT", + "TYPEDEF" + ] + }, + "type": "array", + "propertyOrder": 1 + }, "severity": { "enum": [ "INFO", @@ -2459,7 +2587,7 @@ "IGNORE" ], "type": "string", - "propertyOrder": 0 + "propertyOrder": 3 } }, "additionalProperties": false @@ -2836,6 +2964,21 @@ "props": { "type": "object", "properties": { + "tokens": { + "items": { + "type": "string" + }, + "type": "array", + "propertyOrder": 0 + }, + "option": { + "enum": [ + "eol", + "nl" + ], + "type": "string", + "propertyOrder": 1 + }, "severity": { "enum": [ "INFO", @@ -2844,7 +2987,7 @@ "IGNORE" ], "type": "string", - "propertyOrder": 0 + "propertyOrder": 2 } }, "additionalProperties": false diff --git a/schema/CheckstyleSchemaGenerator.hx b/schema/CheckstyleSchemaGenerator.hx index dd13f22b..f7faf8e9 100644 --- a/schema/CheckstyleSchemaGenerator.hx +++ b/schema/CheckstyleSchemaGenerator.hx @@ -60,6 +60,19 @@ class CheckstyleSchemaGenerator { case "ExcludeConfig.version": fields.push({field: "minimum", expr: macro 1}); fields.push({field: "maximum", expr: macro 1}); + case "ConstantName.tokens.items": + makeAnyOfAbstract(fields, "checkstyle.checks.naming.ConstantNameCheck.ConstantNameCheckToken", pos); + case "LocalVariableName.tokens.items": + fields.push({field: "type", expr: macro "string"}); + case "MemberName.tokens.items": + makeAnyOfAbstract(fields, "checkstyle.checks.naming.MemberNameCheck.MemberNameCheckToken", pos); + case "MethodName.tokens.items": + makeAnyOfAbstract(fields, "checkstyle.checks.naming.MethodNameCheck.MethodNameCheckToken", pos); + case "ParameterName.tokens.items": + fields.push({field: "type", expr: macro "string"}); + case "TypeName.tokens.items": + makeAnyOfAbstract(fields, "checkstyle.checks.naming.TypeNameCheck.TypeNameCheckToken", pos); + default: } } @@ -104,23 +117,12 @@ class CheckstyleSchemaGenerator { if (!refs.exists(name)) { refs[name] = null; var classFields:Array = []; - var fieldOrder:Int = 0; - for (field in fields.get()) { - switch (field.kind) { - case FVar(_): - if (field.isPublic) { - classFields.push ({ - field: field.name, - expr: JsonSchemaGenerator.genSchema(field.type, typeName + "." + name, pos, null, refs, fieldOrder, null) - }); - fieldOrder++; - } - default: - } - } + addSuperClassFields(typeName, classFields, cl.superClass, pos, refs); + addClassFields(typeName, classFields, fields.get(), pos, refs); classFields.push({ field: "severity", - expr: JsonSchemaGenerator.genSchema(Context.getType("checkstyle.SeverityLevel"), typeName + ".severity", pos, null, refs, fieldOrder, null) + expr: JsonSchemaGenerator.genSchema(Context.getType("checkstyle.SeverityLevel"), + typeName + ".severity", pos, null, refs, classFields.length, null) }); var props = SchemaUtils.makeObject(SchemaUtils.makeObjectDecl(classFields, -1, pos), null, [], -1, pos); @@ -141,5 +143,35 @@ class CheckstyleSchemaGenerator { } throw new Error("Cannot generate Json schema for type " + type, pos); // + type.toString(), pos); } + + static function addClassFields(typeName:String, classFields:Array, fields:Array, pos:Position, refs:DynamicAccess) { + for (field in fields) { + switch (field.kind) { + case FVar(_): + if (field.isPublic) { + classFields.push ({ + field: field.name, + expr: JsonSchemaGenerator.genSchema(field.type, typeName + "." + field.name, pos, null, refs, classFields.length, checkstyleFieldsCallback) + }); + } + default: + } + } + } + + static function addSuperClassFields(typeName:String, + classFields:Array, + superClass:Null<{t:Ref, params:Array}>, + pos:Position, + refs:DynamicAccess) { + if (superClass == null) return; + if (superClass.t.get().name == "Check") return; + addClassFields(typeName, classFields, superClass.t.get().fields.get(), pos, refs); + } + + static function makeAnyOfAbstract(fields:Array, type:String, pos:Position) { + var values:Expr = JsonSchemaGenerator.getAbstractEnumValues(macro $p{type.split(".")}); + fields.push({field: "anyOf", expr: values}); + } #end } \ No newline at end of file diff --git a/schema/JsonSchemaGenerator.hx b/schema/JsonSchemaGenerator.hx index 7903ef72..6c75fa11 100644 --- a/schema/JsonSchemaGenerator.hx +++ b/schema/JsonSchemaGenerator.hx @@ -41,8 +41,7 @@ class JsonSchemaGenerator { return main; } - static function getAbstractEnumValues(typePath:Expr):Expr { - // trace (typePath); + public static function getAbstractEnumValues(typePath:Expr):Expr { // Get the type from a given expression converted to string. // This will work for identifiers and field access which is what we need, // it will also consider local imports. If expression is not a valid type path or type is not found, @@ -100,11 +99,14 @@ class JsonSchemaGenerator { case [{pack: [], name: "Array"}, [elemType]]: var fields:Array = [ {field: "type", expr: macro "array"}, - {field: "items", expr: genSchema(elemType, typeName, pos, null, refs, -1, extendCB)} + {field: "items", expr: genSchema(elemType, typeName + ".items", pos, null, refs, -1, extendCB)} ]; if (extendCB != null) extendCB(fields, typeName, pos, refs); return SchemaUtils.makeObjectDecl(fields, order, pos); default: + var fields:Array = []; + if (extendCB != null) extendCB(fields, typeName, pos, refs); + if (fields.length > 0) return SchemaUtils.makeObjectDecl(fields, order, pos); } case TAbstract(_.get() => ab, params): diff --git a/schema/SchemaUtils.hx b/schema/SchemaUtils.hx index e8a4216e..09a49874 100644 --- a/schema/SchemaUtils.hx +++ b/schema/SchemaUtils.hx @@ -19,7 +19,7 @@ class SchemaUtils { fields.push({field: "description", expr: macro structInfo.doc.trim()}); } if (required.length > 0) { - var exprs:Array = [for(req in required) macro $v{req}]; + var exprs:Array = [for (req in required) macro $v{req}]; fields.push({field: "required", expr: macro $a{exprs}}); } return makeObjectDecl(fields, order, pos);