This package provides a shareable config for the Prettier code formatter.
npm install --save-dev @m-thalmann/prettier-config
Create a .prettierrc.cjs
file with the following content:
const prettierConfig = require('@m-thalmann/prettier-config');
module.exports = prettierConfig.default;
If you want to overwrite some settings or have additional configs to use, you can do so by using the merge()
function:
const prettierConfig = require('@m-thalmann/prettier-config');
const projectConfig = {
// override any project-specific settings
};
module.exports = prettierConfig.merge(prettierConfig.default, projectConfig);
The prettierConfig.merge()
function receives at least one configuration to merge with. The configurations are merged from left to right, so the last configuration will override the previous ones.
For PHP projects, you can also include the php
config:
const prettierConfig = require('@m-thalmann/prettier-config');
const projectConfig = {
// override any project-specific settings
};
module.exports = prettierConfig.merge(
prettierConfig.default,
prettierConfig.php('8.1'), // set your project's PHP version (optional)
projectConfig,
);
Make sure to also install the @prettier/plugin-php
package:
npm install --save-dev @prettier/plugin-php
The configuration for the PHP config is applied within the overrides
array (only applying to *.php
files).
[!NOTE]
When using VS Code you have to take care of some additional settings to make the PHP plugin work correctly. See the Prettier PHP Plugin documentation for more information.
This package is released under the MIT License.