1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
use serde::Serialize;
/// Every language netto knows about.
///
/// The goal is to cover any framework someone might run netto against —
/// Flutter, Next.js, Svelte, Express, Laravel, Rails, Django, Spring,
/// Unity, and everything in between. If a file extension maps to a
/// language here, netto will count it. If not, it silently skips it.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize)]
pub enum Language {
// ── Systems ───────────────────────────────────────────────
Rust,
C,
Cpp,
CSharp, // Unity, .NET, ASP.NET
Zig,
// ── JVM ───────────────────────────────────────────────────
Java, // Spring, Android
Kotlin, // Android, Ktor
Scala, // Spark, Play
Groovy, // Gradle build scripts
// ── Web — compiled ────────────────────────────────────────
TypeScript, // Next.js, Remix, Angular, NestJS
JavaScript, // Express, Svelte (compiled), React, Vue
// ── Web — templated ───────────────────────────────────────
Html,
Css,
Scss, // Sass/SCSS — separate from plain CSS
Less,
Svelte, // .svelte files are HTML+JS+CSS in one
Vue, // .vue files — same idea
Astro, // .astro files — Astro framework
Htmx, // .html counted under Html; this covers .htmx if used
// ── Scripting ─────────────────────────────────────────────
Python, // Django, FastAPI, Flask
Ruby, // Rails, Sinatra
Php, // Laravel, WordPress, Symfony
Perl,
Lua, // Neovim plugins, game scripting
// ── Mobile ────────────────────────────────────────────────
Dart, // Flutter
Swift, // iOS, macOS
ObjectiveC, // Legacy iOS/macOS
// ── Functional ────────────────────────────────────────────
Haskell,
Elixir, // Phoenix
Erlang,
Clojure,
FSharp,
OCaml,
// ── Go ecosystem ──────────────────────────────────────────
Go, // Gin, Echo, Fiber
// ── Data / ML ─────────────────────────────────────────────
Julia,
R,
Notebooks, // .ipynb — Jupyter
// ── Infrastructure / config ───────────────────────────────
Shell, // bash, zsh, sh
PowerShell,
Dockerfile,
// ── Query ─────────────────────────────────────────────────
Sql,
GraphQL,
// ── Serialisation / config (not source, but tracked) ──────
Json,
Yaml,
Toml,
Xml,
// ── Docs ──────────────────────────────────────────────────
Markdown,
Rst, // reStructuredText — Python docs
Latex,
// ── Catch-all ─────────────────────────────────────────────
Other,
}
impl Language {
/// Map a file extension to a Language.
/// Returns None for extensions netto doesn't recognise
/// (lock files, images, fonts, etc.) — those files are skipped.
pub fn from_extension(ext: &str) -> Option<Self> {
let lang = match ext.to_lowercase().as_str() {
// Systems
"rs" => Self::Rust,
"c" | "h" => Self::C,
"cpp" | "cc" | "cxx" |
"hpp" | "hxx" | "hh" => Self::Cpp,
"cs" => Self::CSharp,
"zig" => Self::Zig,
// JVM
"java" => Self::Java,
"kt" | "kts" => Self::Kotlin,
"scala" | "sc" => Self::Scala,
"groovy" | "gradle" => Self::Groovy,
// Web — compiled
"ts" | "tsx" | "mts" | "cts" => Self::TypeScript,
"js" | "jsx" | "mjs" |
"cjs" => Self::JavaScript,
// Web — templated
"html" | "htm" | "xhtml" => Self::Html,
"css" => Self::Css,
"scss" => Self::Scss,
"less" => Self::Less,
"svelte" => Self::Svelte,
"vue" => Self::Vue,
"astro" => Self::Astro,
"htmx" => Self::Htmx,
// Scripting
"py" | "pyw" | "pyx" => Self::Python,
"rb" | "rake" | "gemspec" => Self::Ruby,
"php" | "php3" | "php4" |
"php5" | "phtml" => Self::Php,
"pl" | "pm" => Self::Perl,
"lua" => Self::Lua,
// Mobile
"dart" => Self::Dart,
"swift" => Self::Swift,
"m" | "mm" => Self::ObjectiveC,
// Functional
"hs" | "lhs" => Self::Haskell,
"ex" | "exs" => Self::Elixir,
"erl" | "hrl" => Self::Erlang,
"clj" | "cljs" | "cljc" => Self::Clojure,
"fs" | "fsx" | "fsi" => Self::FSharp,
"ml" | "mli" => Self::OCaml,
// Go
"go" => Self::Go,
// Data / ML
"jl" => Self::Julia,
"r" | "rmd" => Self::R,
"ipynb" => Self::Notebooks,
// Infrastructure
"sh" | "bash" | "zsh" |
"fish" | "ksh" => Self::Shell,
"ps1" | "psm1" | "psd1" => Self::PowerShell,
"dockerfile" => Self::Dockerfile,
// Query
"sql" => Self::Sql,
"graphql" | "gql" => Self::GraphQL,
// Config / serialisation
"json" | "jsonc" => Self::Json,
"yml" | "yaml" => Self::Yaml,
"toml" => Self::Toml,
"xml" | "xsl" | "xslt" => Self::Xml,
// Docs
"md" | "mdx" => Self::Markdown,
"rst" => Self::Rst,
"tex" | "sty" => Self::Latex,
// Generic catch-all for ini/env/conf style files
"ini" | "env" | "conf" |
"cfg" | "properties" => Self::Other,
_ => return None,
};
Some(lang)
}
/// Human-readable name shown in the output.
pub fn display_name(self) -> &'static str {
match self {
Self::Rust => "Rust",
Self::C => "C",
Self::Cpp => "C++",
Self::CSharp => "C#",
Self::Zig => "Zig",
Self::Java => "Java",
Self::Kotlin => "Kotlin",
Self::Scala => "Scala",
Self::Groovy => "Groovy",
Self::TypeScript => "TypeScript",
Self::JavaScript => "JavaScript",
Self::Html => "HTML",
Self::Css => "CSS",
Self::Scss => "SCSS",
Self::Less => "Less",
Self::Svelte => "Svelte",
Self::Vue => "Vue",
Self::Astro => "Astro",
Self::Htmx => "HTMX",
Self::Python => "Python",
Self::Ruby => "Ruby",
Self::Php => "PHP",
Self::Perl => "Perl",
Self::Lua => "Lua",
Self::Dart => "Dart",
Self::Swift => "Swift",
Self::ObjectiveC => "Objective-C",
Self::Haskell => "Haskell",
Self::Elixir => "Elixir",
Self::Erlang => "Erlang",
Self::Clojure => "Clojure",
Self::FSharp => "F#",
Self::OCaml => "OCaml",
Self::Go => "Go",
Self::Julia => "Julia",
Self::R => "R",
Self::Notebooks => "Jupyter Notebook",
Self::Shell => "Shell",
Self::PowerShell => "PowerShell",
Self::Dockerfile => "Dockerfile",
Self::Sql => "SQL",
Self::GraphQL => "GraphQL",
Self::Json => "JSON",
Self::Yaml => "YAML",
Self::Toml => "TOML",
Self::Xml => "XML",
Self::Markdown => "Markdown",
Self::Rst => "reStructuredText",
Self::Latex => "LaTeX",
Self::Other => "Other",
}
}
/// Single-line comment prefix(es) for this language.
/// Used by the counter to skip comment lines.
pub fn line_comment_prefixes(self) -> &'static [&'static str] {
match self {
// // style
Self::Rust | Self::C | Self::Cpp | Self::CSharp |
Self::Zig | Self::Java | Self::Kotlin | Self::Scala |
Self::Groovy | Self::TypeScript | Self::JavaScript |
Self::Svelte | Self::Vue | Self::Astro | Self::Go |
Self::Swift | Self::Dart | Self::FSharp |
Self::Css | Self::Scss | Self::Less => &["//"],
// # style
Self::Python | Self::Ruby | Self::Shell |
Self::PowerShell | Self::Perl | Self::R |
Self::Julia | Self::Yaml | Self::Dockerfile |
Self::Elixir | Self::Other => &["#"],
// -- style
Self::Haskell | Self::Sql | Self::Lua => &["--"],
// ; style
Self::Clojure => &[";"],
// % style
Self::Erlang | Self::Latex => &["%"],
// No line comments
Self::Html | Self::Xml | Self::Json |
Self::Toml | Self::Markdown | Self::Rst |
Self::GraphQL | Self::ObjectiveC |
Self::OCaml | Self::Htmx | Self::Php |
Self::Notebooks => &[],
}
}
/// Opening and closing delimiters for block comments, if the language has them.
pub fn block_comment_delimiters(self) -> Option<(&'static str, &'static str)> {
match self {
Self::Rust | Self::C | Self::Cpp | Self::CSharp |
Self::Java | Self::Kotlin | Self::Scala | Self::Groovy |
Self::TypeScript | Self::JavaScript | Self::Go |
Self::Swift | Self::Dart | Self::Css |
Self::Scss | Self::Less | Self::Php => Some(("/*", "*/")),
Self::Html | Self::Svelte |
Self::Astro | Self::Htmx | Self::Xml => Some(("<!--", "-->")),
Self::Python => Some(("\"\"\"", "\"\"\"")),
Self::Haskell => Some(("{-", "-}")),
Self::OCaml => Some(("(*", "*)")),
Self::Lua => Some(("--[[", "]]")),
Self::Erlang => Some(("%{", "}")), // not standard but safe
// Vue and Astro have sections — treated as HTML for block comments
Self::Vue => Some(("<!--", "-->")),
_ => None,
}
}
/// Whether this language counts toward the "source lines" total.
///
/// Config, data, and doc files are tracked for the breakdown chart
/// but don't count toward the "I wrote this" score — they inflate
/// the number without reflecting actual programming work.
pub fn is_source_language(self) -> bool {
matches!(
self,
Self::Rust
| Self::C
| Self::Cpp
| Self::CSharp
| Self::Zig
| Self::Java
| Self::Kotlin
| Self::Scala
| Self::Groovy
| Self::TypeScript
| Self::JavaScript
| Self::Svelte
| Self::Vue
| Self::Astro
| Self::Htmx
| Self::Python
| Self::Ruby
| Self::Php
| Self::Perl
| Self::Lua
| Self::Dart
| Self::Swift
| Self::ObjectiveC
| Self::Haskell
| Self::Elixir
| Self::Erlang
| Self::Clojure
| Self::FSharp
| Self::OCaml
| Self::Go
| Self::Julia
| Self::R
| Self::Shell
| Self::PowerShell
| Self::Dockerfile
| Self::Sql
| Self::GraphQL
)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn maps_rust() { assert_eq!(Language::from_extension("rs"), Some(Language::Rust)); }
#[test]
fn maps_tsx() { assert_eq!(Language::from_extension("tsx"), Some(Language::TypeScript)); }
#[test]
fn maps_dart() { assert_eq!(Language::from_extension("dart"), Some(Language::Dart)); }
#[test]
fn maps_svelte() { assert_eq!(Language::from_extension("svelte"), Some(Language::Svelte)); }
#[test]
fn maps_vue() { assert_eq!(Language::from_extension("vue"), Some(Language::Vue)); }
#[test]
fn maps_astro() { assert_eq!(Language::from_extension("astro"), Some(Language::Astro)); }
#[test]
fn maps_swift() { assert_eq!(Language::from_extension("swift"), Some(Language::Swift)); }
#[test]
fn maps_kotlin() { assert_eq!(Language::from_extension("kt"), Some(Language::Kotlin)); }
#[test]
fn maps_elixir() { assert_eq!(Language::from_extension("ex"), Some(Language::Elixir)); }
#[test]
fn maps_php() { assert_eq!(Language::from_extension("php"), Some(Language::Php)); }
#[test]
fn maps_ruby() { assert_eq!(Language::from_extension("rb"), Some(Language::Ruby)); }
#[test]
fn unknown_returns_none() { assert_eq!(Language::from_extension("xyz"), None); }
#[test]
fn dart_is_source() { assert!(Language::Dart.is_source_language()); }
#[test]
fn json_not_source() { assert!(!Language::Json.is_source_language()); }
#[test]
fn yaml_not_source() { assert!(!Language::Yaml.is_source_language()); }
#[test]
fn svelte_is_source(){ assert!(Language::Svelte.is_source_language()); }
}