odin-bot-v2 icon indicating copy to clipboard operation
odin-bot-v2 copied to clipboard

Repo: Add .prettierrc

Open MaoShizhong opened this issue 11 months ago • 2 comments

Complete the following REQUIRED checkboxes:

  • [x] I have thoroughly read and understand The Odin Project Contributing Guide

  • [x] The title of this issue follows the command name: brief description of request format, e.g. /help: add optional @user parameter

The following checkbox is OPTIONAL:

  • [ ] I would like to be assigned this issue to work on it

1. Description of the Feature Request: Currently, prettier is listed as a project dependency (also a little odd it's not listed as a devDep).

On several occasions, if someone is using the VSCode PRettier extension (very common due to the curriculum recommendations), format-on-save or muscle memory with a keybind can kick in which leads to needing to make a new commit reverting any unintentional formatting changes (e.g. quotes, spacing, indents etc.)

This can be solved by adding a root-level .prettierrc file containing the following:

{
    "arrowParens": "always",
    "bracketSpacing": true,
    "bracketSameLine": false,
    "endOfLine": "lf",
    "htmlWhitespaceSensitivity": "css",
    "insertPragma": false,
    "printWidth": 80,
    "proseWrap": "preserve",
    "quoteProps": "as-needed",
    "semi": true,
    "singleQuote": true,
    "tabWidth": 2,
    "trailingComma": "all",
    "useTabs": false
}

The above is the ruleset I found to be the closest formatting to most of the JS files and will result in the fewest unintentional changes. The only real changes to expect would be a few line-break changes due to the 80 printWidth value (80 seems to fit more files than 100, and IMHO is a little more readable for many of the ones that do end up shifting due to it). Perhaps also a few trailing commas (setting to 'es5' removes quite a few from function args in some files).

But as far as I can see, there shouldn't be many changes other than those, and even those should only be limited to the odd line in the odd file.

2. Acceptance Criteria:

  • [ ] Add a top-level .prettierrc file with the above ruleset

3. Additional Information: If approved, the work should be simple so would be happy for anyone to claim it if so. But if it goes unclaimed for a while after approval, I'll knock it out quick.

MaoShizhong avatar Mar 08 '24 15:03 MaoShizhong

This should enable us to format everything with prettier . -w.

cakegod avatar Mar 20 '24 22:03 cakegod

You can even have a GH actions bot run that command in the workflow to ensure nothing is merged without matching

damon314159 avatar Mar 21 '24 09:03 damon314159