Skip to content

Commit 12d3c11

Browse files
authored
Merge pull request #127 from kevv87/fix-off-by-one-line-reporting
Increment for One Indexed reporting of warnings in DFA CLI output
2 parents ec3c8fd + 3db2c40 commit 12d3c11

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
- Fixed issue where statements under top-level in-eachs were not correctly tracked.
1717
- Moved storage of reference->symbol mapping to on-demand timing, should significantly speed
1818
up device analysises
19+
- CLI tool DFA now uses default one-indexed line count for reporting warnings on analyzed files.
20+
`--zero-indexed` flag can be set to `true` when executing DFA for using zero-indexed counting if required.
1921

2022
## 0.9.12
2123
- Added 'simics\_util\_vect' as a known provisional (with no DLS semantics)

src/dfa/client.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -385,13 +385,15 @@ impl ClientInterface {
385385
}{}
386386
}
387387

388-
pub fn output_errors(&self) {
388+
pub fn output_errors(&self, zero_indexed: bool) {
389389
for (path, diagnostics) in &self.diagnostics {
390390
for diag in diagnostics {
391-
println!("{} line {}: {}",
392-
path.to_str().unwrap(),
393-
diag.line,
394-
diag.desc);
391+
println!(
392+
"{} line {}: {}",
393+
path.to_str().unwrap(),
394+
diag.line + if zero_indexed { 0 } else { 1 },
395+
diag.desc
396+
);
395397
}
396398
}
397399
}

src/dfa/main.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct Args {
3434
workspaces: Vec<PathBuf>,
3535
compile_info: Option<PathBuf>,
3636
suppress_imports: Option<bool>,
37+
zero_indexed: Option<bool>,
3738
linting_enabled: Option<bool>,
3839
lint_cfg_path: Option<PathBuf>,
3940
test: bool,
@@ -78,6 +79,11 @@ fn parse_args() -> Args {
7879
.action(ArgAction::Set)
7980
.value_parser(clap::value_parser!(bool))
8081
.required(false))
82+
.arg(Arg::new("zero-indexed").short('z').long("zero-indexed")
83+
.help("Diagnostics reported by the server will be zero-indexed (defaults to false)")
84+
.action(ArgAction::Set)
85+
.value_parser(clap::value_parser!(bool))
86+
.required(false))
8187
.arg(Arg::new("linting-enabled").short('l').long("linting-enabled")
8288
.help("Turns linting on/off (defaults to true)")
8389
.action(ArgAction::Set)
@@ -106,6 +112,8 @@ fn parse_args() -> Args {
106112
.cloned(),
107113
suppress_imports: args.get_one::<bool>("suppress-imports")
108114
.cloned(),
115+
zero_indexed: args.get_one::<bool>("zero-indexed")
116+
.cloned(),
109117
linting_enabled: args.get_one::<bool>("linting-enabled")
110118
.cloned(),
111119
lint_cfg_path: args.get_one::<PathBuf>("lint-cfg-path")
@@ -126,6 +134,7 @@ fn main_inner() -> Result<(), i32> {
126134
let first_workspace = workspace_rest.next();
127135

128136
let linting_enabled = arg.linting_enabled.unwrap_or(true);
137+
let zero_indexed = arg.zero_indexed.unwrap_or(false);
129138

130139
let root = match first_workspace {
131140
Some(w) => w,
@@ -167,7 +176,7 @@ fn main_inner() -> Result<(), i32> {
167176
})?;
168177

169178
if !arg.quiet {
170-
dlsclient.output_errors();
179+
dlsclient.output_errors(zero_indexed);
171180
}
172181
if arg.test && !dlsclient.no_errors() {
173182
exit_code = Err(1);

0 commit comments

Comments
 (0)