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

Introduce NAMED_ARGUMENT_SEPARATOR_TYPE and related rules. #302

Merged
merged 9 commits into from
Aug 30, 2024

Conversation

VincentLanglet
Copy link
Owner

@VincentLanglet VincentLanglet commented Aug 17, 2024

Closes #300

@codecov-commenter
Copy link

codecov-commenter commented Aug 17, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 98.14815% with 1 line in your changes missing coverage. Please review.

Project coverage is 99.95%. Comparing base (9402a6a) to head (ad9672e).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/Rules/Function/NamedArgumentSeparatorRule.php 93.75% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@              Coverage Diff              @@
##                main     #302      +/-   ##
=============================================
- Coverage     100.00%   99.95%   -0.05%     
- Complexity       734      757      +23     
=============================================
  Files             64       66       +2     
  Lines           2290     2343      +53     
=============================================
+ Hits            2290     2342      +52     
- Misses             0        1       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@VincentLanglet VincentLanglet force-pushed the namedArgument branch 2 times, most recently from 3081cdc to af51dbe Compare August 17, 2024 10:59
@@ -587,6 +590,17 @@ private function lexOperator(string $operator): void
} elseif (':' === $operator && $this->isInTernary()) {
$bracket = array_pop($this->bracketsAndTernary);
$this->pushToken(Token::OPERATOR_TYPE, $operator, $bracket);
} elseif ('=' === $operator) {
$bracket = end($this->bracketsAndTernary);
if (false !== $bracket && '(' === $bracket->getValue()) {
Copy link
Owner Author

Choose a reason for hiding this comment

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

I'm not against a double check here (cc @smnandre)

I tried {{ (foo=1) }} or {{ (1=2) }} and nothing was supported by twig.

Is = used somewhere else than in

{% set foo = 1 %}
{{ function(foo=1) }}

? (which means that ( imply it's a named operator)

Copy link
Contributor

Choose a reason for hiding this comment

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

in named arguments for functions and filters (so you may have multiple ones)

Copy link
Owner Author

Choose a reason for hiding this comment

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

I just thought about default value for macro.
{% macro input(name='foo') %}{{ name }}{% endmacro %}

This one need to be handled differently since it cannot be changed to :.

in named arguments for functions and filters (so you may have multiple ones)

functions and filters (and tests) should work the same (and mutliple named operator too).

src/Token/Token.php Outdated Show resolved Hide resolved
@VincentLanglet VincentLanglet force-pushed the namedArgument branch 3 times, most recently from fe7bf65 to 7742a43 Compare August 17, 2024 15:30
@VincentLanglet VincentLanglet changed the title Introduce NAMED_ARGUMENT_OPERATOR_TYPE Introduce NAMED_ARGUMENT_OPERATOR_TYPE and related rules. Aug 17, 2024
@VincentLanglet VincentLanglet force-pushed the namedArgument branch 3 times, most recently from daebc61 to 676105e Compare August 17, 2024 15:52
Comment on lines 20 to 22
if (!InstalledVersions::satisfies(new VersionParser(), 'twig/twig', '>=3.12.0')) {
throw new \InvalidArgumentException('Named argument with semi colons requires twig/twig >= 3.12.0');
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If you want to, you can use the Twig Environment constants for this.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Not sure it can be trusted, when we see mistake like https://github.com/twigphp/Twig/blob/v3.11.0/src/Environment.php#L48

@VincentLanglet VincentLanglet changed the title Introduce NAMED_ARGUMENT_OPERATOR_TYPE and related rules. Introduce NAMED_ARGUMENT_SEPARATOR_TYPE and related rules. Aug 17, 2024
@VincentLanglet VincentLanglet force-pushed the namedArgument branch 11 times, most recently from cd6732f to 7d3d9d4 Compare August 18, 2024 09:21
@VincentLanglet VincentLanglet merged commit 1158bcd into main Aug 30, 2024
17 checks passed
@VincentLanglet VincentLanglet deleted the namedArgument branch August 30, 2024 10:11
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.

Rule idea: named argument syntax
3 participants