XAMPPRocky / tokei

Count your code, quickly.
Other
11.37k stars 542 forks source link

--type filters don’t apply to embedded languages #813

Open chris-morgan opened 3 years ago

chris-morgan commented 3 years ago

Tokei 12.1.2 on Arch Linux.

Here’s some usual output:

$ tokei
===============================================================================
 Language            Files        Lines         Code     Comments       Blanks
===============================================================================
 Markdown                1           33            0           24            9
 TOML                    1           17           13            1            3
-------------------------------------------------------------------------------
 Rust                   40        10389         9381          244          764
 |- Markdown            29          701            0          686           15
 (Total)                          11090         9381          930          779
===============================================================================
 Total                  42        10439         9394          269          776
===============================================================================

But --type filters only apply to the top-level language, and so --type=Rust shows embedded Markdown, which I don’t think it should:

$ tokei --type=Rust
===============================================================================
 Language            Files        Lines         Code     Comments       Blanks
===============================================================================
 Rust                   40        10389         9381          244          764
 |- Markdown            29          701            0          686           15
 (Total)                          11090         9381          930          779
===============================================================================
 Total                  40        10389         9381          244          764
===============================================================================

(In this simple case, --compact would resolve it, but if you allowed more than one type you could get to wanting to include some and hide others.)

And --type=Markdown doesn’t include Markdown embedded in Rust (whether it should or not is more subjective):

$ tokei --type=Markdown
===============================================================================
 Language            Files        Lines         Code     Comments       Blanks
===============================================================================
 Markdown                1           33            0           24            9
===============================================================================
 Total                   1           33            0           24            9
===============================================================================

I think there are three reasonable behaviours people might want here:

  1. Apply the type filter at the file level only (the current behaviour);
  2. Apply the type filter at all levels, ignoring and not reporting on embedded code that doesn’t match the type filter;
  3. Find embedded code that matches the filter, even in files that don’t match (so --type=Markdown would find doc comments in Rust files).

Perhaps there should be a tristate parameter to control this, e.g. --type-filter=files|all|any.

(Example repository used was swash_demo.)

XAMPPRocky commented 3 years ago

Thank you for your issue! I'm reticent to make this too much more complex, as the JSON output does already provide everything, I will think about some more and would be interested in hearing other people's opinions.

sasanquaneuf commented 2 years ago

Hello! I applied tokei to my web application, and obtained the following outputs [one] and [two]:

[one] (branch a)

===============================================================================
 Language            Files        Lines         Code     Comments       Blanks
===============================================================================
 Batch                   4           18           15            0            3
 CSS                    70        36431        31550          780         4101
 INI                     5          596          525           35           36
 JavaScript            356        43263        34611         4773         3879
 JSON                   21         3729         3727            0            2
 Markdown               23          611            0          413          198
 Python                535       123085       105052         4336        13697
 Sass                   26         3635         3020           33          582
 Shell                   9          196          142           23           31
 SQL                     2            6            6            0            0
 SVG                    95         3404         3391           11            2
 Plain Text            160         1109            0         1032           77
 TypeScript             82         9380         7128         1314          938
-------------------------------------------------------------------------------
 HTML                  547        42550        41213          328         1009
 |- CSS                351        16344        14237          104         2003
 |- HTML                 1           28           28            0            0
 |- JavaScript         419        26886        25056         1050          780
 (Total)                          85808        80534         1482         3792
-------------------------------------------------------------------------------
 Vue                   260        12097        11560            5          532
 |- CSS                123         4766         4367           44          355
 |- HTML               242        10869        10785           77            7
 |- JavaScript         257        34695        32675          940         1080
 (Total)                          62427        59387         1066         1974
===============================================================================
 Total                2195       280110       241940        13083        25087
===============================================================================

[two] (branch b)

===============================================================================
 Language            Files        Lines         Code     Comments       Blanks
===============================================================================
 Batch                   4           18           15            0            3
 CSS                    70        36431        31550          780         4101
 INI                     5          606          524           46           36
 JavaScript            356        43263        34611         4773         3879
 JSON                   21         3729         3727            0            2
 Markdown               23          611            0          413          198
 Python                523       120112       102447         4262        13403
 Sass                   26         3635         3020           33          582
 Shell                   9          196          142           23           31
 SQL                     2            6            6            0            0
 SVG                    95         3404         3391           11            2
 Plain Text            160         1109            0         1032           77
 TypeScript             82         9380         7128         1314          938
-------------------------------------------------------------------------------
 HTML                  483        36890        35686          303          901
 |- CSS                305        10573         9290           49         1234
 |- HTML                 1           28           28            0            0
 |- JavaScript         373        21273        19698          940          635
 (Total)                          68764        64702         1292         2770
-------------------------------------------------------------------------------
 Vue                   260        12097        11560            5          532
 |- CSS                123         4766         4367           44          355
 |- HTML               242        10869        10785           77            7
 |- JavaScript         257        34695        32675          940         1080
 (Total)                          62427        59387         1066         1974
===============================================================================
 Total                2119       271487       233807        12995        24685
===============================================================================

and I was confused by the difference of GitHub's addition/deletion line (branch b - branch a). GitHub shows "+80 −20,125", this is not equal to 271487 - 280110.

mark-summerfield commented 2 years ago

I also don't find the output of embedded languages within a file helpful. Why not simply offer a separate flag, say, --noembedded that ignores embedded languages?