Skip to content

Commit f3ea9d8

Browse files
authored
Rename sloc metric suite to loc (#114)
* Rename sloc metric suite to loc Rename `sloc` to `loc` in order to be more consistent with the scientific literature * Remove useless parenthesis
1 parent 368d3c8 commit f3ea9d8

5 files changed

Lines changed: 35 additions & 44 deletions

File tree

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ pub use crate::cyclomatic::*;
3131
pub mod exit;
3232
pub use crate::exit::*;
3333

34-
pub mod sloc;
35-
pub use crate::sloc::*;
34+
pub mod loc;
35+
pub use crate::loc::*;
3636

3737
pub mod halstead;
3838
pub use crate::halstead::*;

src/sloc.rs renamed to src/loc.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl Stats {
5454
let sloc = if self.unit {
5555
self.end - self.start
5656
} else {
57-
((self.end - self.start) + 1)
57+
(self.end - self.start) + 1
5858
};
5959
sloc as f64
6060
}
@@ -70,7 +70,7 @@ impl Stats {
7070
}
7171
}
7272

73-
pub trait SourceLoc
73+
pub trait Loc
7474
where
7575
Self: Checker,
7676
{
@@ -98,7 +98,7 @@ fn init(node: &Node, stats: &mut Stats, is_func_space: bool, is_unit: bool) -> u
9898
start
9999
}
100100

101-
impl SourceLoc for PythonCode {
101+
impl Loc for PythonCode {
102102
fn compute(node: &Node, _code: &[u8], stats: &mut Stats, is_func_space: bool, is_unit: bool) {
103103
use Python::*;
104104

@@ -113,7 +113,7 @@ impl SourceLoc for PythonCode {
113113
}
114114
}
115115

116-
impl SourceLoc for MozjsCode {
116+
impl Loc for MozjsCode {
117117
fn compute(node: &Node, _code: &[u8], stats: &mut Stats, is_func_space: bool, is_unit: bool) {
118118
use Mozjs::*;
119119

@@ -128,7 +128,7 @@ impl SourceLoc for MozjsCode {
128128
}
129129
}
130130

131-
impl SourceLoc for JavascriptCode {
131+
impl Loc for JavascriptCode {
132132
fn compute(node: &Node, _code: &[u8], stats: &mut Stats, is_func_space: bool, is_unit: bool) {
133133
use Javascript::*;
134134

@@ -143,7 +143,7 @@ impl SourceLoc for JavascriptCode {
143143
}
144144
}
145145

146-
impl SourceLoc for TypescriptCode {
146+
impl Loc for TypescriptCode {
147147
fn compute(node: &Node, _code: &[u8], stats: &mut Stats, is_func_space: bool, is_unit: bool) {
148148
use Typescript::*;
149149

@@ -158,7 +158,7 @@ impl SourceLoc for TypescriptCode {
158158
}
159159
}
160160

161-
impl SourceLoc for TsxCode {
161+
impl Loc for TsxCode {
162162
fn compute(node: &Node, _code: &[u8], stats: &mut Stats, is_func_space: bool, is_unit: bool) {
163163
use Tsx::*;
164164

@@ -173,7 +173,7 @@ impl SourceLoc for TsxCode {
173173
}
174174
}
175175

176-
impl SourceLoc for RustCode {
176+
impl Loc for RustCode {
177177
fn compute(node: &Node, _code: &[u8], stats: &mut Stats, is_func_space: bool, is_unit: bool) {
178178
use Rust::*;
179179

@@ -189,7 +189,7 @@ impl SourceLoc for RustCode {
189189
}
190190
}
191191

192-
impl SourceLoc for CppCode {
192+
impl Loc for CppCode {
193193
fn compute(node: &Node, _code: &[u8], stats: &mut Stats, is_func_space: bool, is_unit: bool) {
194194
use Cpp::*;
195195

@@ -206,10 +206,10 @@ impl SourceLoc for CppCode {
206206
}
207207
}
208208

209-
impl SourceLoc for PreprocCode {}
210-
impl SourceLoc for CcommentCode {}
211-
impl SourceLoc for CSharpCode {}
212-
impl SourceLoc for JavaCode {}
213-
impl SourceLoc for GoCode {}
214-
impl SourceLoc for CssCode {}
215-
impl SourceLoc for HtmlCode {}
209+
impl Loc for PreprocCode {}
210+
impl Loc for CcommentCode {}
211+
impl Loc for CSharpCode {}
212+
impl Loc for JavaCode {}
213+
impl Loc for GoCode {}
214+
impl Loc for CssCode {}
215+
impl Loc for HtmlCode {}

src/metrics.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ use crate::exit::{self, Exit};
1414
use crate::fn_args::{self, NArgs};
1515
use crate::getter::Getter;
1616
use crate::halstead::{self, Halstead};
17-
use crate::sloc::{self, SourceLoc};
17+
use crate::loc::{self, Loc};
1818
use crate::tools::write_file;
1919
use crate::traits::*;
2020

2121
#[derive(Debug)]
2222
pub struct CodeMetrics<'a> {
2323
pub cyclomatic: cyclomatic::Stats,
2424
pub halstead: halstead::Stats<'a>,
25-
pub sloc: sloc::Stats,
25+
pub loc: loc::Stats,
2626
pub nargs: fn_args::Stats,
2727
pub nexits: exit::Stats,
2828
}
@@ -35,7 +35,7 @@ impl<'a> Serialize for CodeMetrics<'a> {
3535
let mut st = serializer.serialize_struct("metrics", 3)?;
3636
st.serialize_field("cyclomatic", &self.cyclomatic)?;
3737
st.serialize_field("halstead", &self.halstead)?;
38-
st.serialize_field("loc", &self.sloc)?;
38+
st.serialize_field("loc", &self.loc)?;
3939
st.serialize_field("nargs", &self.nargs)?;
4040
st.serialize_field("nexits", &self.nexits)?;
4141
st.end()
@@ -47,7 +47,7 @@ impl<'a> Default for CodeMetrics<'a> {
4747
Self {
4848
cyclomatic: cyclomatic::Stats::default(),
4949
halstead: halstead::Stats::default(),
50-
sloc: sloc::Stats::default(),
50+
loc: loc::Stats::default(),
5151
nargs: fn_args::Stats::default(),
5252
nexits: exit::Stats::default(),
5353
}
@@ -58,7 +58,7 @@ impl<'a> fmt::Display for CodeMetrics<'a> {
5858
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5959
writeln!(f, "{}", self.cyclomatic)?;
6060
writeln!(f, "{}", self.halstead)?;
61-
writeln!(f, "{}", self.sloc)?;
61+
writeln!(f, "{}", self.loc)?;
6262
writeln!(f, "{}", self.nargs)?;
6363
write!(f, "{}", self.nexits)
6464
}
@@ -68,7 +68,7 @@ impl<'a> CodeMetrics<'a> {
6868
pub fn merge(&mut self, other: &CodeMetrics<'a>) {
6969
self.cyclomatic.merge(&other.cyclomatic);
7070
self.halstead.merge(&other.halstead);
71-
self.sloc.merge(&other.sloc);
71+
self.loc.merge(&other.loc);
7272
self.nargs.merge(&other.nargs);
7373
self.nexits.merge(&other.nexits);
7474
}
@@ -183,7 +183,7 @@ impl<'a> FuncSpace<'a> {
183183
Self::dump_nargs(&metrics.nargs, &prefix, false, stdout)?;
184184
Self::dump_nexits(&metrics.nexits, &prefix, false, stdout)?;
185185
Self::dump_halstead(&metrics.halstead, &prefix, false, stdout)?;
186-
Self::dump_sloc(&metrics.sloc, &prefix, true, stdout)
186+
Self::dump_loc(&metrics.loc, &prefix, true, stdout)
187187
}
188188

189189
fn dump_cyclomatic(
@@ -245,8 +245,8 @@ impl<'a> FuncSpace<'a> {
245245
Self::dump_value("bugs", stats.bugs(), &prefix, true, stdout)
246246
}
247247

248-
fn dump_sloc(
249-
stats: &sloc::Stats,
248+
fn dump_loc(
249+
stats: &loc::Stats,
250250
prefix: &str,
251251
last: bool,
252252
stdout: &mut StandardStreamLock,
@@ -386,7 +386,7 @@ pub fn metrics<'a, T: TSParserTrait>(parser: &'a T, path: &'a PathBuf) -> Option
386386
if let Some(last) = space_stack.last_mut() {
387387
T::Cyclomatic::compute(&node, &mut last.metrics.cyclomatic);
388388
T::Halstead::compute(&node, code, &mut last.metrics.halstead);
389-
T::SourceLoc::compute(&node, code, &mut last.metrics.sloc, func_space, unit);
389+
T::Loc::compute(&node, code, &mut last.metrics.loc, func_space, unit);
390390
T::NArgs::compute(&node, &mut last.metrics.nargs);
391391
T::Exit::compute(&node, &mut last.metrics.nexits);
392392
}

src/traits.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use crate::fn_args::NArgs;
99
use crate::getter::Getter;
1010
use crate::halstead::Halstead;
1111
use crate::languages::*;
12+
use crate::loc::Loc;
1213
use crate::preproc::PreprocResults;
13-
use crate::sloc::SourceLoc;
1414
use crate::ts_parser::Filter;
1515
use crate::web::alterator::Alterator;
1616

@@ -27,7 +27,7 @@ pub trait TSParserTrait {
2727
type Getter: Getter;
2828
type Cyclomatic: Cyclomatic;
2929
type Halstead: Halstead;
30-
type SourceLoc: SourceLoc;
30+
type Loc: Loc;
3131
type NArgs: NArgs;
3232
type Exit: Exit;
3333

src/ts_parser.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ use crate::fn_args::NArgs;
1111
use crate::getter::Getter;
1212
use crate::halstead::Halstead;
1313
use crate::languages::*;
14+
use crate::loc::Loc;
1415
use crate::preproc::{get_macros, PreprocResults};
15-
use crate::sloc::SourceLoc;
1616
use crate::traits::*;
1717
use crate::web::alterator::Alterator;
1818

1919
pub struct TSParser<
20-
T: TSLanguage + Checker + Getter + Alterator + Cyclomatic + Exit + Halstead + NArgs + SourceLoc,
20+
T: TSLanguage + Checker + Getter + Alterator + Cyclomatic + Exit + Halstead + NArgs + Loc,
2121
> {
2222
code: Vec<u8>,
2323
tree: Tree,
@@ -69,23 +69,14 @@ fn get_fake_code<T: TSLanguage>(
6969
}
7070
}
7171

72-
impl<
73-
T: TSLanguage
74-
+ Checker
75-
+ Getter
76-
+ Alterator
77-
+ Cyclomatic
78-
+ Exit
79-
+ Halstead
80-
+ SourceLoc
81-
+ NArgs,
82-
> TSParserTrait for TSParser<T>
72+
impl<T: TSLanguage + Checker + Getter + Alterator + Cyclomatic + Exit + Halstead + Loc + NArgs>
73+
TSParserTrait for TSParser<T>
8374
{
8475
type Checker = T;
8576
type Getter = T;
8677
type Cyclomatic = T;
8778
type Halstead = T;
88-
type SourceLoc = T;
79+
type Loc = T;
8980
type NArgs = T;
9081
type Exit = T;
9182

0 commit comments

Comments
 (0)