11/7/2023 0 Comments Gql formatter![]() ![]() The primary one of these being git blame, but also, conflicts with currently open PRs - this difficulty can be eased though. Unless Prettier’s been introduced from the start, converting a codebase usually leaves one large prettification commit, which can have knock-on effects. Unit tests, with their long identifiers, can be particularly hard-done-by: This is in part because line width drives how we structure code, in a similar way to indent spacing - 2-space indent makes code more likely to have nested constructs. For example, applying a line width of 80/90 to code originally written for 120 columns will cause some uglifications. This means any project that goes away from the beaten track may run into edge-cases. While this can be configured, a lot of the formatting rules are implemented to work prettily on lines that go up to around column 80. That is - Prettier will attempt to fit as much as possible on one line, which works well for this limit, but perhaps not so much for longer lines. Prettier is designed with an 80-column limit in mind. Prettier’s view is that there might be more methods chained later, so this maintains consistency with that case. This used to make me to do a double-take, before I actually read the code. For example, the indent of the closing-parenthesis/opening-brace on complex if-statements: Prettier can take a little getting used to - many of its choices are well intentioned and make code much easier to read. So read on for all the gory details about Prettier - does running it on your code after changes always produce the same result? (spoiler: no) Can its interaction with git be improved? (spoiler: yes) Do you have to let it clobber files and trigger rebuilds? (spoiler: no) Prettier Peculiar Formatting In Prettier’s case, this cost surfaces in a few areas, and here’s how my project tackled them. As with any feature we add to the development process, there is a cost. When I’m developing, I can even forget about extra spaces or scrambled pasted-in object definitions - Prettier will tidy them all. They free developers from having to format their code as they type, and prevent disagreements in code reviews over code formatting. When collaborating on code, tools like Prettier can be incredibly useful for productivity. Or: How I Learnt to Stop Worrying and Love Automated Code Formatting Intro There are changes we can make and tricks we can apply to streamline all of this. Prettier, and code formatting can polarise developers - everyone has an opinion on braces.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |