Skip to content

Formatter

Formatter

Shopware CLI provides code formatting through two format commands:

  • extension format to format a single extension
  • project format to format extensions and configured bundles across a Shopware project

The formatter covers PHP and Administration Twig files, along with files supported by Prettier such as JavaScript, TypeScript, Vue, CSS, and SCSS. PHP formatting uses the Shopware Coding Standard.

A --dry-run mode is available to check formatting without rewriting the target files. Shopware CLI propagates the formatter exit status, so a non-zero dry run can mean that formatting changes are required rather than that the formatter crashed.

The Docker examples are recommended because the image already contains the required runtime dependencies. For local execution, the formatter tooling requires PHP 8.2 or later and Node.js 20 or later. Composer and npm are used when Shopware CLI initializes its local tool cache.

Formatting tools

Without --only, a format command invokes every registered verifier tool. The following tools currently implement formatting in Format():

ToolWhat it formatsImplementation
php-cs-fixerPHP source files using the Shopware Coding Standardphpcsfixer.go
prettierPrettier-supported files in source directories using the Shopware CLI bundled configurationprettier.go
admin-twigAdministration Twig templatesadmin_twig.go

Other registered verifier tools do not modify files in format mode.

Format an extension

The extension path is required.

Format a project

Project format behavior

The project format command applies formatting across local extensions and configured bundles in the project. Extensions resolved under vendor/ and extensions listed in validation.ignore_extensions are skipped.

If you omit the path, project format discovers the nearest Shopware project by walking up from the current directory. A directory is recognized as a Shopware project when its Composer metadata references shopware/core and bin/console exists; PROJECT_ROOT overrides this discovery.

Project format options

FlagDescription
--dry-runCheck formatting without modifying files
--only <tools>Run only the specified comma-separated tools

The path argument is optional for project format but required for extension format.

Format only PHP:

shell
shopware-cli project format /path/to/your/project --only php-cs-fixer

Configuration

PHP-CS-Fixer uses a .php-cs-fixer.dist.php from the target root when one is present. Otherwise, Shopware CLI uses its bundled PHP-CS-Fixer configuration.

Prettier uses the configuration bundled with Shopware CLI. A project or extension .prettierrc is not used by the format commands.

Administration Twig formatting uses the Shopware CLI built-in formatter and has no separate configuration file.

Was this page helpful?
UnsatisfiedSatisfied
Be the first to vote!
0.0 / 5  (0 votes)