-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Generic/DisallowSpaceIndent: multi line comments and the case of the moving space #1599
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
Generic/DisallowSpaceIndent: multi line comments and the case of the moving space #1599
Conversation
bfcc2a0
to
29c9155
Compare
Rebased for merge conflicts. |
29c9155
to
4efa1a7
Compare
…ine `/* */` comments Code sample: ```php /* * Some text */ ``` The tokenizer tokenizes this code as: ``` T_WHITESPACE T_COMMENT T_COMMENT T_COMMENT ``` In other words, the whitespace at the start of subsequent comment lines is tokenized as part of the `T_COMMENT`. In effect, this meant that these lines would not throw the appropriate error, nor be fixed by this sniff. This commit fixes that. Includes unit tests.
Given this code: ```php wp_die( $api ); // Tab - Space - Tab - Tab ``` with tab width set to `4`, `wp_die()` would start in column 13. The sniff was currently fixing this to: ```php wp_die( $api ); // Tab - Tab - Tab - Space ``` which changed the start column to 14 and changed the "space hidden before a tab" to precision alignment. This commit fixes that and is a further iteration building onto the improvements in 1404. The above code will now be fixed as: ```php wp_die( $api ); // Tab - Tab - Tab ``` Notes: * As the tabs in whitespace at the start of `T_INLINE_HTML` and `T_COMMENT` tokens is not replaced by spaces in the `content` by the tokenizer, this has to be done within the sniff to determine what the correct length of the whitespace should be. * Basing the correction of the space-based length of the whitespace allows for fixing with higher precision. * Incidentally, this also fixes one of the metrics being recorded incorrectly. For in-depth details of the effect on the metrics of this fix, please see: https://gist.github.com/jrfnl/5e2d75894c8e60a8f314b9fcb0ad3f62 * The `tabWidth` is now set in the unit test file.
4efa1a7
to
eb3c55f
Compare
Rebased for merge conflicts & code style... |
I never even noticed that the unit test for this was wrong with that mixed space/tab indent. Thanks a lot for these changes. |
You're welcome. Thanks for merging this. |
@gsherwood Greg, if you have a chance, it'd be great if you could also have a look at #1607 which basically fixes the same thing for the comments for the |
Allow the sniff to fix space indents for multi-line
/* */
commentsGiven this code sample (all lines indented with spaces):
The tokenizer tokenizes this code as:
In other words, the whitespace at the start of subsequent comment lines is tokenized as part of the
T_COMMENT
.In effect, this meant that these lines would not throw the appropriate error, nor be fixed by this sniff.
This commit fixes that.
Includes unit tests.
Fix the case of the moving space
This is one of the issues I came across during reviews related to the WP core code style fix effort - WordPress/WordPress-Coding-Standards#977
Given this code:
with tab width set to
4
,wp_die()
would start in column 13.The sniff was currently fixing this to:
which changed the start column to 14 and changed the "space hidden before a tab" to precision alignment.
This commit fixes that and is a further iteration building onto the improvements in #1404 and reverts the change in the fixes for line 22 and 24.
The above code will now be fixed as:
Notes:
* As the tabs in whitespace at the start of
T_INLINE_HTML
andT_COMMENT
tokens is not replaced by spaces in thecontent
by the tokenizer, this has to be done within the sniff to determine what the correct length of the whitespace should be.* Basing the correction on the space-based length of the whitespace allows for fixing with higher precision.
* Incidentally, this also fixes one of the metrics being recorded incorrectly. For in-depth details of the effect on the metrics of this fix, please see: https://gist.github.com/jrfnl/5e2d75894c8e60a8f314b9fcb0ad3f62
* The
tabWidth
is now set in the unit test file.It goes without saying, that for the fixes and the metrics to be accurate, the sniff has to be run with a tab width set.