PhpStorm 2017.1 Help

Command Line Formatter

On this page:

Introduction

Command-line source code formatter is a special functionality within PhpStorm that lets you format arbitrary files outside of a project. So doing, the formatter makes use of XML files with the exported code style settings (Settings/Preferences | Editor | Code Style - Manage - Export Code Style XML File) and a file specification that defines a file or a group of files to be formatted.

For the files to be formatted there should be corresponding plugins which support the required file types. For example, PHP files will be formatted only if PHP plugin is installed.

Formatter launcher script

The script is format.bat/format.sh (Windows/Linux,Mac) in <PhpStorm_HOME>/bin directory, where <PhpStorm_HOME> is PhpStorm's root installation directory. The script launches PhpStorm, which formats the specified files and quits. If launched without any parameters or with -h parameter, the script outputs a list of its options.

Usage

format [-h] [-r|-R] [-s|-settings settingsPath] [-m|-mask masks] [path1 [path2]...]

Parameters

ParameterDescription
-hShows a help message and quits.
-r|-RScans directories specified in path1,path2... recursively.
-s|-settings settingsPathsettingsPath is a path to the file with the exported code style settings.

-m|-mask masksA comma-separated list of file masks, which define the files to be processed. The wildcard characters * (any string), ? (any single character) are supported.
pathNA path to a file or a directory to be processed.

Example

1. Format all the files in C:\Data\src directory, including all subdirectories, using the default code style settings:

format -r C:\Data\src

2. Non-recursively format all .java and .html files in C:\Data\src directory, using code style settings from C:\Data\settings.xml:

format -s C:\Data\settings.xml -m * .java,*.html C:\Data\src

See Also

Last modified: 19 July 2017