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

CLI: Arguments checked as file paths #10465

Closed
gneuvill opened this issue Dec 7, 2023 · 9 comments
Closed

CLI: Arguments checked as file paths #10465

gneuvill opened this issue Dec 7, 2023 · 9 comments

Comments

@gneuvill
Copy link

gneuvill commented Dec 7, 2023

Hi,

New to psalm, I successfully installed it through composer, generated a config file and run it. But as I tried to enable some plugins (previously installed with composer also), I consistently got this abstruse response : Cannot locate enable.

I traced the error using echo statements up to the call to CliUtils::getPathsToCheck(null) in Psalm/Config.php l. 1305. Once I commented out that call, the 'enable' command ran to completion without errors. (so 92bcc5c looks like the culprit and the "enable" argument was apparently treated as a file path)

I am on linux, using php 8.2.12, composer 2.6.5, psalm 5.17.

Hope that will help.

@gneuvill gneuvill changed the title Arguments checked as file paths CLI: Arguments checked as file paths Dec 7, 2023
@kkmuffme
Copy link
Contributor

Can you post the exact command you used to run psalm please?

@florisluiten
Copy link
Contributor

I've got the same problem.

Console output:

$ composer require --dev vimeo/psalm:5.17.0
[...snip...]

$ composer require --dev psalm/plugin-symfony
[...snip...]

$ ./vendor/bin/psalm-plugin enable
  Not enough arguments (missing: "pluginName").
enable [-c|--config CONFIG] [--] <pluginName>

$ ./vendor/bin/psalm-plugin enable psalm/plugin-symfony
Cannot locate enable

@gneuvill
Copy link
Author

@kkmuffme

Can you post the exact command you used to run psalm please?

composer require --dev php-standard-library/psalm-plugin
vendor/bin/psalm-plugin enable php-standard-library/psalm-plugin

@kkmuffme
Copy link
Contributor

The problem is that the "psalm-plugin" command was added with symfony, which has its own argv resolution, but then internally will load a psalm config, which then falls back to psalm's own argv resolution, creating this error.

The error is then initiated from https://github.com/vimeo/psalm/blob/5.x/src/Psalm/Config.php#L1305, which checks the argv and will create this error subsequently.

It's hacky but just wrapping the $paths_to_check in a condition like

global $argv;
if (!isset($argv[0]) || basename($argv[0]) !== 'psalm-plugin') {

should fix the issue.
Can either of you try that and create a PR if it works?

@florisluiten
Copy link
Contributor

Yes, although it now complains about $paths_to_check not being defined ;)

$ ./vendor/bin/psalm-plugin enable psalm/plugin-symfony
PHP Warning:  Undefined variable $paths_to_check in vendor/vimeo/psalm/src/Psalm/Config.php on line 1312

[OK] Plugin enabled

The psalm.xml file is updated correctly :)

@kkmuffme
Copy link
Contributor

kkmuffme commented Dec 13, 2023

I thought it's obvious that above the "if" you added, you need to add $paths_to_check = null; that's why I didn't mention that

@florisluiten
Copy link
Contributor

I thought it's obvious that above the "if" you added, you need to add $paths_to_check = null; that's why I didn't mention that

Yes it was, I was joking. Sorry :-)

@commonpike
Copy link

commonpike commented Jan 9, 2024

Exactly the same error, psalm 5.18, symfony 5.4.15

Even calling vendor/bin/psalm-plugin show returns Cannot locate show

#10465 (comment) fixed it.

Never installed psalm before, and the first thing I have to do is hack it to get it working :-D

@kkmuffme
Copy link
Contributor

kkmuffme commented Jan 9, 2024

Never installed psalm before, and the first thing I have to do is hack it to get it working :-D

The fix is PRed already since a month #10483, nobody had time to merge & release it yet though

@orklah orklah closed this as completed in e6a48e1 Jan 9, 2024
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

No branches or pull requests

4 participants