mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-09 21:28:21 +00:00
Add noqa_row
to diagnostics JSON format (#3228)
In ruff-lsp (https://github.com/charliermarsh/ruff-lsp/pull/76) we want to add a "Disable \<rule\> for this line" quickfix. However, finding the correct line into which the `noqa` comment should be inserted is non-trivial (multi-line strings for example). Ruff already has this info, so expose it in the JSON output for use by ruff-lsp.
This commit is contained in:
parent
cd9fbeb560
commit
33c31cda27
5 changed files with 19 additions and 3 deletions
|
@ -331,7 +331,9 @@ pub fn lint_only(
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
Message::from_diagnostic(diagnostic, path_lossy.to_string(), source)
|
let lineno = diagnostic.location.row();
|
||||||
|
let noqa_row = *directives.noqa_line_for.get(&lineno).unwrap_or(&lineno);
|
||||||
|
Message::from_diagnostic(diagnostic, path_lossy.to_string(), source, noqa_row)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
})
|
})
|
||||||
|
@ -469,7 +471,14 @@ This indicates a bug in `{}`. If you could open an issue at:
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
Message::from_diagnostic(diagnostic, path_lossy.to_string(), source)
|
let lineno = diagnostic.location.row();
|
||||||
|
let noqa_row = *directives.noqa_line_for.get(&lineno).unwrap_or(&lineno);
|
||||||
|
Message::from_diagnostic(
|
||||||
|
diagnostic,
|
||||||
|
path_lossy.to_string(),
|
||||||
|
source,
|
||||||
|
noqa_row,
|
||||||
|
)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -16,6 +16,7 @@ pub struct Message {
|
||||||
pub fix: Option<Fix>,
|
pub fix: Option<Fix>,
|
||||||
pub filename: String,
|
pub filename: String,
|
||||||
pub source: Option<Source>,
|
pub source: Option<Source>,
|
||||||
|
pub noqa_row: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Message {
|
impl Message {
|
||||||
|
@ -23,6 +24,7 @@ impl Message {
|
||||||
diagnostic: Diagnostic,
|
diagnostic: Diagnostic,
|
||||||
filename: String,
|
filename: String,
|
||||||
source: Option<Source>,
|
source: Option<Source>,
|
||||||
|
noqa_row: usize,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
kind: diagnostic.kind,
|
kind: diagnostic.kind,
|
||||||
|
@ -34,6 +36,7 @@ impl Message {
|
||||||
fix: diagnostic.fix,
|
fix: diagnostic.fix,
|
||||||
filename,
|
filename,
|
||||||
source,
|
source,
|
||||||
|
noqa_row,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,6 +114,7 @@ pub fn run(
|
||||||
),
|
),
|
||||||
format!("{}", path.display()),
|
format!("{}", path.display()),
|
||||||
None,
|
None,
|
||||||
|
1,
|
||||||
)])
|
)])
|
||||||
} else {
|
} else {
|
||||||
Diagnostics::default()
|
Diagnostics::default()
|
||||||
|
|
|
@ -50,6 +50,7 @@ struct ExpandedMessage<'a> {
|
||||||
location: Location,
|
location: Location,
|
||||||
end_location: Location,
|
end_location: Location,
|
||||||
filename: &'a str,
|
filename: &'a str,
|
||||||
|
noqa_row: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
|
@ -197,6 +198,7 @@ impl Printer {
|
||||||
location: message.location,
|
location: message.location,
|
||||||
end_location: message.end_location,
|
end_location: message.end_location,
|
||||||
filename: &message.filename,
|
filename: &message.filename,
|
||||||
|
noqa_row: message.noqa_row,
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
)?
|
)?
|
||||||
|
|
|
@ -112,7 +112,8 @@ fn test_stdin_json() -> Result<()> {
|
||||||
"row": 1,
|
"row": 1,
|
||||||
"column": 10
|
"column": 10
|
||||||
}},
|
}},
|
||||||
"filename": "{file_path}"
|
"filename": "{file_path}",
|
||||||
|
"noqa_row": 1
|
||||||
}}
|
}}
|
||||||
]
|
]
|
||||||
"#
|
"#
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue