mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-31 07:37:38 +00:00
Document LinterResult::has_syntax_error
and add Parsed::has_no_syntax_errors
(#16443)
Summary -- This is a follow up addressing the comments on #16425. As @dhruvmanila pointed out, the naming is a bit tricky. I went with `has_no_errors` to try to differentiate it from `is_valid`. It actually ends up negated in most uses, so it would be more convenient to have `has_any_errors` or `has_errors`, but I thought it would sound too much like the opposite of `is_valid` in that case. I'm definitely open to suggestions here. Test Plan -- Existing tests.
This commit is contained in:
parent
a3ae76edc0
commit
37fbe58b13
6 changed files with 50 additions and 26 deletions
|
@ -39,9 +39,7 @@ fn test_valid_syntax(input_path: &Path) {
|
|||
});
|
||||
let parsed = parse_unchecked(&source, options);
|
||||
|
||||
let is_valid = parsed.is_valid() && parsed.unsupported_syntax_errors().is_empty();
|
||||
|
||||
if !is_valid {
|
||||
if parsed.has_syntax_errors() {
|
||||
let line_index = LineIndex::from_source_text(&source);
|
||||
let source_code = SourceCode::new(&source, &line_index);
|
||||
|
||||
|
@ -101,10 +99,8 @@ fn test_invalid_syntax(input_path: &Path) {
|
|||
});
|
||||
let parsed = parse_unchecked(&source, options);
|
||||
|
||||
let is_valid = parsed.is_valid() && parsed.unsupported_syntax_errors().is_empty();
|
||||
|
||||
assert!(
|
||||
!is_valid,
|
||||
parsed.has_syntax_errors(),
|
||||
"{input_path:?}: Expected parser to generate at least one syntax error for a program containing syntax errors."
|
||||
);
|
||||
|
||||
|
@ -224,7 +220,7 @@ f'{foo!r'
|
|||
println!("AST:\n----\n{:#?}", parsed.syntax());
|
||||
println!("Tokens:\n-------\n{:#?}", parsed.tokens());
|
||||
|
||||
if !parsed.is_valid() {
|
||||
if parsed.has_invalid_syntax() {
|
||||
println!("Errors:\n-------");
|
||||
|
||||
let line_index = LineIndex::from_source_text(source);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue