Skip to content

Add new Sniff to check declare statements #179

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

jaymcp
Copy link
Member

@jaymcp jaymcp commented Apr 7, 2025

Description

Introduces linting for declare statements.

It will ensure that there is:

  • a lower case keyword
  • no space between the keyword and opening parenthesis
  • one space after the opening parenthesis
  • a lower case declaration type
  • no unsupported declaration type (i.e. only ticks, strict_types, or encoding)
  • one space before the equals sign
  • one space after the equals sign
  • one space before the closing parenthesis
  • no space between the closing parenthesis and terminating semi-colon
  • one space between the closing parenthesis and opening curly brace in a block declaration
  • no content after the opening curly brace in a block declaration
  • a newline before the closing curly brace in a block declaration
  • same-column alignment between the declare keyword and closing curly brace

Most of these also come with fixers.

Our expectations:

declare( strict_types = 1 );

declare( encoding = 'utf8' );

declare( ticks = 1 ) {
    // stuff here
}

Changelog

  • Add declare statement Sniff

Types of changes:

  • Bug fix (non-breaking change which fixes an issue).
  • New feature (non-breaking change which adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as expected).

Checklist:

  • All checks pass when running `composer run all-checks.

@jaymcp jaymcp marked this pull request as ready for review April 30, 2025 14:46
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

Successfully merging this pull request may close these issues.

1 participant