Skip to content
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

Question: how to check for non-mixed tab or space indentation with wtf ? #20

Open
UffeJakobsen opened this issue Jul 28, 2020 · 7 comments

Comments

@UffeJakobsen
Copy link

Is there a way to make wtf check for specific non-mixed tab or space indentation ?

@dlenski
Copy link
Owner

dlenski commented Jul 28, 2020

check for specific non-mixed tab or space indentation

Not sure that I understand. Can you give an example of text files which are/aren't matching this kind of condition?

@UffeJakobsen
Copy link
Author

UffeJakobsen commented Jul 28, 2020

check for specific non-mixed tab or space indentation

Not sure that I understand. Can you give an example of text files which are/aren't matching this kind of condition?

I'm using wtf to do checks on a C/C++ -source tree.
The formatting rules for the source tree specify that all indentation in the C/C++ files should be done with spaces - no tabs are allowed for indentation.
I may have missed something - but I have failed to find a way to use wtf to check that only spaces are used in indentation.

@dlenski
Copy link
Owner

dlenski commented Jul 28, 2020

I may have missed something - but I have failed to find a way to use wtf to check that only spaces are used in indentation.

Do these options not cover what you're trying to do?

Tabs and Spaces:
  -s, --tab-space-mix   Make sure no mixed spaces and/or tabs exist in leading
                        whitespace; fix requires -x or -y SPACES (default
                        report)
  -S, --report-tab-space-mix
  -Is, --ignore-tab-space-mix
  -x NS, --change-tabs NS
                        Change each tab characters in leading whitespace to NS
                        spaces.
  -y NS, --change-spaces NS
                        Change NS consecutive spaces in leading whitespace to
                        tab character.

Warn-only:

$ printf "\t    blah\n" | wtf -0 -S
<stdin> LINE 1: WARNING: mixed use of spaces and tabs at beginning of line
<stdin>:
	CHOPPED 0 lines with trailing space
	CHOPPED 0 blank lines at EOF
	no change to newline at EOF
	CHANGED 0 line endings which didn't match lf from first line
	WARNED ABOUT 1 lines with mixed tabs/spaces

Replace tabs with 4 spaces:

$ printf "\t    blah\n" | wtf -sx4 -0
<stdin> LINE 1: WARNING: mixed use of spaces and tabs at beginning of line
<stdin>:
	CHOPPED 0 lines with trailing space
	CHOPPED 0 blank lines at EOF
	no change to newline at EOF
	CHANGED 0 line endings which didn't match lf from first line
	WARNED ABOUT 1 lines with mixed tabs/spaces
	CHANGED tabs to 4 spaces on 1 lines

@UffeJakobsen
Copy link
Author

Ah - I failed to understand that the -x option could be used for the scenario that I described above.

From the help/description I got the impression that it was only meant for changing files - and as I only wanted to check/detect if a condition was present without changing the files - I wrote off that option from the beginning.

Thanks for your swift response and help 👍 - I'm closing this issue right away :-)

@UffeJakobsen
Copy link
Author

UffeJakobsen commented Jul 30, 2020

Sorry for reopening this issue
I've now been playing around with the -x and -y options...

As mentioned earlier - I'm now able to get WTF to do what I needed.

But I think that there is some inconsistency in the reporting of what WTF have done or seen

Background:
I'm using WTF in a continuous pipeline - WTF will not change anything - only validate for acceptance or rejection - hence -0 (dry-run option is used)
In case of rejection - reporting the reasons for the details is important (not too verbose - but enough to point the user to the exact problem)

As mentioned earlier - I'm validating a C/C++ source tree where only space is allowed in the indentation - not tabs

In the case of mixed indentation WTF (with option -S) already reports a warning of every line (number) that is found - that is perfect for my use case :-)

Running WTF with options "-0 -S -x 1" enables me to also detect lines that have only (non-mixed) tab indentation.
But they are not reported in the same detail level (with line number) as mixed indentation lines - only mention is in the summary where they are reported as a total changed count.

Now I know that raising the verbose level to >= 2 (-vv) will somewhat fix this.
But that gets too verbose for my use case (the users) as the whole line contents is quoted in the output

I do realize that this is a special corner case - but I find WTF super flexible in every other way - except for this little "issue" that I've found
I'm not sure if I've managed to explain the problem to a level that makes it understandable to others than myself (english is not my native language)

PS: I've made a fix/patch for this "issue" - are you interested in pull requests ? :-)

@UffeJakobsen UffeJakobsen reopened this Jul 30, 2020
@dlenski
Copy link
Owner

dlenski commented Jul 30, 2020

PS: I've made a fix/patch for this "issue" - are you interested in pull requests ? :-)

Yep!

@UffeJakobsen
Copy link
Author

PR #21 created :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants