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

PHPCS ruleset: add sniff to check spacing between property declarations #135

Merged
merged 1 commit into from
May 28, 2019

Conversation

jrfnl
Copy link
Collaborator

@jrfnl jrfnl commented May 22, 2019

The Yoast.WhiteSpace.FunctionSpacing sniff which was added in PR #86 checks that each function within an OO structure has one blank line before the function declaration and no blank line(s) after the last function in a class.

This sniff was added as there was quite some inconsistency regarding this across classes and repos and this way we could enforce consistency.

Similar to this, we should also enforce consistency regarding the spacing out of property declarations in OO structures, which I've noticed becoming inconsistent in some repos as well.

The sniff I'm proposing to add, is a PHPCS native sniff which checks that there is one blank line before the first property declaration in an OO structure, as well as one blank line between property declarations in OO structures.

The sniff includes an auto-fixer.

Ref: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Customisable-Sniff-Properties#squizwhitespacemembervarspacing

Code sample:

Incorrect:

class ABC {
	public $a;
	/**
	 * Docblock.
	 */
	protected $b;


	/**
	 * Docblock.
	 */
	private $c;
}

Correct:

class ABC {

	public $a;

	/**
	 * Docblock.
	 */
	protected $b;

	/**
	 * Docblock.
	 */
	private $c;
}

The `Yoast.WhiteSpace.FunctionSpacing` sniff which was added in 86 checks that each function within an OO structure has one blank line before the function declaration and no blank line(s) after the last function in a class.

This sniff was added as there was quite some inconsistency regarding this across classes and repos and this way we could enforce consistency.

Similar to this, we should also enforce consistency regarding the spacing out of property declarations in OO structures., which I've noticed becoming inconsistent in some repos as well.

The sniff I'm proposing to add is a PHPCS native sniff which checks that there is one blank line before the first property declaration in an OO structure, as well as one blank line between property declarations in OO structures.

The sniff include an auto-fixer.

Ref: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Customisable-Sniff-Properties#squizwhitespacemembervarspacing
@herregroen herregroen merged commit 78128d6 into develop May 28, 2019
@herregroen herregroen deleted the JRF/phpcs-ruleset-add-property-spacing-sniff branch May 28, 2019 14:27
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.

2 participants