@x2od/prettier-config
v0.0.3
Published
X-Squared base Prettier configuration
Downloads
4
Readme
@x2od/prettier-config
A shared Prettier config for X-Squared on Demand.
Installation
To install this package run the following command in the terminal in the root directory of your application.
npm install --save-dev @x2od/prettier-config
Usage
Reference it in package.json
using the prettier
property:
{
"name": "my-projects-name",
"prettier": "@x2od/prettier-config",
"devDependencies": {
"@x2od/prettier-config": "latest"
}
}
OR
If you don't want to use package.json
, you can use any of the supported
extensions to export a string:
// `.prettierrc.json` or `.prettierrc` or `.prettierrc.yaml` or `.prettierrc.yml` or `prettierrc.json`
"@x2od/prettier-config"
OR
Create a prettier.config.js
or .prettierrc.js
file and export an object.
To use the configuration as written:
// `prettier.config.js` or `.prettierrc.js`
module.exports = '@x2od/prettier-config';
To extend the configuration:
module.exports = {
...require('@x2od/prettier-config'),
endOfLine: 'lf', // to overwrite the property
};
Extending Shared Configurations
This configuration is not intended to be changed, but if you have a setup where modification is required, it is possible. Prettier does not offer an "extends" mechanism as you might be familiar from tools such as ESLint.
To extend a configuration you will need to:
- Import/Require this sharable config from within your own configuration. This means you must be using a JavaScript version of a Prettier configuration file.
- Export the modified configuration
Prettier uses cosmiconfig for configuration file support. This means you can configure prettier via:
- A
.prettierrc
file, written in YAML or JSON, with optional extensions:.yaml/.yml/.json
.- A
prettier.config.js
or.prettierrc.js
file that exports an object.- A
"prettier"
key in yourpackage.json
file....
Sharing configurations
Note: This method does not offer a way to extend the configuration to overwrite some properties from the shared configuration. If you need to do that, import the file in a
.prettierrc.js
file and export the modifications, e.g:import companyPrettierConfig from '@company/prettier-config'; export default { ...companyPrettierConfig, semi: false };
source: https://github.com/prettier/prettier/blob/main/docs/configuration.md
For example, if you need to change it so that semicolons are required:
// `prettier.config.js` or `.prettierrc.js`
module.exports = {
...require('@x2od/prettier-config'),
semi: true
};