Skip to content

Instantly share code, notes, and snippets.

@devinrhode2
Last active December 8, 2023 20:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devinrhode2/08c84e175c61b282b76f4766a94e4a01 to your computer and use it in GitHub Desktop.
Save devinrhode2/08c84e175c61b282b76f4766a94e4a01 to your computer and use it in GitHub Desktop.
Prettier config settings to reduce merge conflicts
// Prettier config to reduce merge conflicts: https://gist.github.com/devinrhode2/08c84e175c61b282b76f4766a94e4a01
/** @type {import('prettier').RequiredOptions} */
module.exports = {
singleQuote: true,
semi: false,
// avoid even more merge conflicts: https://prettier.io/blog/2020/03/21/2.0.0.html#change-default-value-for-trailingcomma-to-es5-6963httpsgithubcomprettierprettierpull6963-by-fiskerhttpsgithubcomfisker
trailingComma: 'all',
printWidth: 40,
// Less code per line:
// - less likely to have conflict any given line
// - easier to spot changes in git (e.g. getListThing->getListsThing)
// - Encourages modularity
// - jsx components with 20 indent levels will not look good
// - This encourages creating smaller components
// - Still can opt-out with `// prettier-ignore` comments above component
// - OR, create a `.prettierrc.js` file in code you edit the most
}

These prettier config settings are intended to reduce merge conflicts as much as possible.

My original google searches:

what prettier options are best for git diffs

what prettier options are best for git diffs avoid merge conflicts

what prettier options are best for git diffs avoid merge conflicts "trailingComma"

prettier lowest printWidth

Something I would like, is an eslint config that is very similar to prettier, but does has less deterministic formatting

  • I sense starting with Standard.js or XO eslint style config would be a good starting point.

I'm curious what doing a format with printWidth: 1, and then doing a normal format would be like.

Sometimes prettier will make things more vertical, but not make them more horizontal.

Obviously more vertical is best for reducing merge conflicts.

@devinrhode2
Copy link
Author

@devinrhode2
Copy link
Author

devinrhode2 commented Nov 22, 2021

// Prettier defaults that are already great for reducing merge conflicts:

/** @type {import('prettier').RequiredOptions} */
const goodDefaults = {
  // quoteProps: "as-needed", // Cannot be "consistent" - would cause thrashing - could go with "preserve" if it makes more sense in some situation
  // arrowParens: "always", // avoid thrashing
  // bracketSameLine: false, // avoid/minimize merge conflicts:

  // avoid XO default `false` https://github.com/xojs/xo/pull/616/files
  // bracketSpacing: true,
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment