Skip to content

Commit

Permalink
Move ripgrep to new note level (#1354)
Browse files Browse the repository at this point in the history
  • Loading branch information
brynary authored Dec 20, 2024
1 parent 732db31 commit 3c13f59
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 41 deletions.
5 changes: 5 additions & 0 deletions .qlty/qlty.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ name = "yamllint"
plugins = ["osv-scanner", "trufflehog"]
file_patterns = ["qlty-cli/tests/**"]

# Disable ripgrep from analyzing the ripgrep parser
[[ignore]]
plugins = ["ripgrep"]
file_patterns = ["**/ripgrep.rs"]

[[ignore]]
rules = ["markdownlint/MD024"]
file_patterns = ["CHANGELOG.md"]
24 changes: 12 additions & 12 deletions qlty-check/src/parser/ripgrep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl Parser for Ripgrep {
tool: "ripgrep".into(),
message: text.trim().to_string(),
category: Category::Lint.into(),
level: Level::Medium.into(),
level: Level::Note.into(),
rule_key: submatch.rg_match.text.clone(),
location: Some(Location {
path: path.text.clone(),
Expand Down Expand Up @@ -136,11 +136,11 @@ mod test {
"###;

let issues = Ripgrep::default().parse("ripgrep", input);
insta::assert_yaml_snapshot!(issues.unwrap(), @r"
insta::assert_yaml_snapshot!(issues.unwrap(), @r###"
- tool: ripgrep
ruleKey: FIXME
message: // FIXME TODO
level: LEVEL_MEDIUM
level: LEVEL_NOTE
category: CATEGORY_LINT
location:
path: basic_e.in.rs
Expand All @@ -152,7 +152,7 @@ mod test {
- tool: ripgrep
ruleKey: TODO
message: // FIXME TODO
level: LEVEL_MEDIUM
level: LEVEL_NOTE
category: CATEGORY_LINT
location:
path: basic_e.in.rs
Expand All @@ -164,7 +164,7 @@ mod test {
- tool: ripgrep
ruleKey: NOTE
message: // NOTE
level: LEVEL_MEDIUM
level: LEVEL_NOTE
category: CATEGORY_LINT
location:
path: basic.in.rs
Expand All @@ -176,7 +176,7 @@ mod test {
- tool: ripgrep
ruleKey: FIXME
message: // FIXME TODO
level: LEVEL_MEDIUM
level: LEVEL_NOTE
category: CATEGORY_LINT
location:
path: basic.in.rs
Expand All @@ -188,7 +188,7 @@ mod test {
- tool: ripgrep
ruleKey: TODO
message: // FIXME TODO
level: LEVEL_MEDIUM
level: LEVEL_NOTE
category: CATEGORY_LINT
location:
path: basic.in.rs
Expand All @@ -200,7 +200,7 @@ mod test {
- tool: ripgrep
ruleKey: HACK
message: // HACK
level: LEVEL_MEDIUM
level: LEVEL_NOTE
category: CATEGORY_LINT
location:
path: basic.in.rs
Expand All @@ -209,7 +209,7 @@ mod test {
startColumn: 7
endLine: 4
endColumn: 11
");
"###);
}

#[test]
Expand All @@ -230,17 +230,17 @@ mod test {
assert!(logs_contain("Failed to parse line number"));
assert!(logs_contain("Failed to parse path"));

insta::assert_yaml_snapshot!(issues.unwrap(), @r"
insta::assert_yaml_snapshot!(issues.unwrap(), @r###"
- tool: ripgrep
ruleKey: NOTE
message: // NOTE
level: LEVEL_MEDIUM
level: LEVEL_NOTE
category: CATEGORY_LINT
location:
path: basic.in.rs
range:
startLine: 2
endLine: 2
");
"###);
}
}
9 changes: 2 additions & 7 deletions qlty-check/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ use crate::{
};
use anyhow::Result;
use qlty_analysis::IssueCount;
use qlty_types::{
analysis::v1::{Category, ExecutionVerb, Issue},
level_from_str,
};
use qlty_types::analysis::v1::{Category, ExecutionVerb, Issue};
use tracing::info;

pub struct Processor {
Expand Down Expand Up @@ -69,9 +66,7 @@ impl Processor {

for issue in &self.issues {
if let Some(fail_level) = self.plan.fail_level {
if issue.level
>= level_from_str(fail_level.as_str_name().to_lowercase().as_str()) as i32
{
if issue.level >= fail_level as i32 {
self.counts.failure_issues += 1;
}
}
Expand Down
9 changes: 4 additions & 5 deletions qlty-cli/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use qlty_cloud::format::JsonFormatter;
use qlty_config::Workspace;
use qlty_types::analysis::v1::ExecutionVerb;
use qlty_types::analysis::v1::Level;
use qlty_types::level_from_str;
use std::io::BufRead as _;
use std::io::{self, Read};
use std::path::PathBuf;
Expand Down Expand Up @@ -68,9 +67,9 @@ pub struct Check {
#[arg(long, conflicts_with = "all")]
pub sample: Option<usize>,

/// Minimum level of issues to show (high, medium, low)
#[arg(long)]
pub level: Option<String>,
/// Minimum level of issues to show
#[arg(long, value_enum, default_value = "note")]
pub level: Level,

/// Maximum number of concurrent jobs
#[arg(short, long)]
Expand Down Expand Up @@ -279,7 +278,7 @@ impl Check {
settings.formatters = !self.no_formatters;
settings.filters = CheckFilter::from_optional_list(self.filter.clone());
settings.upstream = self.compute_upstream()?;
settings.level = level_from_str(&self.level.clone().unwrap_or("".to_string()));
settings.level = self.level;
settings.fail_level = if self.no_fail {
None
} else {
Expand Down
3 changes: 2 additions & 1 deletion qlty-cli/src/ui/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ pub fn formatted_level(level: Level) -> String {
Level::High => style("high ").red().to_string(),
Level::Medium => style("medium").magenta().to_string(),
Level::Low => style("low ").yellow().to_string(),
Level::Fmt => style("fmt ").dim().to_string(),
Level::Fmt => style("fmt ").yellow().dim().to_string(),
Level::Note => style("note ").dim().to_string(),
_ => format!("{:?}", level),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`linter=ripgrep fixture=basic version=14.1.0 1`] = `
"issues": [
{
"category": "CATEGORY_LINT",
"level": "LEVEL_MEDIUM",
"level": "LEVEL_NOTE",
"location": {
"path": "basic.in.rs",
"range": {
Expand All @@ -32,7 +32,7 @@ exports[`linter=ripgrep fixture=basic version=14.1.0 1`] = `
},
{
"category": "CATEGORY_LINT",
"level": "LEVEL_MEDIUM",
"level": "LEVEL_NOTE",
"location": {
"path": "basic.in.rs",
"range": {
Expand All @@ -59,7 +59,7 @@ exports[`linter=ripgrep fixture=basic version=14.1.0 1`] = `
},
{
"category": "CATEGORY_LINT",
"level": "LEVEL_MEDIUM",
"level": "LEVEL_NOTE",
"location": {
"path": "basic.in.rs",
"range": {
Expand All @@ -86,7 +86,7 @@ exports[`linter=ripgrep fixture=basic version=14.1.0 1`] = `
},
{
"category": "CATEGORY_LINT",
"level": "LEVEL_MEDIUM",
"level": "LEVEL_NOTE",
"location": {
"path": "basic.in.rs",
"range": {
Expand All @@ -113,7 +113,7 @@ exports[`linter=ripgrep fixture=basic version=14.1.0 1`] = `
},
{
"category": "CATEGORY_LINT",
"level": "LEVEL_MEDIUM",
"level": "LEVEL_NOTE",
"location": {
"path": "basic.in.rs",
"range": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`linter=ripgrep fixture=basic version=14.1.1 1`] = `
"issues": [
{
"category": "CATEGORY_LINT",
"level": "LEVEL_MEDIUM",
"level": "LEVEL_NOTE",
"location": {
"path": "basic.in.rs",
"range": {
Expand All @@ -32,7 +32,7 @@ exports[`linter=ripgrep fixture=basic version=14.1.1 1`] = `
},
{
"category": "CATEGORY_LINT",
"level": "LEVEL_MEDIUM",
"level": "LEVEL_NOTE",
"location": {
"path": "basic.in.rs",
"range": {
Expand All @@ -59,7 +59,7 @@ exports[`linter=ripgrep fixture=basic version=14.1.1 1`] = `
},
{
"category": "CATEGORY_LINT",
"level": "LEVEL_MEDIUM",
"level": "LEVEL_NOTE",
"location": {
"path": "basic.in.rs",
"range": {
Expand All @@ -86,7 +86,7 @@ exports[`linter=ripgrep fixture=basic version=14.1.1 1`] = `
},
{
"category": "CATEGORY_LINT",
"level": "LEVEL_MEDIUM",
"level": "LEVEL_NOTE",
"location": {
"path": "basic.in.rs",
"range": {
Expand All @@ -113,7 +113,7 @@ exports[`linter=ripgrep fixture=basic version=14.1.1 1`] = `
},
{
"category": "CATEGORY_LINT",
"level": "LEVEL_MEDIUM",
"level": "LEVEL_NOTE",
"location": {
"path": "basic.in.rs",
"range": {
Expand Down
2 changes: 1 addition & 1 deletion qlty-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ impl analysis::v1::Level {
impl clap::ValueEnum for analysis::v1::Level {
fn value_variants<'a>() -> &'a [Self] {
&[
analysis::v1::Level::Unspecified,
analysis::v1::Level::Note,
analysis::v1::Level::Fmt,
analysis::v1::Level::Low,
analysis::v1::Level::Medium,
Expand Down
10 changes: 5 additions & 5 deletions qlty-types/src/protos/qlty.analysis.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,11 @@ impl MessageLevel {
#[repr(i32)]
pub enum Level {
Unspecified = 0,
Note = 5,
Fmt = 1,
Low = 2,
Medium = 3,
High = 4,
Note = 10,
Fmt = 20,
Low = 30,
Medium = 40,
High = 50,
}
impl Level {
/// String value of the enum field names used in the ProtoBuf definition.
Expand Down

0 comments on commit 3c13f59

Please sign in to comment.