Skip to content

Commit c2fc74a

Browse files
authored
Support final doc comment (#487)
* added support for final in DocCommentStyle and FieldDocComment * changed reported position for FieldDocComment and MethodLength * renamed InlineFinal to Final * added check for public static to Final check * updated message for public static var in Final check
1 parent 20e5435 commit c2fc74a

File tree

14 files changed

+174
-108
lines changed

14 files changed

+174
-108
lines changed

.github/workflows/checkstyle-linux.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
haxe-version: ['3.4.7', '4.0.0', 'nightly']
1919
env:
2020
CC_TEST_REPORTER_ID: 1dff6f89d7179dff5db635c6b4fe64acdd5694c9ed44d7da5f12f0f7d3d163b7
21+
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
2122
steps:
2223
- uses: actions/checkout@v1
2324
- name: Use Node.js 10

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ after_script:
4141
- if [[ "$HAXE_VERSION" == "haxe4" ]]; then (cd src; ../cc-test-reporter upload-coverage); fi
4242

4343
after_success:
44-
- if [[ "$HAXE_VERSION" == "haxe4" ]]; bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports"
44+
- bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports"

CHANGELOG.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@
22

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

5-
- **Breaking Change** changed `MethodLength.countEmpty` into `ignoreEmptyLines`
5+
- **Breaking Change** changed `MethodLength.countEmpty` into `ignoreEmptyLines` ([#486](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/486))
66
- 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))
77
- 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))
88
- New check `AvoidIdentifier` marks identifiers to avoid ([#483](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/483))
99
- New check `ArrowFunction` to check for curlies, nested functions and returns in arrow functions ([#484](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/484))
1010
- 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))
1111
- Added coverage upload to codeclimate ([#478](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/478))
12-
- Added `ignoreEmptyLines` in FileLengthCheck to ignore empty lines (default = true) ([#486](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/486))
12+
- Added `ignoreEmptyLines` in `FileLengthCheck` to ignore empty lines (default = true) ([#486](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/486))
13+
- Added support for final in `DocCommentStyle` and `FieldDocComment` checks ([#487](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/487))
14+
- Added suggestion to use `final` for `public static var` fields in `Final` check ([#487](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/487))
1315
- Changed default value for `max` in `FileLengthCheck` to 1000 ([#486](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/486))
1416
- Changed `MethodLength` check to use tokentree ([#486](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/486))
15-
- Fixed allow excluding construtor (`new`) via range exclusion ([#479](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/479))
17+
- Changed reported position for `FieldDocComment` and `MethodLength` to only include function signature ([#487](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/487))
18+
- Fixed range exclusion to allow excluding construtor (`new`) ([#479](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/479))
1619
- Refactored build system to use lix ([#478](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/478))
17-
- Refactored / renamed AvoidInlineConditionals to AvoidTernaryOperator ([#479](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/479))
20+
- Refactored / renamed `AvoidInlineConditionals` to `AvoidTernaryOperator` ([#479](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/479))
21+
- Refactored / renamed `InlineFinal` to `Final` ([#487](https://github.com/HaxeCheckstyle/haxe-checkstyle/issues/487))
1822

1923
## version 2.5.0 (2019-10-10)
2024

resources/checkstyle-excludes-schema.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
"$ref": "#/definitions/ExcludeFilterList",
2525
"propertyOrder": 19
2626
},
27+
"Final": {
28+
"$ref": "#/definitions/ExcludeFilterList",
29+
"propertyOrder": 28
30+
},
2731
"MultipleStringLiterals": {
2832
"$ref": "#/definitions/ExcludeFilterList",
2933
"propertyOrder": 45
@@ -89,7 +93,7 @@
8993
},
9094
"HexadecimalLiteral": {
9195
"$ref": "#/definitions/ExcludeFilterList",
92-
"propertyOrder": 28
96+
"propertyOrder": 29
9397
},
9498
"WhitespaceAfter": {
9599
"$ref": "#/definitions/ExcludeFilterList",
@@ -123,10 +127,6 @@
123127
"$ref": "#/definitions/ExcludeFilterList",
124128
"propertyOrder": 52
125129
},
126-
"InlineFinal": {
127-
"$ref": "#/definitions/ExcludeFilterList",
128-
"propertyOrder": 32
129-
},
130130
"AvoidStarImport": {
131131
"$ref": "#/definitions/ExcludeFilterList",
132132
"propertyOrder": 9
@@ -145,7 +145,7 @@
145145
},
146146
"HiddenField": {
147147
"$ref": "#/definitions/ExcludeFilterList",
148-
"propertyOrder": 29
148+
"propertyOrder": 30
149149
},
150150
"UnnecessaryConstructor": {
151151
"$ref": "#/definitions/ExcludeFilterList",
@@ -229,7 +229,7 @@
229229
},
230230
"Indentation": {
231231
"$ref": "#/definitions/ExcludeFilterList",
232-
"propertyOrder": 30
232+
"propertyOrder": 31
233233
},
234234
"version": {
235235
"maximum": 1,
@@ -262,7 +262,7 @@
262262
},
263263
"IndentationCharacter": {
264264
"$ref": "#/definitions/ExcludeFilterList",
265-
"propertyOrder": 31
265+
"propertyOrder": 32
266266
},
267267
"MagicNumber": {
268268
"$ref": "#/definitions/ExcludeFilterList",

resources/checkstyle-schema.json

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,38 +1679,6 @@
16791679
},
16801680
"type": "object"
16811681
},
1682-
"InlineFinalCheck": {
1683-
"description": "Checks for places that use inline var instead of inline final (Haxe 4+).",
1684-
"additionalProperties": false,
1685-
"properties": {
1686-
"type": {
1687-
"description": "Checks for places that use inline var instead of inline final (Haxe 4+).",
1688-
"type": "string",
1689-
"enum": [
1690-
"InlineFinal"
1691-
]
1692-
},
1693-
"props": {
1694-
"description": "Checks for places that use inline var instead of inline final (Haxe 4+).",
1695-
"additionalProperties": false,
1696-
"properties": {
1697-
"severity": {
1698-
"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",
1699-
"type": "string",
1700-
"enum": [
1701-
"INFO",
1702-
"WARNING",
1703-
"ERROR",
1704-
"IGNORE"
1705-
],
1706-
"propertyOrder": 0
1707-
}
1708-
},
1709-
"type": "object"
1710-
}
1711-
},
1712-
"type": "object"
1713-
},
17141682
"Threshold": {
17151683
"description": "threshold for code complexity",
17161684
"required": [
@@ -3059,6 +3027,10 @@
30593027
"$ref": "#/definitions/ExcludeFilterList",
30603028
"propertyOrder": 19
30613029
},
3030+
"Final": {
3031+
"$ref": "#/definitions/ExcludeFilterList",
3032+
"propertyOrder": 28
3033+
},
30623034
"MultipleStringLiterals": {
30633035
"$ref": "#/definitions/ExcludeFilterList",
30643036
"propertyOrder": 45
@@ -3124,7 +3096,7 @@
31243096
},
31253097
"HexadecimalLiteral": {
31263098
"$ref": "#/definitions/ExcludeFilterList",
3127-
"propertyOrder": 28
3099+
"propertyOrder": 29
31283100
},
31293101
"WhitespaceAfter": {
31303102
"$ref": "#/definitions/ExcludeFilterList",
@@ -3158,10 +3130,6 @@
31583130
"$ref": "#/definitions/ExcludeFilterList",
31593131
"propertyOrder": 52
31603132
},
3161-
"InlineFinal": {
3162-
"$ref": "#/definitions/ExcludeFilterList",
3163-
"propertyOrder": 32
3164-
},
31653133
"AvoidStarImport": {
31663134
"$ref": "#/definitions/ExcludeFilterList",
31673135
"propertyOrder": 9
@@ -3180,7 +3148,7 @@
31803148
},
31813149
"HiddenField": {
31823150
"$ref": "#/definitions/ExcludeFilterList",
3183-
"propertyOrder": 29
3151+
"propertyOrder": 30
31843152
},
31853153
"UnnecessaryConstructor": {
31863154
"$ref": "#/definitions/ExcludeFilterList",
@@ -3264,7 +3232,7 @@
32643232
},
32653233
"Indentation": {
32663234
"$ref": "#/definitions/ExcludeFilterList",
3267-
"propertyOrder": 30
3235+
"propertyOrder": 31
32683236
},
32693237
"version": {
32703238
"maximum": 1,
@@ -3297,7 +3265,7 @@
32973265
},
32983266
"IndentationCharacter": {
32993267
"$ref": "#/definitions/ExcludeFilterList",
3300-
"propertyOrder": 31
3268+
"propertyOrder": 32
33013269
},
33023270
"MagicNumber": {
33033271
"$ref": "#/definitions/ExcludeFilterList",
@@ -3716,6 +3684,38 @@
37163684
},
37173685
"type": "object"
37183686
},
3687+
"FinalCheck": {
3688+
"description": "Checks for places that use var instead of final (Haxe 4+).",
3689+
"additionalProperties": false,
3690+
"properties": {
3691+
"type": {
3692+
"description": "Checks for places that use var instead of final (Haxe 4+).",
3693+
"type": "string",
3694+
"enum": [
3695+
"Final"
3696+
]
3697+
},
3698+
"props": {
3699+
"description": "Checks for places that use var instead of final (Haxe 4+).",
3700+
"additionalProperties": false,
3701+
"properties": {
3702+
"severity": {
3703+
"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",
3704+
"type": "string",
3705+
"enum": [
3706+
"INFO",
3707+
"WARNING",
3708+
"ERROR",
3709+
"IGNORE"
3710+
],
3711+
"propertyOrder": 0
3712+
}
3713+
},
3714+
"type": "object"
3715+
}
3716+
},
3717+
"type": "object"
3718+
},
37193719
"ConditionalCompilationCheck": {
37203720
"description": "Checks placement and indentation of conditional compilation flags.",
37213721
"additionalProperties": false,
@@ -4299,6 +4299,9 @@
42994299
{
43004300
"$ref": "#/definitions/FileLengthCheck"
43014301
},
4302+
{
4303+
"$ref": "#/definitions/FinalCheck"
4304+
},
43024305
{
43034306
"$ref": "#/definitions/HexadecimalLiteralCheck"
43044307
},
@@ -4311,9 +4314,6 @@
43114314
{
43124315
"$ref": "#/definitions/IndentationCharacterCheck"
43134316
},
4314-
{
4315-
"$ref": "#/definitions/InlineFinalCheck"
4316-
},
43174317
{
43184318
"$ref": "#/definitions/InnerAssignmentCheck"
43194319
},

resources/default-config.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@
196196
"ignoreEmptyLines": true
197197
}
198198
},
199+
{
200+
"type": "Final",
201+
"props": {}
202+
},
199203
{
200204
"type": "HexadecimalLiteral",
201205
"props": {
@@ -227,10 +231,6 @@
227231
"ignorePattern": "^$"
228232
}
229233
},
230-
{
231-
"type": "InlineFinal",
232-
"props": {}
233-
},
234234
{
235235
"type": "InnerAssignment",
236236
"props": {

schema/CheckstyleSchemaGenerator.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class CheckstyleSchemaGenerator {
102102
continue;
103103
}
104104
#if (haxe_ver < 4)
105-
if (name == "InlineFinalCheck") {
105+
if (name == "FinalCheck") {
106106
continue;
107107
}
108108
#end

src/checkstyle/checks/comments/DocCommentStyleCheck.hx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class DocCommentStyleCheck extends Check {
3838
Kwd(KwdInterface),
3939
Kwd(KwdTypedef),
4040
Kwd(KwdVar),
41+
#if haxe4 Kwd(KwdFinal) #else Const(CIdent("final")) #end,
4142
Kwd(KwdFunction)
4243
], ALL);
4344

src/checkstyle/checks/comments/FieldDocCommentCheck.hx

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,14 @@ class FieldDocCommentCheck extends Check {
8080
var typeTokens = root.filter(typeTokenDefs, ALL);
8181

8282
var fieldTokenDefs:Array<TokenDef> = [];
83-
if ((fieldType == VARS) || (fieldType == BOTH)) fieldTokenDefs.push(Kwd(KwdVar));
83+
if ((fieldType == VARS) || (fieldType == BOTH)) {
84+
fieldTokenDefs.push(Kwd(KwdVar));
85+
#if haxe4
86+
fieldTokenDefs.push(Kwd(KwdFinal));
87+
#else
88+
fieldTokenDefs.push(Const(CIdent("final")));
89+
#end
90+
}
8491
if ((fieldType == FUNCTIONS) || (fieldType == BOTH)) fieldTokenDefs.push(Kwd(KwdFunction));
8592

8693
for (typeToken in typeTokens) {
@@ -112,8 +119,9 @@ class FieldDocCommentCheck extends Check {
112119
var name:String = getTypeName(token);
113120
if (excludeNames.indexOf(name) >= 0) return;
114121
var prevToken:TokenTree = token.previousSibling;
122+
115123
if (prevToken == null || !prevToken.isComment()) {
116-
logPos('Field "$name" should have documentation', token.getPos());
124+
logPos('Field "$name" should have documentation', getReportPos(token));
117125
return;
118126
}
119127
switch (prevToken.tok) {
@@ -123,6 +131,29 @@ class FieldDocCommentCheck extends Check {
123131
}
124132
}
125133

134+
/**
135+
report function signature not body
136+
@param token function or var token
137+
@return Position token position without body
138+
**/
139+
public static function getReportPos(token:TokenTree):Position {
140+
var pos:Position = token.getPos();
141+
var body:Null<TokenTree> = token.access().firstChild().firstOf(POpen).token;
142+
if (body == null) return pos;
143+
body = body.nextSibling;
144+
if (body == null) return pos;
145+
switch (body.tok) {
146+
case BrOpen:
147+
case DblDot:
148+
body = body.nextSibling;
149+
default:
150+
return pos;
151+
}
152+
if (body == null) return pos;
153+
pos.max = body.pos.min;
154+
return pos;
155+
}
156+
126157
function checkIgnoreOverride(token:TokenTree):Bool {
127158
if (!ignoreOverride) return false;
128159
var ignoreTokens:Array<TokenTree> = token.filter([Kwd(KwdOverride)], FIRST);

0 commit comments

Comments
 (0)