1

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 ?

Code > User > settings.json

{
  "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.

Community
  • 1
  • 1
cyb3rZ
  • 43,853
  • 82
  • 251
  • 430
  • 1
    isn't this for javascript? why you are using it for PHP why not using prettier for PHP: https://github.com/prettier/plugin-php – ROOT Mar 16 '20 at 10:20

3 Answers3

3

From the Beautify extension repo README:

Beautify javascript, JSON, CSS, Sass, and HTML in Visual Studio Code.

You are attempting to format PHP code.

I recommend PHP Intelephense. It formatted my file well on save.

PHP Intelephense extension

Before save:

PHP code unformatted

After save:

PHP code formatted

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.

teddybeard
  • 1,133
  • 7
  • 13
1

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:

phpfmt - PHP formatter

Sehdev
  • 4,779
  • 3
  • 8
  • 28
0

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?

Mech
  • 3,611
  • 1
  • 12
  • 25