cloc
cloc copied to clipboard
Wrong line count for the language Elm (and maybe other languages too) when encounter certain characters
The following line of Elm code make the counter to stop the count:
Html.node "style" [] [ Html.text "div[role=button] {-webkit-tap-highlight-color: transparent}" ]
For example, this file 4 lines of code are reported correctly:
module Main exposing (main)
import Html
main =
Html.node "style" [] [ Html.text "div[role=button] {-webkit-tap-highlight-color: transparent}" ]
But for this file, still 4 lines of code are reported, wrongly.
module Main exposing (main)
import Html
main =
Html.node "style" [] [ Html.text "div[role=button] {-webkit-tap-highlight-color: transparent}" ]
a =
3
The culprit seems being {-}, or a similar string where the dash can be followed by any character, like {-xxx}.
Yes, this is an anticipated bug with roots back to SLOCCount, ref the comment block for function remove_haskell_comments() (which is included as an Elm filter) beginning at
https://github.com/AlDanial/cloc/blob/9b1c380fdad27bcf9e86e5884467167b51873adf/cloc#L7361. It is the {- inside the string that the code doesn't account for. I'll have to add logic to see if comment markers are inside a string.
Take your time. For the moment I just added a space between { and - (that is still valid CSS) 😊
Well, I did take my time :) I reran the original case reported as showing 3 lines instead of 4. cloc 1.98 reports the answer is 4 although I don't recall actively changing anything for Elm since then. Can you try with the latest cloc?