Skip to content

Instantly share code, notes, and snippets.

@devinrhode2
Last active December 8, 2023 20:32
Show Gist options
  • Select an option

  • Save devinrhode2/08c84e175c61b282b76f4766a94e4a01 to your computer and use it in GitHub Desktop.

Select an option

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,
// Makes inline-diff highlighting less relelvant.
// - In VSCode, if you edit the last character in a line, it may be hard to see the actual change.
// - Or if there's a one-letter typo... VSCode will highlight that one character change
// - However, with a low printWidth, code becomes very vertical
// - Of course, still aasier to spot single character change with VSCode's help, but
// - Since there's less characters overall, there's less code to look through on any given line
}

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