-
Notifications
You must be signed in to change notification settings - Fork 50
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
Possible incorrect formatting from remove tabs #60
Comments
Hi @SteveBarnes-BH! Interestng, thank you for reporting this. Would you like to submit a PR with a small unit test covering this case, |
Patch for possible test to show the issue: --- a/tests/remove_tabs_test.py
+++ b/tests/remove_tabs_test.py
@@ -6,8 +6,9 @@ from pre_commit_hooks.remove_tabs import main as remove_tabs
@pytest.mark.parametrize(
('input_s', 'expected'),
(
- ('foo \t\nbar', 'foo \nbar'),
+ ('foo \t\nbar', 'foo \nbar'),
('bar\n\tbaz\n', 'bar\n baz\n'),
+ ('foo \tfoo2\nbar', 'foo foo2\nbar'),
),
)
def test_remove_tabs(input_s, expected, tmpdir): |
Alright, thanks! I can apply those patchs myself, thank you very much for providing them 😊 Some contributors sometimes like to have their name in the repo commits history, |
Since this is a work account I an raise a bug report or suggestion but contributing code requires a pile of paperwork :-( in advance hence the patch in the issue report ;-) I hope that you understand. |
Sure, I can perfectly understand! No worries 😊 |
I checked more closely your suggested patch on If you consider the input string |
But visually |
Strictly each tab should align the text that follows it to the next whitespaces_count after its position so my solution above, while it will work for many cases is still not perfect. |
I think that a much better approach would be:
This should align tabs correctly so that:
|
I think I now better understand your point.
|
I opened PR #61: what do you think of it @SteveBarnes-BH? |
Now that I am on my own machine & time I can go into a little more detail. As an old timer who first learnt to use tabs on a mechanical typewriter, (at school I was made to do secretarial studies in an attempt to improve my spelling & learnt a lot just not spelling), my understanding of what is expected with tabs matches the explanation here.
This is what the built in string/bytes method In my personal opinion it is best if the hook leaves the file visually unchanged as, if the originator of the file used a mix of spaces and tabs to align the words in a specific way, then they would expect the output of the hook to look the same. |
Thank you for the detailed explanation & PR! 😊 I now understand why
Alright, I'm going to merge your PR #62 |
If lines contain spaces followed by tabs then replacing with a fixed number of spaces will miss-align which can be a problem for some file types, e.g. fi a file contains 2 lines such as:
"
Line 1
Line 2
"
Then visually, with tab spacing of 4, it will be:
But after tab replacement will become:
Suggest adding:
And changing the line:
With something like:
This should give the expected alignment even on multi column lines such as:
\tCol 1\t Col 2 \tCol 3 \n
The text was updated successfully, but these errors were encountered: