AlDanial / cloc

cloc counts blank lines, comment lines, and physical lines of source code in many programming languages.
GNU General Public License v2.0
19.31k stars 1.02k forks source link

Wrong line count for the language Elm (and maybe other languages too) when encounter certain characters #568

Open lucamug opened 3 years ago

lucamug commented 3 years ago

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}.

AlDanial commented 3 years ago

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.

lucamug commented 3 years ago

Take your time. For the moment I just added a space between { and - (that is still valid CSS) 😊

AlDanial commented 10 months ago

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?

includesec-erik commented 1 month ago

@lucamug can you check to see if your original Elm counting edge case still exists with latest cloc?