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

RichParser: stricter identifiers parser #3079

Merged
merged 7 commits into from
May 23, 2024

Conversation

janedbal
Copy link
Contributor

No description provided.


yield [
'<?php' . PHP_EOL .
'test(); // @phpstan-ignore mečoun' . PHP_EOL,
Copy link
Contributor

Choose a reason for hiding this comment

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

The identifier grammar should be the same as any other PHP identifier grammar, ie. allow \x80-\xff to be valid identifier character - https://www.php.net/manual/en/language.variables.basics.php#language.variables.basics.

Copy link
Member

Choose a reason for hiding this comment

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

No, it's very simple ASCII for good reasons

public const PATTERN_IDENTIFIER = '[a-zA-Z0-9](?:[a-zA-Z0-9\\.]*[a-zA-Z0-9])?';


yield [
'<?php' . PHP_EOL .
'test(); // @phpstan-ignore identifier -- comment' . PHP_EOL, // phpcs comment style
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a question - if the identifiers have to be delimited by comma, what are the reasons to not allow free-text comment, ie. comment not wrapped in parenthesis?

ex: @phpstan-ignore return.reg https://github.com/doctrine/dbal/pull/6407

Such grammar is unambiguous as after @phpstan-ignore and ,\s* one identifier will be still required.

I find this more natural and it will also URL issue we currently have - @phpstan-ignore return.reg (https://github.com/doctrine/dbal/pull/6407) - is opened as https://github.com/doctrine/dbal/pull/6407).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With that, you could not use comma in comment, right?

@phpstan-ignore identifier.one ignored, because of PHPStan bug, identifier.two

Now you can (and you can even use parenthesis inside):

  • @phpstan-ignore identifier.one (ignored, because of PHPStan bug), identifier.two
  • @phpstan-ignore identifier.one (ignored (because of PHPStan bug)), identifier.two

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@phpstan-ignore return.reg (doctrine/dbal#6407) - is opened as doctrine/dbal#6407).

Most widely used IDE (PHPStorm) does not do that (luckily for us).

Copy link
Contributor

@mvorisek mvorisek May 16, 2024

Choose a reason for hiding this comment

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

99% ignores are consisting of a single identifier. So I mean to parse anything after the current \w+( \(...\))?(, \w+( \(...\))?)* (simplified) grammar as a free-text comment.

@ondrejmirtes ondrejmirtes merged commit 5a73f07 into phpstan:1.11.x May 23, 2024
23 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

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.

3 participants