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

Support final doc comment #487

Merged
merged 6 commits into from
Nov 2, 2019
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
1 change: 1 addition & 0 deletions .github/workflows/checkstyle-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
haxe-version: ['3.4.7', '4.0.0', 'nightly']
env:
CC_TEST_REPORTER_ID: 1dff6f89d7179dff5db635c6b4fe64acdd5694c9ed44d7da5f12f0f7d3d163b7
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
steps:
- uses: actions/checkout@v1
- name: Use Node.js 10
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ after_script:
- if [[ "$HAXE_VERSION" == "haxe4" ]]; then (cd src; ../cc-test-reporter upload-coverage); fi

after_success:
- if [[ "$HAXE_VERSION" == "haxe4" ]]; bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports"
- bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports"
12 changes: 8 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@

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

- **Breaking Change** changed `MethodLength.countEmpty` into `ignoreEmptyLines`
- **Breaking Change** changed `MethodLength.countEmpty` into `ignoreEmptyLines` ([#486](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/486))
- New check `CodeSimilarity` to check for similar or identical code blocks ([#479](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/479) + [#480](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/480) + [#484](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/484) + [#486](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/486))
- New check `EnforceVarTypeHint` to enforce type hints for all variables and finals, fixes [#464](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/464) ([#481](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/481) + [#482](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/482))
- New check `AvoidIdentifier` marks identifiers to avoid ([#483](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/483))
- New check `ArrowFunction` to check for curlies, nested functions and returns in arrow functions ([#484](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/484))
- New check `NestedControlFlow` to check for nested control flow expressions (e.g. `if`, `for`, `while`, `do/while`, `switch` and `try`) ([#485](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/485))
- Added coverage upload to codeclimate ([#478](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/478))
- Added `ignoreEmptyLines` in FileLengthCheck to ignore empty lines (default = true) ([#486](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/486))
- Added `ignoreEmptyLines` in `FileLengthCheck` to ignore empty lines (default = true) ([#486](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/486))
- Added support for final in `DocCommentStyle` and `FieldDocComment` checks ([#487](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/487))
- Added suggestion to use `final` for `public static var` fields in `Final` check ([#487](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/487))
- 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))
- Fixed allow excluding construtor (`new`) via range exclusion ([#479](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/479))
- Changed reported position for `FieldDocComment` and `MethodLength` to only include function signature ([#487](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/487))
- Fixed range exclusion to allow excluding construtor (`new`) ([#479](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/479))
- Refactored build system to use lix ([#478](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/478))
- Refactored / renamed AvoidInlineConditionals to AvoidTernaryOperator ([#479](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/479))
- Refactored / renamed `AvoidInlineConditionals` to `AvoidTernaryOperator` ([#479](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/479))
- Refactored / renamed `InlineFinal` to `Final` ([#487](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/487))

## version 2.5.0 (2019-10-10)

Expand Down
16 changes: 8 additions & 8 deletions resources/checkstyle-excludes-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
"$ref": "#/definitions/ExcludeFilterList",
"propertyOrder": 19
},
"Final": {
"$ref": "#/definitions/ExcludeFilterList",
"propertyOrder": 28
},
"MultipleStringLiterals": {
"$ref": "#/definitions/ExcludeFilterList",
"propertyOrder": 45
Expand Down Expand Up @@ -89,7 +93,7 @@
},
"HexadecimalLiteral": {
"$ref": "#/definitions/ExcludeFilterList",
"propertyOrder": 28
"propertyOrder": 29
},
"WhitespaceAfter": {
"$ref": "#/definitions/ExcludeFilterList",
Expand Down Expand Up @@ -123,10 +127,6 @@
"$ref": "#/definitions/ExcludeFilterList",
"propertyOrder": 52
},
"InlineFinal": {
"$ref": "#/definitions/ExcludeFilterList",
"propertyOrder": 32
},
"AvoidStarImport": {
"$ref": "#/definitions/ExcludeFilterList",
"propertyOrder": 9
Expand All @@ -145,7 +145,7 @@
},
"HiddenField": {
"$ref": "#/definitions/ExcludeFilterList",
"propertyOrder": 29
"propertyOrder": 30
},
"UnnecessaryConstructor": {
"$ref": "#/definitions/ExcludeFilterList",
Expand Down Expand Up @@ -229,7 +229,7 @@
},
"Indentation": {
"$ref": "#/definitions/ExcludeFilterList",
"propertyOrder": 30
"propertyOrder": 31
},
"version": {
"maximum": 1,
Expand Down Expand Up @@ -262,7 +262,7 @@
},
"IndentationCharacter": {
"$ref": "#/definitions/ExcludeFilterList",
"propertyOrder": 31
"propertyOrder": 32
},
"MagicNumber": {
"$ref": "#/definitions/ExcludeFilterList",
Expand Down
86 changes: 43 additions & 43 deletions resources/checkstyle-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1679,38 +1679,6 @@
},
"type": "object"
},
"InlineFinalCheck": {
"description": "Checks for places that use inline var instead of inline final (Haxe 4+).",
"additionalProperties": false,
"properties": {
"type": {
"description": "Checks for places that use inline var instead of inline final (Haxe 4+).",
"type": "string",
"enum": [
"InlineFinal"
]
},
"props": {
"description": "Checks for places that use inline var instead of inline final (Haxe 4+).",
"additionalProperties": false,
"properties": {
"severity": {
"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",
"type": "string",
"enum": [
"INFO",
"WARNING",
"ERROR",
"IGNORE"
],
"propertyOrder": 0
}
},
"type": "object"
}
},
"type": "object"
},
"Threshold": {
"description": "threshold for code complexity",
"required": [
Expand Down Expand Up @@ -3059,6 +3027,10 @@
"$ref": "#/definitions/ExcludeFilterList",
"propertyOrder": 19
},
"Final": {
"$ref": "#/definitions/ExcludeFilterList",
"propertyOrder": 28
},
"MultipleStringLiterals": {
"$ref": "#/definitions/ExcludeFilterList",
"propertyOrder": 45
Expand Down Expand Up @@ -3124,7 +3096,7 @@
},
"HexadecimalLiteral": {
"$ref": "#/definitions/ExcludeFilterList",
"propertyOrder": 28
"propertyOrder": 29
},
"WhitespaceAfter": {
"$ref": "#/definitions/ExcludeFilterList",
Expand Down Expand Up @@ -3158,10 +3130,6 @@
"$ref": "#/definitions/ExcludeFilterList",
"propertyOrder": 52
},
"InlineFinal": {
"$ref": "#/definitions/ExcludeFilterList",
"propertyOrder": 32
},
"AvoidStarImport": {
"$ref": "#/definitions/ExcludeFilterList",
"propertyOrder": 9
Expand All @@ -3180,7 +3148,7 @@
},
"HiddenField": {
"$ref": "#/definitions/ExcludeFilterList",
"propertyOrder": 29
"propertyOrder": 30
},
"UnnecessaryConstructor": {
"$ref": "#/definitions/ExcludeFilterList",
Expand Down Expand Up @@ -3264,7 +3232,7 @@
},
"Indentation": {
"$ref": "#/definitions/ExcludeFilterList",
"propertyOrder": 30
"propertyOrder": 31
},
"version": {
"maximum": 1,
Expand Down Expand Up @@ -3297,7 +3265,7 @@
},
"IndentationCharacter": {
"$ref": "#/definitions/ExcludeFilterList",
"propertyOrder": 31
"propertyOrder": 32
},
"MagicNumber": {
"$ref": "#/definitions/ExcludeFilterList",
Expand Down Expand Up @@ -3716,6 +3684,38 @@
},
"type": "object"
},
"FinalCheck": {
"description": "Checks for places that use var instead of final (Haxe 4+).",
"additionalProperties": false,
"properties": {
"type": {
"description": "Checks for places that use var instead of final (Haxe 4+).",
"type": "string",
"enum": [
"Final"
]
},
"props": {
"description": "Checks for places that use var instead of final (Haxe 4+).",
"additionalProperties": false,
"properties": {
"severity": {
"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",
"type": "string",
"enum": [
"INFO",
"WARNING",
"ERROR",
"IGNORE"
],
"propertyOrder": 0
}
},
"type": "object"
}
},
"type": "object"
},
"ConditionalCompilationCheck": {
"description": "Checks placement and indentation of conditional compilation flags.",
"additionalProperties": false,
Expand Down Expand Up @@ -4299,6 +4299,9 @@
{
"$ref": "#/definitions/FileLengthCheck"
},
{
"$ref": "#/definitions/FinalCheck"
},
{
"$ref": "#/definitions/HexadecimalLiteralCheck"
},
Expand All @@ -4311,9 +4314,6 @@
{
"$ref": "#/definitions/IndentationCharacterCheck"
},
{
"$ref": "#/definitions/InlineFinalCheck"
},
{
"$ref": "#/definitions/InnerAssignmentCheck"
},
Expand Down
8 changes: 4 additions & 4 deletions resources/default-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@
"ignoreEmptyLines": true
}
},
{
"type": "Final",
"props": {}
},
{
"type": "HexadecimalLiteral",
"props": {
Expand Down Expand Up @@ -227,10 +231,6 @@
"ignorePattern": "^$"
}
},
{
"type": "InlineFinal",
"props": {}
},
{
"type": "InnerAssignment",
"props": {
Expand Down
2 changes: 1 addition & 1 deletion schema/CheckstyleSchemaGenerator.hx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class CheckstyleSchemaGenerator {
continue;
}
#if (haxe_ver < 4)
if (name == "InlineFinalCheck") {
if (name == "FinalCheck") {
continue;
}
#end
Expand Down
1 change: 1 addition & 0 deletions src/checkstyle/checks/comments/DocCommentStyleCheck.hx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class DocCommentStyleCheck extends Check {
Kwd(KwdInterface),
Kwd(KwdTypedef),
Kwd(KwdVar),
#if haxe4 Kwd(KwdFinal) #else Const(CIdent("final")) #end,
Kwd(KwdFunction)
], ALL);

Expand Down
35 changes: 33 additions & 2 deletions src/checkstyle/checks/comments/FieldDocCommentCheck.hx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,14 @@ class FieldDocCommentCheck extends Check {
var typeTokens = root.filter(typeTokenDefs, ALL);

var fieldTokenDefs:Array<TokenDef> = [];
if ((fieldType == VARS) || (fieldType == BOTH)) fieldTokenDefs.push(Kwd(KwdVar));
if ((fieldType == VARS) || (fieldType == BOTH)) {
fieldTokenDefs.push(Kwd(KwdVar));
#if haxe4
fieldTokenDefs.push(Kwd(KwdFinal));
#else
fieldTokenDefs.push(Const(CIdent("final")));
#end
}
if ((fieldType == FUNCTIONS) || (fieldType == BOTH)) fieldTokenDefs.push(Kwd(KwdFunction));

for (typeToken in typeTokens) {
Expand Down Expand Up @@ -112,8 +119,9 @@ class FieldDocCommentCheck extends Check {
var name:String = getTypeName(token);
if (excludeNames.indexOf(name) >= 0) return;
var prevToken:TokenTree = token.previousSibling;

if (prevToken == null || !prevToken.isComment()) {
logPos('Field "$name" should have documentation', token.getPos());
logPos('Field "$name" should have documentation', getReportPos(token));
return;
}
switch (prevToken.tok) {
Expand All @@ -123,6 +131,29 @@ class FieldDocCommentCheck extends Check {
}
}

/**
report function signature not body
@param token function or var token
@return Position token position without body
**/
public static function getReportPos(token:TokenTree):Position {
var pos:Position = token.getPos();
var body:Null<TokenTree> = token.access().firstChild().firstOf(POpen).token;
if (body == null) return pos;
body = body.nextSibling;
if (body == null) return pos;
switch (body.tok) {
case BrOpen:
case DblDot:
body = body.nextSibling;
default:
return pos;
}
if (body == null) return pos;
pos.max = body.pos.min;
return pos;
}

function checkIgnoreOverride(token:TokenTree):Bool {
if (!ignoreOverride) return false;
var ignoreTokens:Array<TokenTree> = token.filter([Kwd(KwdOverride)], FIRST);
Expand Down
Loading