Implement BLANK metric (#142)
* Implement Blank metric * Update tests * Add Blank to README * Add unit tests for Blank metric
This commit is contained in:
Родитель
9b527ea5f0
Коммит
86ac7c967c
|
@ -26,6 +26,7 @@ control flow of a program.
|
|||
- SLOC: it counts the number of lines in a source file.
|
||||
- LLOC: it counts the number of logical lines (instructions) contained in a source file.
|
||||
- CLOC: it counts the number of comments in a source file.
|
||||
- BLANK: it counts the number of blank lines in a source file.
|
||||
- HALSTEAD: it is a suite that provides a series of information, such as the effort required to maintain the analyzed code, the size in bits to store the program, the difficulty to understand the code, an estimate of the number of bugs present in the codebase, and an estimate of the time needed to implement the software.
|
||||
- MI: it is a suite that allows to evaluate the maintainability of a software.
|
||||
- NOM: it counts the number of functions and closures in a file/trait/class.
|
||||
|
|
46
src/loc.rs
46
src/loc.rs
|
@ -21,10 +21,11 @@ impl Serialize for Stats {
|
|||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let mut st = serializer.serialize_struct("loc", 3)?;
|
||||
let mut st = serializer.serialize_struct("loc", 4)?;
|
||||
st.serialize_field("sloc", &self.sloc())?;
|
||||
st.serialize_field("lloc", &self.lloc())?;
|
||||
st.serialize_field("cloc", &self.cloc())?;
|
||||
st.serialize_field("blank", &self.blank())?;
|
||||
st.end()
|
||||
}
|
||||
}
|
||||
|
@ -33,10 +34,11 @@ impl fmt::Display for Stats {
|
|||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"sloc: {}, lloc: {}, cloc: {}",
|
||||
"sloc: {}, lloc: {}, cloc: {}, blank: {}",
|
||||
self.sloc(),
|
||||
self.lloc(),
|
||||
self.cloc()
|
||||
self.cloc(),
|
||||
self.blank(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -72,6 +74,11 @@ impl Stats {
|
|||
// https://en.wikipedia.org/wiki/Source_lines_of_code
|
||||
self.comment_lines as f64
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn blank(&self) -> f64 {
|
||||
self.sloc() - self.lloc() - self.cloc()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Loc
|
||||
|
@ -248,6 +255,39 @@ mod tests {
|
|||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_blank_python() {
|
||||
check_metrics!(
|
||||
"\na = 42\n\n",
|
||||
"foo.py",
|
||||
PythonParser,
|
||||
loc,
|
||||
[(blank, 1, usize)]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_blank_rust() {
|
||||
check_metrics!(
|
||||
"\nlet a = 42;\n\n",
|
||||
"foo.rs",
|
||||
RustParser,
|
||||
loc,
|
||||
[(blank, 1, usize)]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_blank_c() {
|
||||
check_metrics!(
|
||||
"\nint a = 42;\n\n",
|
||||
"foo.c",
|
||||
CppParser,
|
||||
loc,
|
||||
[(blank, 1, usize)]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cloc_python() {
|
||||
check_metrics!(
|
||||
|
|
|
@ -274,7 +274,8 @@ impl<'a> FuncSpace<'a> {
|
|||
let prefix = format!("{}{}", prefix, pref_child);
|
||||
Self::dump_value("sloc", stats.sloc(), &prefix, false, stdout)?;
|
||||
Self::dump_value("lloc", stats.lloc(), &prefix, false, stdout)?;
|
||||
Self::dump_value("cloc", stats.cloc(), &prefix, true, stdout)
|
||||
Self::dump_value("cloc", stats.cloc(), &prefix, false, stdout)?;
|
||||
Self::dump_value("blank", stats.blank(), &prefix, true, stdout)
|
||||
}
|
||||
|
||||
fn dump_nom(
|
||||
|
|
|
@ -650,7 +650,7 @@ mod tests {
|
|||
"n2": 1.0,
|
||||
"n1": 2.0,
|
||||
"volume": 4.754_887_502_163_468},
|
||||
"loc": {"cloc": 1.0, "lloc": 2.0, "sloc": 4.0},
|
||||
"loc": {"cloc": 1.0, "lloc": 2.0, "sloc": 4.0, "blank": 1.0},
|
||||
"nom": {"functions": 1.0, "closures": 0.0, "total": 1.0},
|
||||
"mi": {"mi_original": 140.204_331_558_152_12,
|
||||
"mi_sei": 161.644_455_240_662_24,
|
||||
|
@ -676,7 +676,7 @@ mod tests {
|
|||
"n2": 1.0,
|
||||
"n1": 2.0,
|
||||
"volume": 4.754_887_502_163_468},
|
||||
"loc": {"cloc": 0.0, "lloc": 2.0, "sloc": 2.0},
|
||||
"loc": {"cloc": 0.0, "lloc": 2.0, "sloc": 2.0, "blank": 0.0},
|
||||
"nom": {"functions": 1.0, "closures": 0.0, "total": 1.0},
|
||||
"mi": {"mi_original": 151.433_315_883_223_23,
|
||||
"mi_sei": 142.873_061_717_489_78,
|
||||
|
@ -728,7 +728,7 @@ mod tests {
|
|||
"n2": 1.0,
|
||||
"n1": 2.0,
|
||||
"volume": 4.754_887_502_163_468},
|
||||
"loc": {"cloc": 0.0, "lloc": 2.0, "sloc": 2.0},
|
||||
"loc": {"cloc": 0.0, "lloc": 2.0, "sloc": 2.0, "blank": 0.0},
|
||||
"nom": {"functions": 1.0, "closures": 0.0, "total": 1.0},
|
||||
"mi": {"mi_original": 151.433_315_883_223_23,
|
||||
"mi_sei": 142.873_061_717_489_78,
|
||||
|
@ -776,7 +776,7 @@ mod tests {
|
|||
"n2": 1.0,
|
||||
"n1": 2.0,
|
||||
"volume": 4.754_887_502_163_468},
|
||||
"loc": {"cloc": 0.0, "lloc": 2.0, "sloc": 2.0},
|
||||
"loc": {"cloc": 0.0, "lloc": 2.0, "sloc": 2.0, "blank": 0.0},
|
||||
"nom": {"functions": 1.0, "closures": 0.0, "total": 1.0},
|
||||
"mi": {"mi_original": 151.433_315_883_223_23,
|
||||
"mi_sei": 142.873_061_717_489_78,
|
||||
|
@ -802,7 +802,7 @@ mod tests {
|
|||
"n2": 1.0,
|
||||
"n1": 2.0,
|
||||
"volume": 4.754_887_502_163_468},
|
||||
"loc": {"cloc": 0.0, "lloc": 2.0, "sloc": 2.0},
|
||||
"loc": {"cloc": 0.0, "lloc": 2.0, "sloc": 2.0, "blank": 0.0},
|
||||
"nom": {"functions": 1.0, "closures": 0.0, "total": 1.0},
|
||||
"mi": {"mi_original": 151.433_315_883_223_23,
|
||||
"mi_sei": 142.873_061_717_489_78,
|
||||
|
|
Загрузка…
Ссылка в новой задаче