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 DisallowShortTernary sniff #1768

Merged
merged 1 commit into from Jul 21, 2019

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jul 20, 2019

This new sniff addresses the new "The short ternary operator must not be used." rule which was recently added to the handbook.

The sniff has been added to the WordPress-Core ruleset.

Refs:

Includes unit tests.
Includes documentation.

Loosely related to #764

This new sniff addresses the new "_The short ternary operator must not be used._" rule which was recently added to the handbook.

The sniff has been added to the `WordPress-Core` ruleset.

Refs:
* https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#ternary-operator
* https://make.wordpress.org/core/2019/07/12/php-coding-standards-changes/

Includes unit tests.
Includes documentation.
</code>
<code title="Invalid: short ternary.">
<![CDATA[
$height = $data['height'] <em>? :</em> 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The space between ? and : is intentional?

Copy link
Member Author

@jrfnl jrfnl Jul 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. WPCS has no specific rules about the formatting of short ternaries and considering they will be banned, specifying such rules has low priority.

In the absence of specific rules, WPCS will treat the ? and : the same way as other operators and demands whitespace on both sides.

In other words, the formatting complies with the CS rules for this piece of code as per current WPCS.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh this makes sense, thanks!

@dingo-d dingo-d merged commit 4011319 into develop Jul 21, 2019
@dingo-d dingo-d deleted the feature/new-disallow-short-ternary-sniff branch July 21, 2019 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants