Skip to content

fix(phpcs): run from project root instead of file directory#5105

Open
Firehed wants to merge 1 commit intodense-analysis:masterfrom
Firehed:fix-phpcs-cwd
Open

fix(phpcs): run from project root instead of file directory#5105
Firehed wants to merge 1 commit intodense-analysis:masterfrom
Firehed:fix-phpcs-cwd

Conversation

@Firehed
Copy link
Contributor

@Firehed Firehed commented Mar 7, 2026

Summary

When phpcs.xml sets installed_paths to a relative path (e.g. vendor/slevomat/coding-standard), running phpcs from the file's directory causes it to fail because the path is resolved relative to cwd rather than the config file location.

This changes the linter to find the project root by looking for:

  1. phpcs.xml / phpcs.xml.dist / .phpcs.xml / .phpcs.xml.dist
  2. composer.json (fallback)

If none are found, it falls back to ALE's default behavior (returns v:null).

This follows the same pattern as the phpstan linter.

Most likely fixes #3146; I suspect we have the same underlying issue, but that ticket is over 5 years old so I don't want to do too much digging.

Test plan

  • Existing tests pass
  • Added composer.json to test fixture for project root detection
  • Manually verified phpcs now works when editing files in subdirectories of a project with installed_paths set to a relative vendor path

🤖 Generated with Claude Code

When phpcs.xml sets installed_paths to a relative path (e.g.
vendor/slevomat/coding-standard), running phpcs from the file's
directory causes it to fail because the path is resolved relative to
cwd rather than the config file location.

Change cwd to find the nearest composer.json and use that directory,
matching how most PHP ecosystem tools expect to operate.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

phpcs config that relies on paths relative to the project root don't work

1 participant