Expand description
Counts the lines of a codebase: which language every file is written in, and how many of its lines are code, comments and neither.
A run takes two things. EngineConfig says what to count, and Languages says what the
symbols of each language are. The second is built against the first and refuses to be used with
any other, since counting Rust with settings that name Python would give figures that look
perfectly normal and describe something else.
use mezura_core::{CountingModel, EngineConfig, Languages, run};
let config = EngineConfig::new(["./src", "./tests"]);
let (languages, warnings) = Languages::shipped(&config);
for warning in &warnings {
eprintln!("{}", warning.message);
}
let result = run(&config, languages)?;
for (name, stats) in result.sort_languages_by(Default::default(), CountingModel::Content) {
println!("{name}: {} code", stats.calculate_code_lines(CountingModel::Content));
}Every line is sorted into one of the nine LineClasses, and a CountingModel folds those
nine into the three columns of a report, so one run answers both models.
run_watched is the same run for a caller that needs real time feedback while it happens, and
explain_file reads a single file line by line and says why each line was counted the way it
was.
Re-exports§
pub use engine::config::EngineConfig;pub use engine::config::ForcedLanguages;pub use engine::config::LanguageNames;pub use engine::config::ScopedByModule;pub use engine::config::Target;pub use engine::config::Threads;pub use engine::config::format_module_scope;pub use engine::config::split_off_module_scope;pub use engine::targets::TargetError;pub use languages::LanguageClaims;pub use languages::Languages;pub use warnings::Affects;pub use warnings::Code;pub use warnings::Warning;
Modules§
- engine
- The machinery that turns a set of targets into a result.
- language_
file - The format of a language file, which is the one thing under this roof that decides a number: what a language is called, which extensions it claims and which symbols open a comment.
- languages
- Which languages a run has in play, and which of them owns an extension two of them claim. The
format a language file is written in is
crate::language_filenext door. - render
- The arithmetic behind showing a result: shares, percentages, and how a number reads to a person. Nothing here decides a color, a width or a word, and nothing reads a global.
- warnings
- What a run wants the caller to know without it being an error: an answer was produced, and this says what to be careful about in it.
Structs§
- Claim
- One name a language claims, and which language a file wearing it is counted as.
- Explained
Line - What one line of the file came to.
- Faulty
File Details - A file that could not be read or parsed. Its lines are in no total, but it is counted among the files that were seen.
- File
Entry - One counted file.
- File
Explanation - One file read line by line, as
explain_fileanswers it. - Files
Present - How much of what the scan saw it had reason to count.
- Keyword
- A word worth counting occurrences of, under a name of its own.
- Language
- One language: what it is called, which files belong to it, and the symbols that decide what each of their lines is.
- Leveled
Pair - A long-bracket comment pair, split around the run of
=that gives it its level:--[=*[is the prefix--[and the suffix[. - Line
Classes - Where each line of a file landed, one slot per line, so the nine always add up to the lines.
- Line
Continuation - A line ending in this symbol is joined to the one after it, before anything is decided about either.
- Module
Result - One module and its own figures. A module is a target that was given a name, as in
mezura frontend=./web backend=./api. - Multiline
String - A string that crosses lines: the same symbol twice for Python’s
""", two different ones for a raw form liker#"with"#. - Nested
Language - One section of another language inside a file: everything between the two tags is counted with that language’s own symbols.
- Performance
- What the run cost.
- RunResult
- Everything one run of
crate::runproduced. - Scan
Progress - How far a run has got, for a caller that needs real time feedback.
- Skipped
Files - The paths of the files a run set aside after reading their head, by the reason each was set aside for.
- Span
- One stretch of a line, as
crate::explain_filereports it: which bytes sit inside a string, which inside a comment, and which outside both. - Stats
- What was counted, for one language, one module or a whole run.
- String
Rules - The symbols that open a string, and the one byte that cancels the symbol standing after it: the backslash in most languages, the backtick in PowerShell, and nothing in the family that escapes a quote by doubling it, which is what Pascal, Ada, Fortran, COBOL and standard SQL need.
- Unreadable
DirDetails - A directory that could not be opened, so nothing inside it reached any figure.
Enums§
- Bucket
- One of the three columns a report shows, which is what a
CountingModelfolds the nine classes into. - Carried
- What was open when a line began.
- Claim
Kind - The three ways a file’s name says what language it is. A whole name is answered before an
extension, and the
#!line only for a file that has neither. - Counting
Model - Where the code and comment columns come from.
- Explain
Error - Why a file could not be explained.
- Line
Class - Which of the nine a single line was sorted into. One variant per field of
LineClasses, named after it and described there. - RunError
- A run that produced nothing at all, as opposed to a run that produced zeros.
- Scan
Skip - The head check that sets a file aside in a directory scan.
- Settled
By - What decided a name that more than one language claimed.
- Sort
Criterion - Which figure decides the order of a report’s rows.
- Span
Kind - What a
Spanholds.
Constants§
- LANGUAGE_
CONFLICTS_ FILE_ NAME - The name of the file that decides which language gets an extension or a file name two of them claim.
- UNNAMED_
MODULE_ NAME - The name of the report row holding everything no target was given a name for.
Functions§
- explain_
file - Reads one file and answers for every line of it: which class it landed in, what earlier lines had left open, and which language’s rules read it.
- prints_
phase_ timing - Whether this run will print a report of where its time went to the error output, which the
MEZURA_PHASE_TIMINGenvironment variable asks for. - run
- Counts the directories and files the configuration names, and gives back the figures.
- run_
watched - The same run, for a caller that needs real time feedback while it happens.