XAMPPRocky / tokei

Count your code, quickly.
Other
10.84k stars 524 forks source link

Improved Vue and Svelte Support #784

Open Redfire75369 opened 3 years ago

Redfire75369 commented 3 years ago

Currently, .vue and .svelte files do not correctly report their embedded languages when not using the defaults.

Sample Vue File

<template lang="pug">
div
  p Here's some pug code.
</template>

<script lang="ts">
type Exports = {
  name: string
};
const exports: Exports = {
  name: "App"
};
export default exports;
</script>

<style lang="scss">
div {
  p {
    color: red;
  }
}
</style>

Tokei Output

===============================================================================
 Language            Files        Lines         Code     Comments       Blanks
===============================================================================
 Vue                     1            8            6            0            2
 |- CSS                  1            5            5            0            0
 |- JavaScript           1            7            7            0            0
 |- Pug                  1            2            2            0            0
 (Total)                             22           20            0            2
===============================================================================
 Total                   1            8            6            0            2
===============================================================================

There are many more than just TypeScript and SCSS, as shown here. The difficulty here comes from the fact that these files can support any number of new languages simply with the help of new loaders; it seems there would need to be a generic way to tokei to analyze them properly, using the lang attribute, for Vue and Svelte, and type attribute for Svelte (MIME Types).

As shown by the correct report of Pug in .vue files, such code to allow thing probably exists in the codebase and might only need to be extended to allow for <script> and <style> tags.

Changes will also have to be made to Svelte in languages.json to add <template to important_syntax.

Some languages that are affected include: Pug, CoffeeScript, TypeScript, LESS, PostCSS, Sass, Stylus and SugarSS.

XAMPPRocky commented 3 years ago

Thank you for your issue! I definitely want to add this.