Is using Prettier to format code bad.
How to make "Prettier" the default formatter in VS Code? - Stack Overflow
How to format selected code using vscode and Prettier? - Stack Overflow
Those who stopped using prettier , why ?
Videos
» npm install prettier-format
Recently joined a agency as an Contract React developer. I was assigned a task to edit some inline Scss code.
Being a Prettier user I formatted the code, made the necessary changes and submitted a pull request.
Next day the senior developer reviewed my code and asked me to stop using Prettier and assigned me a task to change back the Scss code manually to inline Scss.
When I asked why should I not use prettier to format code. He said it's bad and time consuming and other team members started telling me a story how one time prettier wasn't working and started throwing errors.
That's why they never use it.
I wanted to say that It was showing error because you were doing something wrong.
Just because you once had an bad experience doesn't mean it's bad.
Plus they use one big single Scss file for the whole project.
When I question it too and asked them to use separate files and how it can effect the performance.
One team member answered it doesn't matter, how they don't care about the performance and I should be open minded and learn from them. The boss has 18 years of experience.
What should I learn why not to follow good practices!
Don't know why but setting Default Formatter to ebsenp.prettier didn't work for me. But I found a similar command that worked.
- ctrl + shift + p
- Format document with
- Configure default formatter
- Choose prettier
Open settings by clicking the cog in the bottom left of the vs code side bar and selecting settings from the menu, or by hitting Ctrl+,
At the top right of the settings pane, hit the open file icon (if you hover, the tooltip will read 'Open Settings (JSON)'
Add the following line to the settings json:
"editor.defaultFormatter": "esbenp.prettier-vscode"
I dont know the solution yet, but there are some info that may help.
Basically, there are something wrong with the linter. ( https://github.com/prettier/prettier-vscode/issues/137 )
And your may fix it by checking out this https://prettier.io/docs/en/integrating-with-linters.html ,
- I dont know how & didnt try. cuz:: [[
- looks complicated (download many things) & mess up with the project structure
- may not even work
- some info I have no knowledge of / incompatible with my understanding
- dont know what will happen to my linters
- dont know what is the next step
[]
https://github.com/prettier/prettier-vscode/issues/134
[]
No, the issue is with
prettier-eslintnot supporting range formatting....
I would suggest switching to the recommended approach of integrating ESLint and Prettier
https://github.com/prettier/prettier-vscode/issues/137
[]
let Prettier do the formatting and configure the linter to not deal with formatting rules. You can find instructions on how to configure each linter on the Prettier docs site.
...
For details refer to the Prettier documentation.
https://github.com/prettier/prettier-vscode#linter-integration
[]
Linters usually contain not only code quality rules, but also stylistic rules. Most stylistic rules are unnecessary when using Prettier, but worse – they might conflict with Prettier! Use Prettier for code formatting concerns, and linters for code-quality concerns, as outlined in Prettier vs. Linters.
Luckily it’s easy to turn off rules that conflict or are unnecessary with Prettier, by using these pre-made configs:
eslint-config-prettier
stylelint-config-prettier
https://prettier.io/docs/en/integrating-with-linters.html
[]
I would like to format my code with prettier, then apply all eslint fixes. Previously, this could be achieved by setting prettier.eslintIntegration to true. Now, the extension say that this option is [DEPRECTAED] and prettier-eslint should be used instead. However, it's not clear how to use prettier-eslint in vscode.
https://github.com/prettier/prettier-vscode/issues/999
Actually, "format only selected code" is working on my end, I didnt do any fancy extra config.
What you need to pay attention to is the "syntax tree"
-- ie: dont blindly select across the
scope (the bracket {}).@eg::
given
function test() { let a = [1, 2, 3, 4]; let b = [ 1,2 ,3,4]; // select only this line return false }if you only select::
let b = [ 1,2 ,3,4];then press
ctrl+k, ctrl+feverything is fine
if you select across the bracket (the
}for function scope)::let b = [ 1,2 ,3,4]; // select only this line return false }then press
ctrl+k, ctrl+fthe whole thing in the bracket (the
}for function scope) gets formatted
the "syntax tree" in a
classis a bit weird.-- ie: if you select the WHOLE function AA & format it -- codes inside another function BB will also get formatted...
you may need to apply
// prettier-ignoresomewhere to prevent formattingprettier-ignore
A JavaScript comment of
// prettier-ignorewill exclude the next node in the abstract syntax tree from formatting.https://prettier.io/docs/en/ignore.html
(note, it seems there is no ending tag for
// prettier-ignorefor Javascript (at current stage of Prettier))for the meaning of a "syntax tree", see ex below
if you place it above the code line
seems it applies to the item (the code) (-- which is a "syntax tree node") directly below ((empty lines not counted for)) the// prettier-ignoreline
-- eg-below:console.log("show a", a);, and ends there.if you place it behind the code line (inline)
seems it applies to the inline code only
@for_your_case-do_this:
const test = (a, b, c) => { // prettier-ignore console.log("show a", a); // prettier-ignore console.log("show b", b); } // or const test = (a, b, c) => { console.log("show a", a); // prettier-ignore console.log("show b", b); // prettier-ignore }
Select the code or leave the cursor in the row you want to format and press Ctrl + K Ctrl + F.
» npm install prettier