COMMUNITY

Haxe-checkstyle release!

Last week I finally released checkstyle version 2.5.0 on haxelib, over a year after version 2.4.2 came out. Despite no releases in between checkstyle development wasn’t completely dormant, there were quite a few bug fixes including some null pointer crashes in C++ builds (and other targets).

Checkstyle code was reformatted using formatter. Compatibility between formatter and checkstyle is somewhat existing, but since formatter and checkstyle use different algorithms for whitespace calculation, they are not 100% compatible. There are no plans to remove whitespace checks from checkstyle, but only very limited amount of work is going into making them fully compatible. Chances are if you use formatter, then checkstyle whitespace checks are redundant. If you really want to ensure your whitespace is formatted according to formatter rules, use formatter with --check.

Checkstyle supports Haxe 4 code with the exception of inline (Not-)XML.

I have cleaned up command line options, because there was a bit of a mess with long and short options. Starting from 2.5.0 all long options will use --, whereas short options use -. So you might have to update your CI configuration, batch files or external command invocations.

I’ve added two new checks, one is BlockBreakingConditional which will display a message whenever an unbalanced amount of curlies appear inside a conditional section e.g. #if js if (condition) { #end.
The other is InlineFinal which generates a message for every inline var and suggest to change it to inline final. InlineFinal only makes sense for a Haxe 4 code base.

Checkstyle will try to detect nodeJS at startup (when called via haxelib run checkstyle) and if present will launch haxecheckstyle.js via node passing on your CLI parameters. That should speed up checking your code base.

Not for 2.5.0 release but slightly after, I have changed checkstyle’s build system to use lix. So it should be a lot easier to set up a development / git version of checkstyle because lix takes care of all dependencies and makes sure you have the correct versions. With a bit of manual adjustments you can even compile checkstyle with Haxe 3, by default checkstyle uses Haxe 4rc5.

You can find documentation for checkstyle’s checks at http://haxecheckstyle.github.io/docs, please report any issues here: https://github.com/HaxeCheckstyle/haxe-checkstyle/issues

VS Code plugin for checkstyle was updated as well, make sure you have version 1.4.0 installed.

7 Likes

New version 2.6.0 of checkstyle is out!
Along with it vscode-checkstyle extension version 1.5.0 is available on VSCode marketplace.

Breaking change Configuration setting MethodLength.countEmpty was changed to MethodLength.ignoreEmptyLines

New checkstyle comes with a few new checks:

  • CodeSimilarity - find similar or identical code blocks
    It operates on token level (operators, identifiers, keywords, parens, etc.).
    • Similar code blocks share the same structure, but use different identifiers, operators or values.
      It disregards comments and whitespace and classifies operators into different groups (arithmetic, logical, comparison, etc.), and allows variations within each group.
      So changing a + to - will still trigger a similarity warning, whereas swapping + with && will not.
    • Identical code blocks use the same structure, identifiers, operators and values. It also disregards comments and whitespace.
  • EnforceVarTypeHint - ensures that all vars have a type hint
  • AvoidIdentifier - discourages use of user defined identifiers
  • ArrowFunction - checks for curlies, nested functions and returns in arrow functions
  • NestedControlFlow - limits nested control flow expressions (e.g. if, for, while, do/while, switch and try)
    It’s a stricter version of NestedForDepth, NestedIfDepth and NestedTryDepth checks. e.g. NestedIfDepth only checked nesting levels of if with if. NestedControlFlow check will emit a warning for any nested combination of control flow expressions violating its max value.

Renamed AvoidInlineConditionals to AvoidTernaryOperator and InlineFinal to Final (old names still supported).

Updated reported positions for a few checks, so they don’t mark full function bodies or larger than necessary areas of code. Mostly useful for IDE integration like vscode-checkstyle extension.

4 Likes