ぴよがち

技術的な話をします。みんなで強くなりましょう。

Prettierの空白や括弧を取り除く際の挙動について

だいぶどうでもいい内容なんですけど、気づいてしまったので備忘録。

演算子とかの順序を明示するために、必要ないけど括弧を付けることあるじゃないですか。
ESLintのno-mixed-operatorsみたいな感じに。

eslint.org

で、これをprettierに通したら括弧を消されるという事件が起きて、何とかする方法を調べたところ、

github.com

Prettier disregards whitespace and then regenerates it when needed. Sometimes the input and the output happen to be identical, so it looks like 'Prettier kept that whitespace', but it's not exactly what happened. Same with parens. They are not 'kept' or 'removed'.

とのことで、ちょっと衝撃を受けました。

彼らは空白や括弧を一度全部取り去ってから再生成してるんですね。面白い挙動です。

というわけで、この不要な括弧を取り除く挙動を無効にするような設定はないらしいので、Prettierはお役御免にさせていただきました。
おしまい。