-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix for D413
introduces whitespace
#10050
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I took a quick look at this and the culprit seems to be here: ruff/crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs Lines 1667 to 1683 in 175c266
Instead of the fix "introducing" whitespace it is more so leaving behind the original indentation space which obviously violates (W293). In this scenario I would imagine the original indentation will need to be deleted before inserting the new line and new indentation. Below is an initial attempt at addressing this problem. Let me know if this is a good solution and I would be glad to submit a pull request. let fix = match num_blank_lines {
0 => Fix::safe_edit(Edit::insertion(
format!("{}{}", line_end.repeat(2), docstring.indentation),
context.end(),
)),
1 => {
let del_start = context.end() - TextSize::from(docstring.indentation.len() as u32);
let rest = [Edit::insertion(
format!("{}{}", line_end, docstring.indentation),
context.end(),
)];
Fix::safe_edits(Edit::deletion(del_start, context.end()), rest)
}
_ => unreachable!(),
};
diagnostic.set_fix(fix); |
@jusexton this looks about right, although it would be nice if we don't have to branch on the existing empty lines. I also think that this won't work if the line has more whitespace than just the indent? def test_func():
"""Some test function.
Returns
-------
None
"""
pass Could we maybe use the range information in |
@MichaReiser Thanks for the help. A PR has been created making use of |
Minimal
test.py
:Fixing with
ruff --isolated --select="D413" --fix test.py
adds unnecessary whitespace (W293
)The text was updated successfully, but these errors were encountered: