I have code that when formatted with Prettier ESLint gives me an error
ORIGINAL:
$(document).trigger('HideDropDown').trigger('UpdateDropDowns');
FIXED with Prettier
$(document)
.trigger('HideDropDown')
.trigger('UpdateDropDowns');
ESLINT complains that I need extra spaces as such:
$(document)
.trigger('HideDropDown')
.trigger('UpdateDropDowns');
Is this something that needs to be adjusted through Prettier or ESLint? I do prefer only two spaces rather than 4 but I am not sure how to adjust it so that ESLint doesn't complain about it.
In my case I figured out that the following setting would allow ESLint and Prettier work together well:
"MemberExpression": 1 // default is 2
Related
I have vim-prettier installed and also have the vscode extension for prettier installed.
They format differently however. I would like to use vim-prettier to format the same way I would for vscode's prettier.
I followed vscode's configuration and it lead me to /home/user/.prettierrc.json but it is empty and only has {} inside of it.
I put let g:prettier#autoformat = ["/home/user/.prettierrc.json"]
inside my .vimrc file but it does not format to the same way vscode-prettier does.
Is there a way to do this?
So first I tried whereis prettier and compared it to the value i get from running :PrettierCliPath
prettier is in /usr/local/bin/prettier
and the one that vim uses is in /home/user/node_modules/.bin/prettier
I tried to set my vimrc to point to the first one via
let g:prettier#exec_cmd_path = "~/path/to/cli/prettier"
But it didn't work. It gave me a syntax error whenever I tried to run prettier in vim.
After a long time I noticed this line in the README for vim-prettier
Note: vim-prettier default settings differ from prettier intentionally. However they can be configured by:
and it gave a bunch of settings like let g:prettier#config#print_width = 'auto'
So I ended up just manually configuring each setting to the desired result.
Now I want to find a way to only allow these settings for a certain filetype(html) so that the formatter for html and css are different instead of the same.
I have an SCSS file that contains a calc() function.
When i use a calc function without spaces around the operator like so calc(var(--primary-color-h)+5) the transpiled CSS result doesn't work. Only when i set spaces around the operator does it work; like this calc(var(--primary-color-h) + 5)
How would i instruct VSCODE to created spaces around the operator upon save.
I have prettier, scss Formatter and StyleLint installed. But neither seems to fix it.
tnx,
RDG
You can use Stylelint and the following two rules:
function-calc-no-unspaced-operator
function-whitespace-after
These will flag the lack of space before and after the + operator, respectively. See this demo.
This rules are turned on the SCSS standard config, which you can extend in your Stylelint configuration object:
{
"extends": "stylelint-config-standard-scss"
}
How would i instruct VSCODE to created spaces around the operator upon save
You can use the editor.codeActionsOnSave option from the official Visual Studio Code extension for Stylelint. And the following to your VS Code settings file:
"editor.codeActionsOnSave": {
"source.fixAll.stylelint": true
}
I'm using prettier in VS Code for typescript. It always remove extra parenthesis, for example
(new Controller()).setData(data).run();
will always be format into
new Controller().setData(data).run();
Which rules handle this deletion? I did see a similar rule in eslint: no-extra-parens. However, I am not using this rule in my eslint file.
I'm using prettier to format my Vue files, but can't find to seem a setting that puts props/attributes of html elements to new lines.
I'd like to make sure that my code is always formatted as it is for v-text-fieldin a yellow frame, rather than below. I set Prose Wrap to "never", but I guess that was not it. Any help appreciated!
You can set the setting of Print Width to higher value.
That's what Prettier does: breaks lines if they get too long. It doesn't make sense to use Prettier if you don't need its line-breaking behavior as this behavior and Prettier are one and the same.
I have my Prettier extension set to make my code prettier on save. It works amazing 99% of the time...
However:
If I type
If (x = 14) {};
my prettier extension in VsCode will change it to
if ((x=14)) {};
which will cause nothing to work. I have tried everything to fix this. Prettier is great, but this is so annoying, please help ...
It looks suspicious to me that you use single equal sign in the if statement. Are you sure you want to assign a value? Not sure why prettier uses double brackets though. It may be to highlight the unusual.