Skip to content

Instantly share code, notes, and snippets.

@devinrhode2
Last active December 8, 2023 20:32
Show Gist options
  • 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
/*
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.
*/
/** @type {import('prettier').RequiredOptions} */
module.exports = {
printWidth: 40,
// determined here:
// commit 27987c4b47834a1fff9402b729d3a39d7539b6f9 (origin/chore-dgr-dropping-xo-fix-all-script, chore-dgr-dropping-xo-fix-all-script)
// Author: Rhode, Devin <[email protected]>
// Date: Wed Oct 27 16:29:49 2021 -0500
//
// wip redirect manager
//
// It also 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
// Required:
bracketSameLine: false,
jsxBracketSameLine: false // deprecated in 2.4
// Required:
trailingComma: 'all'
// Cannot be "consistent" - would cause thrashing in git history:
quoteProps: "as-needed" // Could go with "preserve" if it makes more sense in some situation
// Devins personal preference:
// Also avoids extra finger movement:
singleQuote: true
// Avoid thrashing, assert default?
arrowParens: "always"
// avoid XO default `false` https://github.com/xojs/xo/pull/616/files
bracketSpacing: true,
}
@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