Skip to content

Support platform-specific paths, variable expansion, and working directory for all tools#225

Merged
benmatselby merged 2 commits intomainfrom
expand-variables
Feb 25, 2026
Merged

Support platform-specific paths, variable expansion, and working directory for all tools#225
benmatselby merged 2 commits intomainfrom
expand-variables

Conversation

@benmatselby
Copy link
Owner

Summary

  • Adds platform-specific path settings using a dict syntax with osx/linux/windows keys, allowing settings to sync across operating systems (closes Plugin in multiple environments #183)
  • Expands Sublime Text variables (${project_path}, ${folder}, etc.) in all setting values, enabling project-relative config file paths (closes Question: php-cs-fixer config file path in sublime-project? #143)
  • Sets working directory to the target file's directory in Fixer, CodeBeautifier, MessDetector, and Linter, matching the existing Sniffer behaviour so that relative paths in _additional_args resolve correctly

Detail

Platform-specific paths (#183)

Any path setting can now accept a dictionary keyed by platform instead of a plain string:

"phpcs_executable_path": {
    "windows": "c:\\xampp\\php\\bin\\phpcs",
    "linux": "/usr/bin/phpcs",
    "osx": "/usr/local/bin/phpcs"
}

A "default" fallback key is also supported. Non-platform dicts (e.g. phpcs_additional_args) are left unchanged.

Variable expansion (#143)

All setting values now support Sublime Text's ${var} syntax via sublime.expand_variables(). The most useful variables are $project_path and $folder, which are stable within a project session. For example:

"php_cs_fixer_additional_args": {
    "--config": "${project_path}/.php-cs-fixer.php"
}

Working directory fix

Fixer, CodeBeautifier, MessDetector, and Linter now set their subprocess working directory to the target file's parent directory (via setWorkingDir), matching what Sniffer already does. This allows tools to find config files via relative paths.

Implementation

All three features are implemented in Pref.get(), keeping the change minimal:

  1. Raw value is fetched from project or global settings
  2. _resolve_platform_value() resolves dict-based platform values
  3. _expand_variables() expands ${var} syntax using window.extract_variables()

This means every setting automatically benefits from both features with no changes needed in the tool classes (except the setWorkingDir calls).

Tests

  • 11 tests for platform resolution (string passthrough, per-platform resolution, default fallback, non-platform dict passthrough, etc.)
  • 8 tests for variable expansion (string expansion, dict recursion, list recursion, no-window fallback, etc.)
  • 5 tests for working directory (one per tool class)

…directory for all tools

- Add platform-specific path settings using dict syntax with osx/linux/windows
  keys, allowing settings to sync across operating systems (closes #183)

- Expand Sublime Text variables (${project_path}, ${folder}, etc.) in all
  setting values, enabling project-relative config file paths (closes #143)

- Set working directory to the target file's directory in Fixer,
  CodeBeautifier, MessDetector, and Linter, matching existing Sniffer
  behaviour so relative paths in additional_args resolve correctly

- Add unit tests for platform resolution, variable expansion, and
  working directory behaviour across all tool classes
@benmatselby benmatselby merged commit 616868a into main Feb 25, 2026
1 check passed
@benmatselby benmatselby deleted the expand-variables branch February 25, 2026 20:39
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.

Plugin in multiple environments Question: php-cs-fixer config file path in sublime-project?

1 participant