Skip to content

@onerepo/plugin-prettier

Install via npm
npm install --save-dev @onerepo/plugin-prettier
function prettier(opts): Plugin;

Include the prettier plugin in your oneRepo plugin setup:

onerepo.config.ts
import { prettier } from '@onerepo/plugin-prettier';
export default {
plugins: [prettier()],
};
ParameterType
optsOptions
type Options: {
githubAnnotate: boolean;
name: string | string[];
useCache: boolean;
};

Options for configuring the Prettier plugin for oneRepo.

onerepo.config.js
export default {
plugins: [
prettier({
useCache: true,
}),
],
};
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
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.

optional useCache: boolean;

Whether to use Prettier’s built-in cache determinism.

  • Default: true
./onerepo.config.ts
import 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:

./onerepo.config.ts
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;

Aliases: one format

Format files with prettier

Terminal window
one prettier [options...]
OptionTypeDescription
--addbooleanAdd modified files after write
--affectedbooleanSelect all affected Workspaces. If no other inputs are chosen, this will default to true.
--all, -abooleanRun across all Workspaces
--checkbooleanCheck for changes.
--files, -farrayDetermine Workspaces from specific files
--stagedbooleanUse 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, -warrayList of Workspace names to run against
Advanced options
OptionTypeDescription
--cacheboolean, default: trueUse Prettier’s built-in cache to determin whether files need formatting or not.
--from-refstringGit ref to start looking for affected files or Workspaces
--github-annotateboolean, default: trueAnnotate files in GitHub with errors when failing format checks in GitHub Actions.
--show-advancedbooleanPair with --help to show advanced options.
--through-refstringGit ref to start looking for affected files or Workspaces