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

Various sniffs: simplify skipping the rest of the file + update docs about skipping rest of file #363

Merged
merged 2 commits into from
Mar 1, 2024

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Feb 24, 2024

Description

Inspired by #360

*Sniff::process(): update documentation

As the tokens stack indexes are 0-based and a token count is 1-based, it is sufficient to return the token count to skip the rest of the file.

Various sniffs: simplify skipping the rest of the file

This commit updates various sniffs to use return $phpcsFile->numTokens instead of return ($phpcsFile->numTokens + 1).

If a sniff file contains 50 tokens, the last $stackPtr will be 49, so returning 50 will already get us passed the end of the token stack and the + 1 is redundant.

Suggested changelog entry

N/A

Copy link
Contributor

@rodrigoprimo rodrigoprimo left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thanks for working on this!

As the tokens stack indexes are 0-based and a token count is 1-based, it is sufficient to return the token count to skip the rest of the file.
This commit updates various sniffs to use `return $phpcsFile->numTokens` instead of `return ($phpcsFile->numTokens + 1)`.

If a sniff file contains 50 tokens, the last `$stackPtr` will be 49, so returning `50` will already get us passed the end of the token stack and the `+ 1` is redundant.
@jrfnl jrfnl force-pushed the feature/various-sniff-update-skip-to-end-code branch from aecb4f6 to dd80edb Compare March 1, 2024 09:10
@jrfnl
Copy link
Member Author

jrfnl commented Mar 1, 2024

Rebased without changes. Merging once the build passes.

@jrfnl jrfnl merged commit 0eee691 into master Mar 1, 2024
44 checks passed
@jrfnl jrfnl deleted the feature/various-sniff-update-skip-to-end-code branch March 1, 2024 09:41
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