Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 128x 128x 128x 128x 10x 10x 10x 10x 10x 10x 10x 10x 118x 128x 93x 93x 93x 93x 93x 93x 93x 93x 25x 128x 12x 12x 12x 12x 12x 12x 12x 12x 13x 13x 13x 13x 13x 13x 13x 13x 1x 1x 1x 1x 1x 103x 103x 321x 102x 102x 321x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 9x 9x 9x 9x 9x 9x 9x 27x 27x 27x 24x 24x 24x 24x 24x 27x 27x 27x 27x 19x 19x 19x 19x 19x 27x 27x 27x 27x 27x 2x 27x 2x 2x 9x 9x 9x 19x 19x 19x 9x 9x 9x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 2x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x | /**
* Language detection utility for file extensions
* Maps file extensions to programming languages for syntax highlighting
*/
import path from "path";
// Comprehensive mapping of file extensions to programming languages
const EXTENSION_LANGUAGE_MAP = {
// JavaScript/TypeScript ecosystem
".js": "javascript",
".jsx": "jsx",
".ts": "typescript",
".tsx": "tsx",
".mjs": "javascript",
".cjs": "javascript",
".vue": "vue",
".svelte": "svelte",
// Web technologies
".html": "html",
".htm": "html",
".xml": "xml",
".xhtml": "xhtml",
".css": "css",
".scss": "scss",
".sass": "sass",
".less": "less",
".stylus": "stylus",
// Python
".py": "python",
".pyx": "python",
".pyi": "python",
".pyw": "python",
".py3": "python",
// Java ecosystem
".java": "java",
".kt": "kotlin",
".kts": "kotlin",
".scala": "scala",
".groovy": "groovy",
".gradle": "gradle",
// C/C++
".c": "c",
".h": "c",
".cpp": "cpp",
".cxx": "cxx",
".cc": "cpp",
".hpp": "hpp",
".hxx": "hpp",
".hh": "hpp",
// C#/.NET
".cs": "csharp",
".vb": "vb",
".fs": "fsharp",
// Rust
".rs": "rust",
// Go
".go": "go",
// PHP
".php": "php",
".php3": "php",
".php4": "php",
".php5": "php",
".phtml": "php",
// Ruby
".rb": "ruby",
".rbw": "ruby",
".rake": "ruby",
".gemspec": "ruby",
// Swift
".swift": "swift",
// Objective-C
".m": "objective-c",
".mm": "objective-c",
// Shell scripts
".sh": "bash",
".bash": "bash",
".zsh": "zsh",
".fish": "fish",
".ksh": "ksh",
".csh": "csh",
".tcsh": "tcsh",
// PowerShell
".ps1": "powershell",
".psd1": "powershell",
".psm1": "powershell",
// Batch files
".bat": "batch",
".cmd": "batch",
// SQL
".sql": "sql",
".mysql": "sql",
".pgsql": "sql",
".plsql": "plsql",
// R
".r": "r",
".R": "r",
// MATLAB (Note: .m conflicts with Objective-C, we prioritize Objective-C)
".mlx": "matlab",
// Perl
".pl": "perl",
".pm": "perl",
".t": "perl",
// Lua
".lua": "lua",
// Haskell
".hs": "haskell",
".lhs": "haskell",
// Clojure
".clj": "clojure",
".cljs": "clojure",
".cljc": "clojure",
// Erlang/Elixir
".erl": "erlang",
".ex": "elixir",
".exs": "elixir",
// Dart
".dart": "dart",
// Configuration files
".json": "json",
".json5": "json5",
".jsonl": "jsonl",
".yaml": "yaml",
".yml": "yaml",
".toml": "toml",
".ini": "ini",
".cfg": "ini",
".conf": "apache",
".config": "xml",
// Markup languages
".md": "markdown",
".markdown": "markdown",
".mdown": "markdown",
".mkd": "markdown",
".rst": "rst",
".tex": "latex",
".bib": "bibtex",
// Docker
".dockerfile": "dockerfile",
".dockerignore": "ignore",
// Git
".gitignore": "ignore",
".gitattributes": "ignore",
// Other data formats
".csv": "csv",
".tsv": "tsv",
".log": "log",
".txt": "text",
// Build files
".mk": "makefile",
".cmake": "cmake",
".ninja": "ninja",
// Package managers
".lock": "text", // Various lock files
".sum": "text" // Checksums
};
// Special filename patterns that override extension-based detection
const FILENAME_LANGUAGE_MAP = {
"Dockerfile": "dockerfile",
"Makefile": "makefile",
"Rakefile": "ruby",
"Gemfile": "ruby",
"Guardfile": "ruby",
"Vagrantfile": "ruby",
"Jenkinsfile": "groovy",
".bashrc": "bash",
".zshrc": "zsh",
".vimrc": "vim",
".gitconfig": "ini",
".gitignore": "ignore",
".gitattributes": "ignore",
"package.json": "json",
"tsconfig.json": "json",
"composer.json": "json",
"bower.json": "json",
".eslintrc": "json",
".babelrc": "json",
".prettierrc": "json",
"webpack.config.js": "javascript",
"rollup.config.js": "javascript",
"vite.config.js": "javascript",
"jest.config.js": "javascript",
"tailwind.config.js": "javascript",
"next.config.js": "javascript",
"nuxt.config.js": "javascript",
"vue.config.js": "javascript",
"svelte.config.js": "javascript",
"astro.config.js": "javascript",
"vitest.config.js": "javascript",
"cypress.config.js": "javascript",
"playwright.config.js": "javascript",
"eslint.config.js": "javascript",
"prettier.config.js": "javascript",
"babel.config.js": "javascript",
"postcss.config.js": "javascript",
"karma.config.js": "javascript",
"gulpfile.js": "javascript",
"gruntfile.js": "javascript"
};
// Language categories for grouping
const LANGUAGE_CATEGORIES = {
"Web Frontend": [
"javascript",
"typescript",
"jsx",
"tsx",
"html",
"css",
"scss",
"sass",
"less",
"stylus",
"vue",
"svelte"
],
"Backend/Server": [
"python",
"java",
"csharp",
"php",
"ruby",
"go",
"rust",
"swift",
"kotlin",
"scala",
"groovy",
"nodejs"
],
"Systems/Low-level": ["c", "cpp", "rust", "go", "zig", "assembly"],
"Functional": ["haskell", "clojure", "erlang", "elixir", "fsharp", "ocaml"],
"Scripting": ["bash", "zsh", "fish", "powershell", "batch", "perl", "lua"],
"Data/Config": ["json", "yaml", "toml", "xml", "csv", "sql", "ini"],
"Documentation": ["markdown", "rst", "latex", "text"],
"Mobile": ["swift", "kotlin", "dart", "objective-c"],
"DevOps": ["dockerfile", "yaml", "bash", "makefile", "cmake", "ninja"]
};
/**
* Detect programming language from file path
* @param {string} filePath - The file path to analyze
* @returns {Object} - Language detection result
*/
export function detectLanguage(filePath) {
const basename = path.basename(filePath);
const extension = path.extname(filePath).toLowerCase();
// Check filename patterns first (more specific)
if (FILENAME_LANGUAGE_MAP[basename]) {
const language = FILENAME_LANGUAGE_MAP[basename];
return {
language,
confidence: "high",
source: "filename",
category: getCategoryForLanguage(language)
};
}
// Check extension patterns
if (EXTENSION_LANGUAGE_MAP[extension]) {
const language = EXTENSION_LANGUAGE_MAP[extension];
return {
language,
confidence: "medium",
source: "extension",
category: getCategoryForLanguage(language)
};
}
// Special cases for files without extensions
if (!extension) {
// Check if it might be a script with shebang
return {
language: "text",
confidence: "low",
source: "fallback",
category: "Other"
};
}
// Unknown file type
return {
language: "text",
confidence: "low",
source: "unknown",
category: "Other"
};
}
/**
* Get category for a language
* @param {string} language - The language identifier
* @returns {string} - The category name
*/
function getCategoryForLanguage(language) {
for (const [category, languages] of Object.entries(LANGUAGE_CATEGORIES)) {
if (languages.includes(language)) {
return category;
}
}
return "Other";
}
/**
* Get all supported languages
* @returns {Array} - Array of supported language identifiers
*/
export function getSupportedLanguages() {
const languages = new Set();
// Add all languages from extension map
Object.values(EXTENSION_LANGUAGE_MAP).forEach((lang) => languages.add(lang));
// Add all languages from filename map
Object.values(FILENAME_LANGUAGE_MAP).forEach((lang) => languages.add(lang));
return Array.from(languages).sort();
}
/**
* Get language statistics from file paths
* @param {Array<string>} filePaths - Array of file paths
* @returns {Object} - Language statistics
*/
export function getLanguageStats(filePaths) {
const stats = {
byLanguage: {},
byCategory: {},
total: filePaths.length,
unknown: 0
};
filePaths.forEach((filePath) => {
const detection = detectLanguage(filePath);
// Count by language
if (!stats.byLanguage[detection.language]) {
stats.byLanguage[detection.language] = {
count: 0,
files: []
};
}
stats.byLanguage[detection.language].count++;
stats.byLanguage[detection.language].files.push(filePath);
// Count by category
if (!stats.byCategory[detection.category]) {
stats.byCategory[detection.category] = {
count: 0,
languages: new Set()
};
}
stats.byCategory[detection.category].count++;
stats.byCategory[detection.category].languages.add(detection.language);
// Count unknown
if (
detection.confidence === "low" &&
(detection.source === "unknown" || detection.source === "fallback")
) {
stats.unknown++;
}
});
// Convert language sets to arrays for serialization
Object.keys(stats.byCategory).forEach((category) => {
stats.byCategory[category].languages = Array.from(
stats.byCategory[category].languages
);
});
return stats;
}
/**
* Format language detection for display
* @param {Object} detection - Language detection result
* @returns {string} - Formatted string
*/
export function formatLanguageDetection(detection) {
const confidence =
detection.confidence === "high"
? "✓"
: detection.confidence === "medium"
? "~"
: "?";
return `${detection.language} ${confidence} (${detection.source})`;
}
export default {
detectLanguage,
getSupportedLanguages,
getLanguageStats,
formatLanguageDetection,
LANGUAGE_CATEGORIES
};
|