Skip to content

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

Merged
hsanson merged 1 commit intodense-analysis:masterfrom
Firehed:fix-phpcs-cwd
Mar 28, 2026
Merged

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

Conversation

@Firehed
Copy link
Copy Markdown
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>
@hsanson hsanson merged commit 0369442 into dense-analysis:master Mar 28, 2026
8 checks passed
hsanson added a commit to hsanson/ale that referenced this pull request Mar 28, 2026
* upstream/master:
  Added support for harper in markdown files (dense-analysis#5104)
  fix(phpcs): run from project root instead of file directory (dense-analysis#5105)
  support running solargraph via bundle (dense-analysis#5097)
  Fix dense-analysis#5062 - Keep ALE LSP compatible with Neovim 0.10 and 0.11+
  Tell OpenCode how to write ALE code
  feat(rstcheck): Add automatic --config support with version check (dense-analysis#5095)
  Truncate astro test files to quiet dependabot
  Skip ALE docker download attempts
  doc goimport (dense-analysis#5093)
  refactor: use ale#Pad for option padding across the codebase (dense-analysis#5091)
  add option to lint diff buffers (dense-analysis#3185)
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

2 participants