I have and error of eslint in my code that I cannot understand how turn off, these are some examples:
As you can see there is a eslint(prettier/prettier) rule that is incomprehensible and I can't understand how to turn off.
This is my eslint and prettier config:
eslint
module.exports = {
root: true,
extends: ['#react-native-community'],
parser: '#typescript-eslint/parser',
plugins: ['#typescript-eslint'],
overrides: [
{
files: ['*.ts', '*.tsx'],
rules: {
'#typescript-eslint/no-shadow': ['error'],
'no-shadow': 'off',
'no-undef': 'off',
},
},
],
};
prettier
module.exports = {
printWidth: 100,
arrowParens: 'avoid',
bracketSameLine: false,
singleQuote: true,
tabWidth: 2
};
Oh Pierro... Its you again.
Your Prettier configuration is not in sync with your ESLint configuration.
When you set Prettier's print-width rule, you need to always make sure that you set ESLint's max-len rule to the same value. This is very import, and is likely causing your issue. You seem to have some other stuff going on though.
#see this post
You need to synchronize the two. Ir looks like a JSX configuration that's causing problems. Try changing the value of bracketSameLine in your prettier configuration to true, or try getting rid of it all together.
You see where it says that the rule prettier/prettier is causing the issue? That should be in your configuration.
That's odd... You don't seem to have your .eslintrc.* file configured properly. It looks like your not properly configuring the eslint-plugin-prettier plugin for ESLint.
If you look at the plugin's documentation, which is where the prettier/prettier rule comes from (the first prettier is the name if the plugin, the second prettier is the name of the rule) it says you need to add the following values to the correct settings in your .eslintrc.* configuration file.
{
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error"
}
}
Its odd that the prettier/prettier rule shows up at all without you having added that configuration.
#see this answer here, it thoroughly explains what the prettier/prettier rule is.
The if the prettier config file is not present, the auto-formatting properties of vscode are taken as the default. the settings.json in the .vscode settings should be in sync with the linter properties. In your case you don't have prettier configured thats why the error is being thrown from prettier/prettier
Problem
I want to use Caps_Lock as the key to exit insert mode in Visual Studio code's vim extension. I have already remapped the keys in Xorg with Xmodmap, but Visual studio doesn't seem to really matter.
My VScode settings
As you can see, I already tried with "vim.insertModeKeyBindings", but it only disables the Escape key, leaving me thinking that Caps_lock has another key name/keysym, but I can't seem to find it.
{
"editor.fontFamily": "'Inconsolata-g for Powerline'",
"editor.fontSize": 16,
"liveshare.authenticationProvider": "GitHub",
"vim.enableNeovim": true,
"code-runner.enableAppInsights": false,
"code-runner.runInTerminal": true,
"workbench.startupEditor": "newUntitledFile",
"workbench.editorAssociations": [
{
"viewType": "jupyter.notebook.ipynb",
"filenamePattern": "*.ipynb"
}
],
"workbench.colorTheme": "BeardedTheme Anthracite",
"extensions.autoUpdate": "onlyEnabledExtensions",
"vim.vimrc.enable": true,
"vim.vimrc.path": "$HOME/.config/nvim/init.vim",
"editor.fontWeight":"bold",
"vim.insertModeKeyBindings": [
{
"before": ["<Esc>"],
"after": ["<Caps_Lock>"]
}
]
}
Another thing i'd like to address is that i already have j,k and their combinations to exit insert mode. Is that a default?
Huge thanks in advance to anybody offering to help!!
Solution
As this problem arose in Linux and, I already changed my settings in Xmodmap, it seems that VScode not respecting remappings with xkbmap is a known issue and should be fixed by adding "keyboard.dispatch": "keyCode" in VScode's settings.json and reopening VS.
Press CTRL + SHIFT + P to open the command pallete.
Then, click on the settings button on any of the commands.
This opens the keybindings.
Search extension.vim_escape
Change this to CAPS_LOCK.
The only issue with this is that it still capitalises things when you re-enter insert mode, so you have to press it twice.
I see you already found a possible workaround, but I wonder if the 'xcape' tool
(apt install xcape) can help with the following in your bashrc?
# set capslock to escape key
setxkbmap -option ctrl:nocaps
xcape -e '#66=Escape'
I recently started using Code Runner Extension for Vs-Code and despite checking off the "code-runner.showExecutionMessage": false it keeps printing the file path, and some unwanted code after which it does print output but it's not clean, looks messy and hard to read the output. Here's what it does.
PS [path] \VsCode\ProblemSolving> cd "[path] \VsCode\ProblemSolving"
PS [path] \VsCode\ProblemSolving> cd "[path] \VsCode\ProblemSolving\" ; if ($?)
{ g++ CodingCompetitionTools.cpp -o CodingCompetitionTools } ; if ($?) { .\CodingCompetitionTools }
This precedes the actual program output and I don't want to see this, just the clean program output.
Settiings.json for code-runner
"code-runner.defaultLanguage": "c++",
"code-runner.saveAllFilesBeforeRun": true,
"code-runner.saveFileBeforeRun": true,
"code-runner.fileDirectoryAsCwd": true,
"code-runner.showExecutionMessage": false,
"code-runner.clearPreviousOutput": true,
"code-runner.runInTerminal": false,
Refer this link for Vs-Code Marketplace extension
Could you please share your settings.json file?
I guess your setting looks like this?
{
"code-runner.showExecutionMessage": false
}
Maybe you have code-runner.runInTerminal set to true? If so, change it to false.
Just to debug this a little further, create a .vscode folder in the root of your current project (with a preceding dot) and inside of that folder a settings.json file with just:
{
"code-runner.defaultLanguage": "c++",
"code-runner.saveAllFilesBeforeRun": true,
"code-runner.saveFileBeforeRun": true,
"code-runner.fileDirectoryAsCwd": true,
"code-runner.showExecutionMessage": false,
"code-runner.clearPreviousOutput": true,
"code-runner.runInTerminal": false
}
See if this changes anything.
Apologies if these steps are already obvious to you, but better safe than sorry.
I'm trying to get Prettier to format my files with a printWidth of 80 chars (what I understand to be the default). However, even with my user settings configured:
"prettier.printWidth": 80
AND using a .prettierrc config in the project:
{
"tabWidth": 2,
"useTabs": false,
"printWidth": 80
}
...nothing changes when I save a file (other settings are implemented, which makes me think there is a conflict somewhere).
Even the Prettier output in VS Code shows that it's pulling in the config:
["INFO" - 8:27:53 PM] Using config file at '/Users/username/Documents/whatever/.prettierrc'
["INFO" - 8:27:53 PM] Prettier Options:
{
"filepath": "/Users/username/Documents/whatever/project/file.mdx",
"parser": "mdx",
"tabWidth": 2,
"useTabs": false,
"printWidth": 80
}
["INFO" - 8:27:53 PM] Formatting completed in 93.855083ms.
You're formatting MDX, which is a variant of Markdown. Breaking text to respect the print width in Markdown is considered unsafe by default because this can affect some renderers sensitive to line breaks. That's why Prettier's option proseWrap(docs) defaults to preserve. Set it to always for Prettier to start wrapping text.
When I execute a Format Document command on a Vue Component.vue file VSCode replace all single quoted string with double quoted string.
In my specific case this rule conflicts with electron-vue lint configuration that require singlequote.
I don't have prettier extensions installed (no prettier.singleQuote in my setting)
How to customize VSCode to avoid this?
I dont have prettier extension installed, but after reading the possible duplicate answer I've added from scratch in my User Setting (UserSetting.json, Ctrl+, shortcut):
"prettier.singleQuote": true
A part a green warning (Unknown configuration setting) the single quotes are no more replaced.
I suspect that the prettier extension is not visible but is embedded inside the Vetur extension.
Well, like the guy (#user2982122) mentioned but instead of File go to Code -> Preferences -> Settings, then look for Quote, select Prettier and check both boxes
For projects that use .editorconfig file by default. The formatter will ignore the rules in the settings and use the rules in .editorconfig, then you can either:
Remove .editorconfig file, and use your VSCode settings.
Add quote_type = single to the .editorconfig file regarding your file type. You can also set quote_type value to double or auto.
It looks like it is a bug open for this issue: Prettier Bug
None of above solution worked for me.
The only thing that worked was, adding this line of code in package.json:
"prettier": {
"singleQuote": true
},
At the time of writing (June 2022):
please consider that .editorconfig overwrites every other configuration at the end, find the file (most probably on the root of your project), edit it and add the following:
[*]
quote_type = single
From the vuejs/vetur issue page https://github.com/vuejs/vetur/issues/986#
This solution worked for me.
In VSCodes settings.json file add this entry
"vetur.format.defaultFormatterOptions": {
"prettier": {
"singleQuote": true
}
},
Install prettier extension and paste below code in your VSCode settings.json file
"prettier.useEditorConfig": false,
"prettier.singleQuote": true
this will ignore your .editorconfig file setting.
What worked for me was setting up the .prettierrc.json config file. Put it to the root of your project with a sample config like this:
{
"singleQuote": true,
"trailingComma": "all",
"tabWidth": 2,
"semi": true,
"arrowParens": "always"
}
After triggering the Format Document command, all works just as expected.
Side note: What comes as a bonus with this solution is that each team member gets the same formatting outputs thanks to the present config file.
Correct solution :
I add .prettierrc.js file in my main root project
and write
module.exports = {
singleQuote: true
};
For newbies like me:
From the menu Nav bar at the top: Select File -> Preferences -> Settings.
In the search text box, type in Quote
In the filtered list that appears below, look for the gear icon and next to it - "Prettier". Click on check box to enable "Prettier: Single Quote"
I had the same issue in vscode. Just create a .prettierrc file in your root directory and add the following json.
For single quotes add:
{
"singleQuote": true
}
For double quotes add:
{
"singleQuote": false
}
Try one of these solutions
In vscode settings.json file add this entry
"prettier.singleQuote": true
In vscode if you have .editorconfig file, add this line under the root [*] symbol quote_type = single
In vscode if you have .prettierrc file, add this line
{
"singleQuote": true,
"vetur.format.defaultFormatterOptions": {
"prettier": {
"singleQuote": true
}
}
}
quote_type = single
add this inside .editorconfig
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false
quote_type = single
As noted by #attdona the Vetur extension includes prettier.
While you can change the prettier settings, as per the accepted answer, you can also change the formatter for specific regions of a vue component.
Here, for example, I've set Vetur to use the vscode-typescript formatter as it uses single quotes by default:
in .prettierrc add
{
"arrowParens": "avoid",
"semi": false,
"singleQuote": true
}
After struggling with the issue I found a useful tool. If you click on the Prettier word in the right lower corner you will get the Output window opened. In that window once you run formatting (in my case it is Alt + Shift + F) you will see all the configurations which prettier will use to format the document. So, we can clearly see that specifying the prettier in the prettier.singleQuote is wrong. It should just be singleQuote. Hence, having the .prettierrc file in my user root folder with the following contents produced the desired result:
{
"trailingComma": "none",
"useEditorConfig": false,
"singleQuote": true
}
Also, make sure that you have the Prettier extension installed.
I'm using typescript, for me it got resolved with checking "Tslint integration" flag under prettier settings (in vscode preferences):
There only solution that worked for me:
and only for Angular Projects:
Just go into your project ".editorconfig" file and paste 'quote_type = single'.
Hope it should work for you as well.
In my case, the problem was in the escaping \ character inside the string:
message = 'Error argument is not an object, it\'s ' + typeof error
Turning on the avoidEscape option and using double quotes for that string solved the problem:
message = "Error argument is not an object, it's " + typeof error
.eslintrc.js
module.exports = {
rules : {
// Other rules...
'quotes' : ['error', 'single', {'avoidEscape' : true}],
}
}
I added file called .prettierrc in my project folder.
File content:
{
"singleQuote": true,
"vetur.format.defaultFormatterOptions": {
"prettier": {
"singleQuote": true
}
}
}
It works for me to check single quote in Prettier as well
tslint.autoFixOnSave as true
You can use this in settings.json
"javascript.preferences.quoteStyle": "single"
Use this extension.
https://marketplace.visualstudio.com/items?itemName=BriteSnow.vscode-toggle-quotes
cmd ' (ctrl ' on win/Linux) will cycle among ' " `
For JSX use:
{"jsxSingleQuote": false}
First, install the Prettier extension. Create a .prettierrc configuration file at the root of your project. And add config like below:
{
"trailingComma": "es5",
"singleQuote": true,
"jsxSingleQuote": true,
"printWidth": 100,
"tabWidth": 2,
"semi": true,
"endOfLine": "auto"
}
Well for me both options solved the issue:
By adding inside the .prettierrc - "singleQuote": true
Or by adding following inside the package.json ->
"prettier": {
"singleQuote": true
}
Though I tried also adding .prettierrc.js and have following
module.exports = {
singleQuote: true
};
This didn't worked.
I had a lot of issues controlling linting and prettier formating. I had rules for eslint on for prettier like
"prettier/prettier": [
"error",
{ "singleQuote": true, "trailingComma": "none" }
],
and rules inside .prettierrc file
{
"tabWidth": 2
}
But my .prettierrc file was not getting processed. My fix was installing prettier as a package on dev dependency. So the solution that worked for me was installing all these packages eslint-config-prettier eslint-plugin-prettier and prettier.
This works for me :
try right click on the current document
and choose "format document with " ,
and choose your own format extension for the document.
:)
If you're using a YAML plugin, it also has a single/double quote option that was tripping me up. Cheers.
"prettier": {
"singleQuote": true
},
This line of code save my hours.