I'm using Prettier to reformat my code in VSCode. When I start new TypeScript projects, I add the following .prettierrc
file:
{
"semi": false,
"useTabs": false,
"tabWidth": 2,
"arrowParens": "avoid",
"endOfLine": "lf",
"printWidth": 120,
"trailingComma": "none"
}
To semicolon or not to semicolon
I've written some blogs on TypeScript and JavaScript; I started to omit the semicolons. Why? I think it makes my code easier to read on my blogs. Because I'm a C# developer, typing a ;
comes naturally. I'll let Prettier remove them, to keep my code consistent.
More info about automatic semicolon insertion on MDN.
Tabs or spaces?
I'm a big tab fan, but for my blogs spaces just look better: sorry.
ArrowParens!?
I'm not a native English speaker, so I had to google its meaning. It helps to remove the parens )(
from the fat arrows:
let array = [1, 2, 3]
let before = array.map((x) => x * 2)
// "arrowParens": "avoid"
let after = array.map(x => x * 2)
Conclusion
I would like my blogs to contain code that clear. Any settings that can help to reduce overhead will end up in my file (except for endOfLine
😉).
Changelog
- 2022-10-25 Added
"trailingComma": "none"
setting.