Format JavaScript code in PHP files using Prettier - Fast and lightweight!
This VS Code extension allows you to format JavaScript code embedded in PHP files. Works cross-platform (Windows, macOS, Linux) and supports Format on Save.
`
Features
Format JavaScript files (.js) using Prettier
Format JavaScript code within PHP files (.php)
Selection-based formatting - Format only selected code
Press Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (macOS)
Run Format JS using PHP
Format JavaScript in PHP Files (Selection)
Open a PHP file containing JavaScript code
Select the JavaScript code you want to format
Right-click and choose Format JS in PHP (Selection)
Or use Ctrl+Shift+P and run Format JS in PHP (Selection)
Configuration
You can customize the indentation style to match your preferences (tabs vs. spaces) by opening your VS Code Settings (Ctrl+, or Cmd+,) and searching for Format JS in PHP:
formatJsInPhp.useTabs: Enable this to use Tabs for indentation. Disable it to use Spaces (default).
formatJsInPhp.tabWidth: The number of spaces per indentation level. Only applies when useTabs is false (default is 2).
(Note: If your workspace has a .prettierrc file, the extension will also automatically respect those formatting rules!)