Reputation: 58662
In VS Code, I have Beautify
installed and enabled.
https://marketplace.visualstudio.com/items?itemName=HookyQR.beautify
I tested on my a php file,
When I hit save, I can't get the reindent or beautify to happen.
What did I missed ?
{
"workbench.startupEditor": "newUntitledFile",
"window.zoomLevel": 1,
"editor.fontSize": 14,
"terminal.integrated.fontSize": 11,
"extensions.ignoreRecommendations": true,
// syncedSideBar
"explorer.autoReveal": true,
// Is git enabled
"git.enabled": false,
// Path to the git executable
"git.path": null,
// Whether auto fetching is enabled.
"git.autofetch": false,
"workbench.statusBar.visible": false,
"workbench.activityBar.visible": true,
"eslint.autoFixOnSave": true,
"explorer.confirmDelete": false,
"explorer.confirmDragAndDrop": false,
"workbench.colorTheme": "Monokai",
"javascript.updateImportsOnFileMove.enabled": "always",
"openInGitHub.providerType": "github",
"gitlens.advanced.messages": {
"suppressGitDisabledWarning": true
},
"liveServer.settings.donotShowInfoMsg": true,
"window.closeWhenEmpty": false,
"editor.emptySelectionClipboard": false,
"editor.dragAndDrop": false,
"editor.fontFamily": "Source Code Pro",
"editor.selectionHighlight": false,
"window.openFilesInNewWindow": "off",
"workbench.editor.enablePreview": true,
"editor.scrollBeyondLastLine": false,
"editor.mouseWheelScrollSensitivity": 5,
"window.title": "${activeEditorFull}${separator}${rootName}",
"editor.tabSize": 4,
"files.trimTrailingWhitespace": true,
"editor.useTabStops": true,
"editor.wordWrap": "on",
"editor.formatOnPaste": false,
"editor.multiCursorModifier": "ctrlCmd",
"editor.snippetSuggestions": "top",
"vsicons.dontShowNewVersionMessage": true,
"files.autoSave": "afterDelay",
"editor.formatOnType": false,
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}
I just want to reindent my code when I saved.
Upvotes: 1
Views: 1888
Reputation: 5662
Same issue is already listed on Beautify official github repository
As per their reponse
Beautify doesn't support PHP.
If you want beautify
PHP
files, you have to use different addon, for example:
Upvotes: 1
Reputation: 2014
From the Beautify extension repo README:
Beautify
javascript
,JSON
,CSS
,Sass
, andHTML
in Visual Studio Code.
You are attempting to format PHP code.
I recommend PHP Intelephense. It formatted my file well on save.
Before save:
After save:
IMPORTANT: only formats a file if it contains no closing ?>
php tag. You will have to remove your closing tags. From PHP Tags documentation:
If a file contains only PHP code, it is preferable to omit the PHP closing tag at the end of the file. This prevents accidental whitespace or new lines being added after the PHP closing tag, which may cause unwanted effects because PHP will start output buffering when there is no intention from the programmer to send any output at that point in the script.
Upvotes: 4
Reputation: 4015
For Windows click on 'File' -> Preferences -> Settings. Then search for editor.formatOnSave, and put "true" instead of "false"
For Mac click on 'Code' (top left of screen, to the left of 'File', 'Edit', and 'View') -> Preferences -> Settings -> enter the term 'editor.formatOnSave' in the search settings box at the top of the page. Click on the tick to mark it as true.
src: Beautify on save in VS code?
Upvotes: 0