@onerepo/plugin-prettier
Installation
Section titled Installationnpm install --save-dev @onerepo/plugin-prettier
yarn add --dev @onerepo/plugin-prettier
pnpm install --save-dev @onerepo/plugin-prettier
Configuration
Section titled Configurationprettier()
Section titled prettier()function prettier(opts): Plugin;
Include the prettier
plugin in your oneRepo plugin setup:
import { prettier } from '@onerepo/plugin-prettier';
export default { plugins: [prettier()],};
Parameters
Section titled ParametersParameter | Type |
---|---|
opts | Options |
Options
Section titled Optionstype Options: { githubAnnotate: boolean; name: string | string[]; useCache: boolean;};
Options for configuring the Prettier plugin for oneRepo.
export default { plugins: [ prettier({ useCache: true, }), ],};
Type declaration
Section titled Type declarationgithubAnnotate?
Section titled githubAnnotate?optional githubAnnotate: boolean;
When true
or unset and run in GitHub Actions, any files failing format checks will be annotated with an error in the GitHub user interface.
- Default:
true
name?
Section titled name?optional name: string | string[];
The name of the prettier command. You might change this to 'format'
or ['format', 'prettier']
to keep things more familiar for most developers.
useCache?
Section titled useCache?optional useCache: boolean;
Whether to use Prettier’s built-in cache determinism.
- Default:
true
Recommended tasks
Section titled Recommended tasksimport type { Config } from 'onerepo';
export default { tasks: { 'pre-commit': { serial: ['$0 prettier --add'], }, 'pre-merge': { serial: ['$0 prettier --check'], }, },} satisfies Config;
If you’re also running ESLint, it is important to run Prettier after ESLint. Do this by creating sequential tasks: an array of tasks within the serial
tasks array:
import type { Config } from 'onerepo';
export default { tasks: { 'pre-commit': { serial: [['$0 eslint --add', '$0 prettier --add']], }, 'pre-merge': { serial: [['$0 eslint --all --no-fix', '$0 prettier --check']], }, },} satisfies Config;
Commands
Section titled Commandsone prettier
Section titled one prettierAliases: one format
Format files with prettier
one prettier [options...]
Option | Type | Description |
---|---|---|
--add | boolean | Add modified files after write |
--affected | boolean | Select all affected Workspaces. If no other inputs are chosen, this will default to true . |
--all, -a | boolean | Run across all Workspaces |
--check | boolean | Check for changes. |
--files, -f | array | Determine Workspaces from specific files |
--staged | boolean | Use files on the git stage to calculate affected files or Workspaces. When unset or --no-staged , changes will be calculated from the entire branch, since its fork point. |
--workspaces, -w | array | List of Workspace names to run against |
Advanced options
Option | Type | Description |
---|---|---|
--cache | boolean , default: true | Use Prettier’s built-in cache to determin whether files need formatting or not. |
--from-ref | string | Git ref to start looking for affected files or Workspaces |
--github-annotate | boolean , default: true | Annotate files in GitHub with errors when failing format checks in GitHub Actions. |
--show-advanced | boolean | Pair with --help to show advanced options. |
--through-ref | string | Git ref to start looking for affected files or Workspaces |