Skip to content

[Repo Assist] fix: align configSearch file priority with PHP_CodeSniffer's auto-detection order#137

Draft
github-actions[bot] wants to merge 1 commit intomasterfrom
repo-assist/fix-configsearch-file-priority-order-53c7502674640938
Draft

[Repo Assist] fix: align configSearch file priority with PHP_CodeSniffer's auto-detection order#137
github-actions[bot] wants to merge 1 commit intomasterfrom
repo-assist/fix-configsearch-file-priority-order-53c7502674640938

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot commented Apr 8, 2026

🤖 This is an automated draft PR from Repo Assist.

Problem

The confFileNames array in getStandard() had its entries in the wrong order relative to what PHP_CodeSniffer itself uses when auto-detecting ruleset files.

Extension's previous order:

.phpcs.xml → .phpcs.xml.dist → phpcs.xml → phpcs.xml.dist → phpcs.ruleset.xml → ruleset.xml
```

**PHP_CodeSniffer's actual order** (from [`Config.php`](https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/src/Config.php)):
```
.phpcs.xml → phpcs.xml → .phpcs.xml.dist → phpcs.xml.dist

The bug: .phpcs.xml.dist was placed before phpcs.xml. This means if a project had both .phpcs.xml.dist (a distribution template) and phpcs.xml (the actual project config) in the same directory, the extension would pass .phpcs.xml.dist to --standard= instead of phpcs.xml.

Fix

Reorder confFileNames to match PHPCS's own priority:

['.phpcs.xml', 'phpcs.xml', '.phpcs.xml.dist', 'phpcs.xml.dist', 'phpcs.ruleset.xml', 'ruleset.xml']
```

The two PHPCS-style legacy names (`phpcs.ruleset.xml`, `ruleset.xml`) remain at the end since PHPCS no longer includes them in its own discovery but older projects may still use them.

## Test Status

Three new priority-ordering unit tests added to `test/unit.test.js`:

```
 findFiles (10/10 passing) 
  including:
   PHPCS priority: .phpcs.xml beats phpcs.xml when both exist
   PHPCS priority: phpcs.xml beats .phpcs.xml.dist when both exist
   PHPCS priority: .phpcs.xml.dist beats phpcs.xml.dist when both exist

node --check extension.js: OK

No CI workflow exists in this repository; all checks are manual.

Impact

This is an edge-case fix — it only affects users who have multiple config files in the same directory (e.g. a project with both .phpcs.xml.dist checked in as a template and phpcs.xml as the active config). For everyone else, the behaviour is unchanged.

Relates to #17 (extension ignores phpcs.xml).

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@346204513ecfa08b81566450d7d599556807389f

…-detection order

The confFileNames array had .phpcs.xml.dist before phpcs.xml, but
PHP_CodeSniffer itself searches in this order:
  .phpcs.xml > phpcs.xml > .phpcs.xml.dist > phpcs.xml.dist

This only matters when a project has two different config files in
the same directory (e.g. both phpcs.xml and .phpcs.xml.dist), but
the extension was silently choosing the wrong one.

Fix: reorder to match PHPCS Config.php:
https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/src/Config.php

Also adds 3 new unit tests that document and lock in the correct priority.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants