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

[New sniff?] Check for non-printable characters #94

Closed
4 tasks
jrfnl opened this issue Dec 18, 2016 · 3 comments
Closed
4 tasks

[New sniff?] Check for non-printable characters #94

jrfnl opened this issue Dec 18, 2016 · 3 comments

Comments

@jrfnl
Copy link

jrfnl commented Dec 18, 2016

Rule type:

Warning

Rule:

Check for non-printable characters [\x00-\x08\x0B-\x0C\x0E-\x1F\x80-\xFF]

Ref: https://make.wordpress.org/themes/handbook/review/required/theme-check-plugin/#info

Theme check file covering this rule:

https://github.com/WordPress/theme-check/blob/master/checks/nonprintable.php

Notes for implementation:
  • Quite possibly there will be an existing sniff somewhere we could re-use for this.

To do:

  • Maybe clarify the rule in the Theme Review handbook
  • Research if there is an existing sniff we could reuse, if so, add that sniff to the ruleset
  • Otherwise: Create unit tests
  • Otherwise: Create new sniff
@grappler
Copy link
Member

For this sniff we can most likely use the token T_BAD_CHARACTER

@selul
Copy link

selul commented Dec 22, 2016

i would like to try this.

selul added a commit to selul/WordPress-Coding-Standards that referenced this issue Jan 6, 2017
@jrfnl
Copy link
Author

jrfnl commented May 31, 2018

From: #103 (comment)

I spoke to Otto and the reason this was added in the Theme Check was to check for Byte Order Mark. Explanation. This is now being checked with Generic.Files.ByteOrderMark

The check was made a bit looser to try to catch other issues too.

I did a bit of research, non printable characters are things like line breaks. In order for this sniff to work we would need to think of places where it does not make sense to have non printable characters. I am not sure how many places there are.

More of the ASCII codes can be found in the links 1-31 and 127-159 are the invisible characters.
http://ascii.cl/htmlcodes.htm
http://www.ascii-code.com/

It basically needs to become clear whether just checking for the BOM is enough, or checking for more non-printables is needed.

If the latter, PR #103 contains the basic principle of a sniff for that, but should in that case probably be pulled upstream, either in WPCS or - even better - in PHPCS itself.

@jrfnl jrfnl closed this as completed May 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants