Note
Codestyler 5
is the last version that runs on its own code and includes a mechanism for publishing files via command
parameters. It is also the last version installed globally via Composer.
Starting with Codestyler 6
, the project will contain pint.json
and .editorconfig
files, and adding them to the
project will be done by calling a console command.
You can install the package using Composer:
composer require dragon-code/codestyler --dev
composer config scripts.style "vendor/bin/pint --parallel"
After installing the dependency, add a file copy command to the scripts.post-update-cmd
section.
This will automatically copy the pint.json
file to the project root.
When adding the command, replace 8.4
with the minimum PHP version your application works with.
Available presets: 8.2
, 8.3
and 8.4
.
You can also add copying the .editorconfig
file to help the IDE and calling normalize the composer.json
file:
{
"scripts": {
"post-update-cmd": [
"cp vendor/dragon-code/codestyler/presets/pint/8.4.json pint.json",
"cp vendor/dragon-code/codestyler/.editorconfig .editorconfig",
"composer normalize"
]
}
}
Laravel Pint
is used as the linker. Documentation for working with it can be
found here.
The linter is invoked by a console command:
composer style
The .editorconfig
file helps your IDE to work according to certain rules.
To do this, make sure the file is in the root of the project.
You can also automate this process by adding a call to the file copy function in the scripts.post-update-cmd
section of the composer.json
file.
{
"scripts": {
"post-update-cmd": [
"cp vendor/dragon-code/codestyler/.editorconfig .editorconfig"
]
}
}
We recommend using the Composer Normalize plugin,
which normalizes the composer.json
file appearance to match its schema.
This will keep each project's file consistent, making it much easier to read.
To activate the plugin, call the console command:
composer config allow-plugins.ergebnis/composer-normalize true
To use this feature, add a call parameter to the post-update-cmd
block of the composer.json
file:
{
"scripts": {
"post-update-cmd": [
"composer normalize"
]
}
}
Now you can just a run console command:
composer update
After completing all the steps, the composer.json
file will have the following changes:
{
"require-dev": {
"dragon-code/codestyler": "^6.0"
},
"config": {
"allow-plugins": {
"ergebnis/composer-normalize": true
}
},
"scripts": {
"post-update-cmd": [
"cp vendor/dragon-code/codestyler/presets/pint/8.4.json pint.json",
"cp vendor/dragon-code/codestyler/.editorconfig .editorconfig",
"composer normalize"
],
"style": "vendor/bin/pint --parallel"
}
}
After executing the composer update
console command, a .editorconfig
file will be added to your application.
If the file already exists, it will be replaced.
In order for your IDE to read the code style settings from it, make sure its support is enabled in the settings.
For example, in phpStorm
the setting is in
the File | Settings | Editor | Code Style:
This package is licensed under the MIT License.