PhpStorm 2018.1 Help

Formatting Files from Command Line

Command-line source code formatter is a special functionality within PhpStorm that lets you format arbitrary files outside a project.

  • In the command line, run format command the using the following syntax:
    format [-h] [-r|-R] [-s|-settings settingsPath] [-m|-mask masks] path1 [path2...]

    The command launches PhpStorm, which formats the specified files and then quits.

The command options are as follows:

OptionDescription
format

The full path to the format.bat (format.sh on macOS and Linux) script located in the <IDE_HOME>/bin directory.

-h (optional) Show the help message and quit.
-r|-R (optional) Scan directories specified in path1,path2... recursively.
-s|-settings settingsPath (optional) Format code according to the code style settings file provided in the settingsPath. You can use one of the following:
  • A file with the exported code style settings: in the Settings/Preferences dialog (Ctrl+Alt+S), open the Editor | Code Style page, click cogwheel black with arrow, and select Export.
  • The .idea/codeStyleSettings.xml file stored in your project directory (for PhpStorm version 2017.2 and earlier).
  • The .idea/codeStyles/codeStyleConfig.xml file stored in your project directory (for PhpStorm version 2017.3 and later).

If the parameter is omitted, the default code style settings will be used.

-m|-mask masks (optional) A comma-separated list of file masks that define the files to be processed. The * (any string) and ? (any single character) wildcards are supported.
pathN The path to a file or directory to be processed.

Examples

  1. Format all files in the C:\Data\src directory including all subdirectories using the default code style settings:
    <IDE_HOME>\bin\format.bat -r C:\Data\src
  2. Non-recursively format all the .xml and .html files in the C:\Data\src directory using code style settings from C:\Data\settings.xml:
    <IDE_HOME>\bin\format.bat -s C:\Data\settings.xml -m * .xml,*.html C:\Data\src
  1. Format all files in the ~/MyProject/src directory including all subdirectories using the default code style settings:
    <IDE_HOME>/bin/format.sh -r ~/MyProject/src
  2. Non-recursively format all the .xml and .html files in the ~/MyProject/src directory using code style settings from ~/Data/settings.xml:
    <IDE_HOME>/bin/format.sh -s ~/Data/settings.xml -m * .xml,*.html ~/MyProject/src
Last modified: 27 July 2018

See Also