My disdain for Prettier stems from the fact that it restricts my freedom to utilize my preferred brace style.
In my workflow, I rely on tools like CSSComb, PHP CS Fixer, and SCSS Allman Formatter as they support Allman style. While VSCode offers native JavaScript and TypeScript brace style settings:
{
"javascript.format.placeOpenBraceOnNewLineForControlBlocks": true,
"javascript.format.placeOpenBraceOnNewLineForFunctions": true,
"typescript.format.placeOpenBraceOnNewLineForControlBlocks": true,
"typescript.format.placeOpenBraceOnNewLineForFunctions": true,
}
The issue arises when these settings are limited to specific languages only. My desire is to format all types of data in Allman style, including database structures, markup languages, and various programming languages, with the exception of Python.
I have come across recommendations to use ESLint as an alternative to Prettier and JS Beautifier.
To familiarize myself with ESLint, I extensively studied their documentation sections like Getting started and Configuring ESLint.
I initiated the setup by creating a
package.json
file where I included ESLint development dependencies for the project. The contents ofproject/package.json
are as follows:{ "editor.codeActionsOnSave": { "source.fixAll.eslint": true }, "eslint.format.enable": true, "eslint.alwaysShowStatus": true, "eslint.validate": [ "css", "javascript", "json", "jsonc", "markdown", "scss", "typescript" ], }
I then created a
.eslintrc
file in YAML format within the project folder. The content ofproject/.eslintrc.yml
is as below:env: browser: true es2021: true node: true overrides: [] parserOptions: ecmaVersion: latest rules: brace-style: - error - allman
Lastly, I configured the settings in
project/.vscode/settings.json
:{ "editor.codeActionsOnSave": { "source.fixAll.eslint": true }, "eslint.format.enable": true, "eslint.alwaysShowStatus": true, "eslint.validate": [ "css", "javascript", "json", "jsonc", "markdown", "scss", "typescript" ], }
Despite my efforts to run ESLint by selecting Format Document from the Command Palette, it did not yield the desired formatting results.
Experimenting with creating an eslintrc.json
file showed promising outcomes, yet JSON files were still not formatted according to Allman style preferences.
Reflecting on past experiences with Atom, I reminisce about the flexibility it offered in allowing me to apply Allman style across numerous languages.