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

Add compatibility/arrow-functions-feature lint #42

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

LinusU
Copy link

@LinusU LinusU commented Jan 18, 2025

This is my first attempt at writing a lint!

In order to test it out properly, the MINIMUM_PHP_VERSION needs to be lowered to PHP73 since arrow functions are available on PHP 7.4+. (note: there is currently an issue with "Null Coalesce Assignment Feature" that warns for php_version = "7.4" see more info here: 95a84ce#r151496707)

pub const MINIMUM_PHP_VERSION: PHPVersion = PHPVersion::PHP74;

I have done that locally, and the lint seems to be working! 🎉

Screenshot 2025-01-18 at 16 05 13

Copy link
Member

@azjezz azjezz left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution 😄 could you please rebase?

impl Rule for ArrowFunctionsFeatureRule {
fn get_definition(&self) -> RuleDefinition {
RuleDefinition::enabled("Arrow Functions Feature", Level::Error)
.with_maximum_supported_php_version(PHPVersion::PHP73)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.with_maximum_supported_php_version(PHPVersion::PHP73)
.with_maximum_supported_php_version(PHPVersion::PHP74)

.with_description(indoc! {"
Flags any usage of the `fn` keyword for arrow functions, which was introduced in PHP 7.4.

In environments running older versions of PHP, you can use the `use` keyword to import variables instead.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
In environments running older versions of PHP, you can use the `use` keyword to import variables instead.
In environments running older versions of PHP, you can use an anonymous function
with `use` keyword anonymous functions combined with the `use` keyword to import variables instead.

In environments running older versions of PHP, you can use the `use` keyword to import variables instead.
"})
.with_example(RuleUsageExample::valid(
"Using the `use` keyword for arrow functions",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"Using the `use` keyword for arrow functions",
"Using an anonymous function with `use` keyword",

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.

2 participants