Skip to content

Commit c467aea

Browse files
ndmitchellfacebook-github-bot
authored andcommitted
Make lint store its severity
Summary: Rather than having is_serious with unclear semantics, just store a severity level directly. Reviewed By: stepancheg Differential Revision: D47150377 fbshipit-source-id: 156fddb540d56b129a74db51190aa539fed572c4
1 parent d21c3ad commit c467aea

File tree

7 files changed

+24
-23
lines changed

7 files changed

+24
-23
lines changed

starlark/src/analysis/dubious.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use thiserror::Error;
2121

2222
use crate::analysis::types::LintT;
2323
use crate::analysis::types::LintWarning;
24+
use crate::analysis::EvalSeverity;
2425
use crate::codemap::CodeMap;
2526
use crate::codemap::FileSpan;
2627
use crate::codemap::Span;
@@ -43,8 +44,8 @@ pub(crate) enum Dubious {
4344
}
4445

4546
impl LintWarning for Dubious {
46-
fn is_serious(&self) -> bool {
47-
true
47+
fn severity(&self) -> EvalSeverity {
48+
EvalSeverity::Warning
4849
}
4950

5051
fn short_name(&self) -> &'static str {

starlark/src/analysis/flow.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use thiserror::Error;
1919

2020
use crate::analysis::types::LintT;
2121
use crate::analysis::types::LintWarning;
22+
use crate::analysis::EvalSeverity;
2223
use crate::codemap::CodeMap;
2324
use crate::codemap::ResolvedFileSpan;
2425
use crate::codemap::Span;
@@ -51,11 +52,11 @@ pub(crate) enum FlowIssue {
5152
}
5253

5354
impl LintWarning for FlowIssue {
54-
fn is_serious(&self) -> bool {
55+
fn severity(&self) -> EvalSeverity {
5556
match self {
5657
// Sometimes people add these to make flow clearer
57-
FlowIssue::RedundantContinue | FlowIssue::RedundantReturn => false,
58-
_ => true,
58+
FlowIssue::RedundantContinue | FlowIssue::RedundantReturn => EvalSeverity::Disabled,
59+
_ => EvalSeverity::Warning,
5960
}
6061
}
6162

starlark/src/analysis/incompatible.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use thiserror::Error;
2424

2525
use crate::analysis::types::LintT;
2626
use crate::analysis::types::LintWarning;
27+
use crate::analysis::EvalSeverity;
2728
use crate::codemap::CodeMap;
2829
use crate::codemap::FileSpan;
2930
use crate::codemap::Span;
@@ -46,8 +47,8 @@ pub(crate) enum Incompatibility {
4647
}
4748

4849
impl LintWarning for Incompatibility {
49-
fn is_serious(&self) -> bool {
50-
true
50+
fn severity(&self) -> EvalSeverity {
51+
EvalSeverity::Warning
5152
}
5253

5354
fn short_name(&self) -> &'static str {

starlark/src/analysis/names.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use thiserror::Error;
3434

3535
use crate::analysis::types::LintT;
3636
use crate::analysis::types::LintWarning;
37+
use crate::analysis::EvalSeverity;
3738
use crate::codemap::CodeMap;
3839
use crate::codemap::Span;
3940
use crate::codemap::Spanned;
@@ -66,10 +67,10 @@ pub(crate) enum NameWarning {
6667
}
6768

6869
impl LintWarning for NameWarning {
69-
fn is_serious(&self) -> bool {
70+
fn severity(&self) -> EvalSeverity {
7071
match self {
71-
Self::UsingUnassigned(..) => true,
72-
_ => false,
72+
Self::UsingUnassigned(..) => EvalSeverity::Warning,
73+
_ => EvalSeverity::Disabled,
7374
}
7475
}
7576

starlark/src/analysis/performance.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use thiserror::Error;
1919

2020
use crate::analysis::types::LintT;
2121
use crate::analysis::types::LintWarning;
22+
use crate::analysis::EvalSeverity;
2223
use crate::codemap::CodeMap;
2324
use crate::syntax::ast::Argument;
2425
use crate::syntax::ast::AstExpr;
@@ -40,8 +41,8 @@ pub(crate) enum Performance {
4041
}
4142

4243
impl LintWarning for Performance {
43-
fn is_serious(&self) -> bool {
44-
true
44+
fn severity(&self) -> EvalSeverity {
45+
EvalSeverity::Warning
4546
}
4647

4748
fn short_name(&self) -> &'static str {

starlark/src/analysis/types.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::codemap::Span;
3232
use crate::errors::Diagnostic;
3333

3434
pub(crate) trait LintWarning: Display {
35-
fn is_serious(&self) -> bool;
35+
fn severity(&self) -> EvalSeverity;
3636
fn short_name(&self) -> &'static str;
3737
}
3838

@@ -54,7 +54,7 @@ pub struct Lint {
5454
pub short_name: String,
5555
/// Is this code highly-likely to be wrong, rather
5656
/// than merely stylistically non-ideal.
57-
pub serious: bool,
57+
pub severity: EvalSeverity,
5858
/// A description of the underlying problem.
5959
pub problem: String,
6060
/// The source code at [`location`](Lint::location).
@@ -87,7 +87,7 @@ impl<T: LintWarning> LintT<T> {
8787
Lint {
8888
location: self.location,
8989
short_name: self.problem.short_name().to_owned(),
90-
serious: self.problem.is_serious(),
90+
severity: self.problem.severity(),
9191
problem: self.problem.to_string(),
9292
original: self.original,
9393
}
@@ -200,12 +200,7 @@ impl From<Lint> for EvalMessage {
200200
Self {
201201
path: x.location.filename().to_owned(),
202202
span: Some(x.location.resolve_span()),
203-
severity: if x.serious {
204-
EvalSeverity::Warning
205-
} else {
206-
// Start with all non-serious errors disabled, and ramp up from there
207-
EvalSeverity::Disabled
208-
},
203+
severity: x.severity,
209204
name: x.short_name,
210205
description: x.problem,
211206
full_error_with_span: None,

starlark/src/analysis/underscore.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use thiserror::Error;
2121

2222
use crate::analysis::types::LintT;
2323
use crate::analysis::types::LintWarning;
24+
use crate::analysis::EvalSeverity;
2425
use crate::codemap::CodeMap;
2526
use crate::syntax::ast::Assign;
2627
use crate::syntax::ast::AstExpr;
@@ -39,8 +40,8 @@ pub(crate) enum UnderscoreWarning {
3940
}
4041

4142
impl LintWarning for UnderscoreWarning {
42-
fn is_serious(&self) -> bool {
43-
false
43+
fn severity(&self) -> EvalSeverity {
44+
EvalSeverity::Disabled
4445
}
4546

4647
fn short_name(&self) -> &'static str {

0 commit comments

Comments
 (0)