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

Expire comment by composer dependency package version #32

Merged
merged 30 commits into from
Dec 20, 2023
Merged

Conversation

staabm
Copy link
Owner

@staabm staabm commented Dec 20, 2023

closes #31

@staabm
Copy link
Owner Author

staabm commented Dec 20, 2023

@nikophil wdyt? feedback welcome

@staabm staabm marked this pull request as ready for review December 20, 2023 11:29
@staabm staabm changed the title Expire comment by package version Expire comment by dependency package version Dec 20, 2023
@staabm staabm changed the title Expire comment by dependency package version Expire comment by composer dependency package version Dec 20, 2023
@staabm
Copy link
Owner Author

staabm commented Dec 20, 2023

@m29corey maybe you can run this against some real world projects to see possible perf impact?

Copy link

@VincentLanglet VincentLanglet left a comment

Choose a reason for hiding this comment

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

Hi, this seems to be a great idea.

In some personal open source project, I encounter the situation where I have code to support both Symfony 6 and 7 (for example) ; with a composer constraint

"symfony/symfony": "^6 || ^7"

and with a comment in my code

TODO Remove this when dropping Symfony 6 support

And even if locally my composer.lock use SF 7, I would expect to not have the error until I remove ^6 from the composer.json.

Does this PR could satisfy this need ?

Copy link

@nikophil nikophil left a comment

Choose a reason for hiding this comment

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

wow this was fast 😅

actually my rule is looking pretty much not different from yours!

src/TodoByPackageVersionRule.php Outdated Show resolved Hide resolved
// TODO: not-installed/package:<5 this should error because package is not in composer.json

// TODO: phpunit/phpunit:<9
// TODO: phpunit/phpunit:<10

Choose a reason for hiding this comment

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

wouldn't this test fail when using phpunit 10? 🤔

Copy link
Owner Author

Choose a reason for hiding this comment

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

right, I had had the logic reversed. I think all feedback is addressed now

Copy link

@nikophil nikophil Dec 20, 2023

Choose a reason for hiding this comment

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

and now your rule looks even closer from mine 😅

@nikophil
Copy link

nikophil commented Dec 20, 2023

I've also added a way to test against php version. I've done my rule few month ago, but I think if I've done this because InstalledVersions::satisfies() or InstalledVersions::isInstalled() do not recognize php as a dependency:

if ('php' === $dependency) {
    if (\version_compare(\PHP_VERSION, $constraint, '>=')) {
$errors[] = \sprintf('dependency "%s" satisfies constraint "%s"%s', $dependency, $constraint, $message ? ": {$message}." : '.');
    }

    continue;
}

// TODO: phpunit/phpunit:<50 This has to be fixed when updating to phpunit 50.x

// TODO: phpunit/phpunit:<5 This has to be fixed when updating to phpunit 5.x
// TODO: phpunit/phpunit:5.3.* This has to be fixed when updating to phpunit 5.3.*
Copy link

@nikophil nikophil Dec 20, 2023

Choose a reason for hiding this comment

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

actually I've done my check the other way around, and the rule fails when constraint is satisfied

phpunit/phpunit:>=10

I think it reads better: "please phpstan, fail when phpunit meets this dependency"

About this specific todo: phpunit/phpunit:5.3.*, I think it would not fail when phpunit is at 5.3.*
but it will if we have phpunit>=5.4.0 and phpunit<5.3, which seems pretty strange

My take was to always add >= if the constraint does not specifies it

@nikophil
Copy link

@VincentLanglet I don't think this PR satisfies your need: it only looks on what is currently required by composer.lock but does not read composer.json which is what you'd need

@staabm
Copy link
Owner Author

staabm commented Dec 20, 2023

I've also added a way to test against php version. I've done my rule few month ago, but I think if I've done this because InstalledVersions::satisfies() or InstalledVersions::isInstalled() do not recognize php as a dependency:

if ('php' === $dependency) {
    if (\version_compare(\PHP_VERSION, $constraint, '>=')) {
$errors[] = \sprintf('dependency "%s" satisfies constraint "%s"%s', $dependency, $constraint, $message ? ": {$message}." : '.');
    }

    continue;
}

I have similar stuff locally. what I don't like is, that this code depends on the runtime php version. I would want to compare the composer.json php requirement against the comment constraint.. I haven't found a way to achieve that though :)

@staabm
Copy link
Owner Author

staabm commented Dec 20, 2023

Does this PR could satisfy this need ?

@VincentLanglet I think it kind of satiesfies it, but in an unexpected way. the result of the check depends on your composer.lock, which means it compares against the constraints which have been installed with composer install.

this means as long as you run the check against a composer.lock which was generated with the minimum supported php version of your package, it should work

@staabm staabm merged commit 4ba5f23 into main Dec 20, 2023
11 checks passed
@staabm staabm deleted the package-vers branch December 20, 2023 19:14
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.

expire comment by composer package version
3 participants