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

Allow for path-mode option to be used #20

Open
nloyola opened this issue Feb 21, 2023 · 1 comment
Open

Allow for path-mode option to be used #20

nloyola opened this issue Feb 21, 2023 · 1 comment

Comments

@nloyola
Copy link

nloyola commented Feb 21, 2023

In my php-cs-fixer configuration I am excluding directories and files. When edit one of these files and save it, this package reformats the file when it shouldn't.

If the configuration for this package allows the --path-mode=intersection option to be used, then excluded files will not reformatted.

See the manual for a description for this option: https://cs.symfony.com/doc/usage.html

@nloyola
Copy link
Author

nloyola commented Feb 22, 2023

I solved this by adding my own before-save-hook:

(defun nl/php-before-save-hook ()
    (when (string-match-p (regexp-quote ".php") buffer-file-name)
        (let ((file-name (replace-regexp-in-string (projectile-project-root) "" buffer-file-name))
              (command (concat php-cs-fixer-command
                               " list-files --config "
                               (shell-quote-argument php-cs-fixer-config-option)))
              (default-directory (projectile-project-root)))
          (when (string-match-p (regexp-quote file-name) (shell-command-to-string command))
            (php-cs-fixer-fix)
          ))))

It uses php-cs-fixer's list-files command to list all the files that php-cs-fixer should examine.

Note that this code uses Projectile to get the project's root folder.

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

1 participant