How can I auto-format the style block in vue3 properly with TailwindCSS with colon character? - visual-studio-code

I have a vue file with a style block like this, using TailwindCSS and PostCSS
<style scoped lang="postcss">
.button {
#apply bg-green-200 hover:bg-green-400;
}
</style>
In VSCode, with the Volar extension, I can perform auto-format. However, after auto-format, my style looks like this
<style scoped lang="postcss">
.button {
#apply bg-green-200 hover: bg-green-400; # notice the space after hover:
}
</style>
This breaks TailwindCSS because it would treat "hover:" and "bg-green-400" as 2 separate classes.
What can I adjust to improve on this? I don't see a lot of option when trying to create ".vscode/settings.json" myself to control Volar.
I am using:
Vue 3
Nuxt 3
TailwindCSS 3
Volar VSCode extension
VSCode
Update
I don't have any vscode setting in the root directory. Here is my VSCode global settings
{
"git.autofetch": true,
"explorer.confirmDragAndDrop": false,
"git.confirmSync": false,
"files.associations": {
"*.rmd": "markdown"
},
"workbench.editorAssociations": {
"*.ipynb": "jupyter-notebook",
"*.wasm": "default"
},
"terminal.integrated.inheritEnv": false,
"files.autoSave": "afterDelay",
"git.suggestSmartCommit": false,
"[dart]": {
"editor.formatOnSave": true,
"editor.formatOnType": true,
"editor.rulers": [
80
],
"editor.selectionHighlight": false,
"editor.suggest.snippetsPreventQuickSuggestions": false,
"editor.suggestSelection": "first",
"editor.tabCompletion": "onlySnippets",
"editor.wordBasedSuggestions": false
},
"editor.suggestSelection": "first",
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
"files.watcherExclude": {
"**/.bloop": true,
"**/.metals": true,
"**/.ammonite": true
},
"workbench.productIconTheme": "fluent-icons",
"jupyter.askForKernelRestart": false,
"security.workspace.trust.untrustedFiles": "open",
"notebook.cellToolbarLocation": {
"default": "right",
"jupyter-notebook": "left"
},
"diffEditor.ignoreTrimWhitespace": false,
"redhat.telemetry.enabled": false,
"[vue]": {
"editor.defaultFormatter": "Vue.volar"
},
"files.exclude": {
"**/.classpath": true,
"**/.project": true,
"**/.settings": true,
"**/.factorypath": true
},
"[python]": {
"editor.defaultFormatter": "ms-python.python"
},
"liveServer.settings.donotShowInfoMsg": true,
"editor.inlineSuggest.enabled": true,
"github.copilot.enable": {
"*": true,
"yaml": false,
"plaintext": false,
"markdown": false,
"scala": false,
"properties": false,
"rust": false,
"python": false,
"typescript": false,
"http": false,
"vue": false
},
"[java]": {
"editor.defaultFormatter": "scalameta.metals"
},
"files.autoSaveDelay": 1500,
"[typescript]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
},
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"remote.SSH.defaultExtensions": [
"gitpod.gitpod-remote-ssh"
],
"remote.SSH.configFile": "/var/folders/rz/j1sp0c394pn5sv5pttp2pkt40000gn/T/gitpod_ssh_config-55598-oizqwPMdK6La",
"terminal.integrated.fontFamily": "JetBrainsMono Nerd Font Mono",
"terminal.integrated.fontSize": 13,
"editor.fontFamily": "JetBrainsMono Nerd Font Mono",
"editor.fontSize": 13,
"[javascript]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
},
"[postcss]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}

I'm facing the same issue as you. What I can do now is install the postcss-nesting package add it to the postcss.config.js file:
module.exports = {
plugins: {
'tailwindcss/nesting': 'postcss-nesting',
tailwindcss: {},
autoprefixer: {},
},
}
In the style tag, you can do something like this:
<style scoped lang="postcss">
.button {
#apply bg-green-200;
&:hover {
#apply bg-green-400;
}
}
</style>

Related

How to prevent automatically turn tab to space when save a file

I got a formatting issue, please help me guys. When I Ctrl+S a .js file, it turn to indent Tab for a moment then turn indent to Space. Yes I have tried to set Tabs size to 2 and uncheck Insert Space in settings but no use. Here is my settings.json file. I use Prettier for default code formatter.
{
//"editor.formatOnSave": true,
"editor.formatOnType": true,
"editor.tabSize": 2,
"prettier.singleQuote": true,
"prettier.useTabs": true,
"terminal.integrated.defaultProfile.windows": "Git Bash",
"editor.fontWeight": "normal",
"editor.defaultFormatter": "esbenp.prettier-vscode",
"liveServer.settings.donotShowInfoMsg": true,
"workbench.startupEditor": "none",
"workbench.iconTheme": "vscode-icons",
"editor.guides.bracketPairs": true,
"[css]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"prettier.printWidth": 72,
"prettier.useEditorConfig": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"html.customData": ["snippet"],
"html.format.indentInnerHtml": true,
"git.autofetch": true,
"eslint.codeActionsOnSave.rules": null,
"eslint.workingDirectories": [
{
"mode": "auto"
}
],
"editor.parameterHints.enabled": false,
"vetur.completion.scaffoldSnippetSources": {
"workspace": "💼",
"user": "🗒️",
"vetur": "✌"
},
"[vue]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"workbench.editorAssociations": {
"*.sqlite": "sqlite-viewer.option"
},
"vsicons.dontShowNewVersionMessage": true,
"[python]": {
"editor.defaultFormatter": "ms-python.python"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"diffEditor.ignoreTrimWhitespace": false,
"bracket-pair-colorizer-2.depreciation-notice": false,
"editor.suggest.showKeywords": false,
"vetur.format.options.useTabs": false,
"sync.autoDownload": true,
"editor.comments.insertSpace": false,
"editor.detectIndentation": true,
"editor.tabCompletion": "on",
"editor.trimAutoWhitespace": false
}

Is there a list of all VS Code settings.json fields?

In the example settings.json below, the html.fake setting is greyed out with the error Unknown Configuration Setting, meaning VSCode is aware of all possible config settings.
Is there a way to view this full list, or view an example settings.json with the default values for all accepted fields?
{
"html.autoClosingTags": "never",
"html.fake": "never"
}
I understand extensions may have their own config settings; I'm only interested in the base settings.
Please find the list of all default settings for VSCode(Link). I believe this is what you are looking for.
{
"files.autoSave": "afterDelay",
//"workbench.colorTheme": "Dracula Soft",
//"compile-hero.generate-minified-html": true,
//"compile-hero.generate-minified-css": true,
"php.validate.executablePath": "C:/php-7.4.28/php.exe",
"php.executablePath": "C:/php-7.4.28/php.exe",
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
//"editor.renderIndentGuides": true,
"editor.fontWeight": "normal",
"editor.detectIndentation": false,
"editor.tabSize": 3,
"editor.suggestSelection": "first",
"editor.codeLensFontFamily": "Fira Code, Operator Mono",
"editor.codeLensFontSize": 16,
"breadcrumbs.enabled": false,
"editor.fontSize": 15,
"editor.fontFamily": "Fira Code, Operator Mono",
"editor.fontLigatures": "terminal.integrated.cursorWidth",
"editor.cursorWidth": 2,
"editor.lineHeight": 24,
// cursor
"editor.cursorSmoothCaretAnimation": true,
"editor.cursorBlinking": "expand",
"editor.quickSuggestions": {
"other": true,
"comments": true,
"strings": true,
"tag": true,
"class": true,
"id": true
},
// config related to code formatting
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": false,
"[javascript]": {
"editor.formatOnSave": true
},
"[javascriptreact]": {
"editor.formatOnSave": true
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
"source.fixAll.tslint": true,
"source.organizeImports": true
},
//terminal
//"terminal.integrated.cursorSmoothCaretAnimation": true,
"terminal.integrated.cursorBlinking": true,
"terminal.integrated.cursorStyle": "line",
"terminal.integrated.fontSize": 16,
"terminal.integrated.lineHeight": 1.5,
//"terminal.integrated.fontWeight": "normal",
"terminal.integrated.fontFamily": "Fira Code, Operator Mono",
"terminal.integrated.cursorWidth": 2,
// "terminal.integrated.shell.windows": "C:/Users/user/AppData/Local/Microsoft/WindowsApps/wt.exe",
"terminal.integrated.automationShell.windows": null,
// terminal customization
"workbench.colorCustomizations": {
"terminal.ansiBlack": "#171c2a",
"terminal.ansiRed": "#E35535",
"terminal.ansiGreen": "#52AB62",
"terminal.ansiYellow": "#ffd866",
"terminal.ansiBlue": "#00B3BD",
"terminal.ansiMagenta": "#e991e3",
"terminal.ansiCyan": "#78e8c6",
"terminal.ansiWhite": "#FFFFFFcc",
"terminal.ansiBrightBlack": "#00B3BD",
"terminal.ansiBrightRed": "#E35535",
"terminal.ansiBrightGreen": "#52AB62",
"terminal.ansiBrightYellow": "#ffd866",
"terminal.ansiBrightBlue": "#00B3BD",
"terminal.ansiBrightMagenta": "#e991e3",
"terminal.ansiBrightCyan": "#78e8c6",
"terminal.ansiBrightWhite": "#ffffff",
"terminal.background": "#171c2a",
"terminalCursor.background": "#ffd866",
"terminalCursor.foreground": "#ffd866",
// Editor customaize
// "editorIndentGuide.activeBackground": "#430f7e",
// "editorIndentGuide.background": "#3a383a",
// "activityBar.background": "#740ee9f8",
// "editorBracketMatch.background": "#430f7e",
// "editorBracketMatch.border": "#ffffff",
//"editor.wordHighlightStrongBackground": "#740ee9f8",
"editor.wordHighlightBorder": "#740ee9f8",
//"editor.rangeHighlightBackground": "#740ee9f8",
// "editor.rangeHighlightBorder": "#740ee9f8",
"editor.selectionBackground": "#c7c7c76b",
// "editor.selectionHighlightBorder": "#ffffff",
// "tab.activeBackground": "#5332a0",
// "tab.border": "#430f7e"
},
// "prettier.disableLanguages": ["html", "css"],
"dictCompletion.addSpaceAfterCompletion": true,
"beautify.language": {
"js": {
"type": ["javascript", "json", "jsonc"],
"filename": [".jshintrc", ".jsbeautifyrc"]
},
"css": ["css", "scss"],
"html": ["htm", "html", "css", "javascript", "php", "blade"],
"php": ["javascript", "php", "blade"]
},
"phpformatter.logging": true,
"[json]": {
"editor.quickSuggestions": {
"strings": true
},
"editor.suggest.insertMode": "replace"
},
"workbench.colorTheme": "Learn with Sumit - Peace of the eye",
"workbench.iconTheme": "vscode-icons",
"[php]": {
"editor.defaultFormatter": "bmewburn.vscode-intelephense-client"
},
"[html]": {
"editor.defaultFormatter": "HookyQR.beautify"
},
"cSpell.userWords": [
"backorder"
],
"explorer.confirmDelete": false,
"window.zoomLevel": 1,
}
I hope you got the answering.

how to solve or find problems in VS Code Editor settings.json file?

My settings.json file shows 3 problems with my settings but I can't find it. My settings is below -
{
"telemetry.enableTelemetry": false,
"window.zoomLevel": 1,
"workbench.iconTheme": "material-icon-theme",
"workbench.colorTheme": "Community Material Theme Ocean",
"explorer.confirmDelete": false,
"javascript.validate.enable": false,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"files.associations": {
"*.js": "javascriptreact"
},
"editor.formatOnSave": true,
"git.enableSmartCommit": true,
"liveServer.settings.https": {
"enable": true
},
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
}
so I just removed this part
"liveServer.settings.https": {
"enable": true
},
and now no problem is showing. but don't know why

VSCode Add All Missing imports Not Working

For example i make a new create-react-app and i remove App import from index.js. ESLint shows the problem and i can fix it by clicking on App and pressing "Ctrl + Space" or "Ctrl + ." and import App with a click, but i want files to be imported on save.
Source Action > Add all missing imports doesn't work, but interestingly organize imports does.
I don't know what could be the problem. I want to use organize imports and add missing imports on save together.
My Settings.json
+
One thing i realized that vs code can't tell what files are missing at all, because when i removed the auto import extension both ctrl + space and ctrl + . stopped working.
{
"workbench.iconTheme": "vscode-icons",
"liveServer.settings.donotShowInfoMsg": true,
"window.zoomLevel": 1,
"git.enableSmartCommit": true,
"eslint.format.enable": true,
"editor.formatOnSave": true,
"javascript.updateImportsOnFileMove.enabled": "always",
// "files.autoSave": "afterDelay",
"diffEditor.renderSideBySide": false,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"explorer.confirmDragAndDrop": false,
"emmet.triggerExpansionOnTab": true,
"emmet.includeLanguages": {
"javascript": "javascriptreact"
},
"emmet.syntaxProfiles": {
"javascript": "jsx"
},
"prettier.arrowParens": "always",
"editor.fontLigatures": true,
"workbench.activityBar.visible": true,
"workbench.preferredDarkColorTheme": "One Dark Pro",
"oneDarkPro.bold": true,
"oneDarkPro.editorTheme": "Onedark Pro",
"oneDarkPro.vivid": true,
"workbench.preferredHighContrastColorTheme": "One Dark Pro",
"workbench.preferredLightColorTheme": "One Dark Pro",
"workbench.colorTheme": "One Dark Pro",
"editor.fontFamily": "Fira Code, Fira Code iScript, Consolas, 'Courier New', monospace",
"gitlens.advanced.messages": {
"suppressCommitHasNoPreviousCommitWarning": true
},
"eslint.workingDirectories": [{ "mode": "auto" }],
"prettier.trailingComma": "es5",
"autoimport.filesToScan": "**/*.{jsx,js,ts,tsx}",
"autoimport.doubleQuotes": true,
"autoimport.showNotifications": true,
"explorer.compactFolders": false,
"eslint.codeAction.showDocumentation": {
"enable": true
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"typescript.tsdk": "",
"path-intellisense.mappings": {},
"relativePath.excludedExtensions": [".js"],
"typescript.updateImportsOnFileMove.enabled": "always",
"typescript.preferences.includePackageJsonAutoImports": "on",
"prettier.useTabs": true,
"editor.codeActionsOnSave": {
"source.addMissingImports": true
// "source.fixAll.eslint": true
// "source.organizeImports": true
},
"editor.snippetSuggestions": "top"
}
Please create a new jsconfig.json file in the root of your app, with:
{
"compilerOptions": {
"baseUrl": "./src",
"checkJs": true,
"jsx": "react"
}
}
and then try it with:
import React from 'react'
const Component = () => {
const [test] = useState(0)
return <div>{test}</div>
}
export default Component

How to set indent and formatting behavior for each language in visual studio code?

Is there a way to make vscode format python files using 4 spaces while formatting files from other languages such JS, Typescript and HTML using 2 spaces only?
It`s pretty annoying to have to indent manually every time.
All of this trying is setting up a mess on my settings and still, I can`t make it work as I want.
This is what my settings.json looks like for the moment
{
"python.jediEnabled": false,
"miramac.node.terminalMode": false,
"python.pythonPath": "/usr/local/bin/python3",
"workbench.colorTheme": "Dracula",
"workbench.startupEditor": "newUntitledFile",
"workbench.editor.labelFormat": "short",
"terminal.integrated.fontSize": 12,
"editor.fontFamily": "Fira Code",
"editor.lineHeight": 19,
"editor.fontLigatures":true,
"editor.suggestSelection": "first",
"editor.renderLineHighlight": "gutter",
"editor.detectIndentation": true,
"editor.insertSpaces": false,
"editor.tabSize": 2,
"editor.autoIndent": "full",
"eslint.alwaysShowStatus": true,
"eslint.debug": true,
"eslint.format.enable": true,
"eslint.options": {
},
"python.languageServer": "Microsoft",
"liveServer.settings.donotVerifyTags": true,
"[html]": {
"editor.tabSize": 2,
"editor.codeActionsOnSave": {
"source.fixAll": true,
},
},
"liveServer.settings.donotShowInfoMsg": true,
"prettier.tabWidth": 2,
"[javascript]":{
"editor.codeActionsOnSave": {
"source.fixAll": true,
}
},
"[javascriptreact]":{
"editor.codeActionsOnSave": {
"source.fixAll": true,
}
},
"[typescript]":{
"editor.codeActionsOnSave": {
"source.fixAll": true,
},
"editor.defaultFormatter": "rvest.vs-code-prettier-eslint"
},
"[typescriptreact]":{
"editor.codeActionsOnSave": {
"source.fixAll": true,
},
"editor.defaultFormatter": "rvest.vs-code-prettier-eslint"
},
"[python]": {
"editor.tabSize": 4,
"editor.codeActionsOnSave": {
// "source.fixAll": true,
},
},
"extensions.ignoreRecommendations": true,
"explorer.compactFolders": false,
//perguntar se vc confirma delete e drag and drops
"explorer.confirmDragAndDrop": false,
"explorer.confirmDelete": false,
//mostra o caminho completo do arquivo
"breadcrumbs.enabled": true,
"javascript.updateImportsOnFileMove.enabled": "never",
"typescript.updateImportsOnFileMove.enabled": "never",
"python.linting.pylintArgs": [
"--extension-pkg-whitelist=pygame"
],
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
//set zsh theme to my terminal
//"terminal.integrated.shell.osx": "/bin/bash",
"terminal.integrated.shell.osx": "/bin/bash",
//"terminal.integrated.cwd": "",
"editor.renderControlCharacters": false,
"window.zoomLevel": -1,
"git.path": "/usr/local/git/bin/git",
"gitlens.views.repositories.files.layout": "list",
"gitlens.views.compare.files.layout": "tree",
"emmet.syntaxProfiles": {"javascript": "jsx"},
"emmet.includeLanguages": {"javascript": "javascriptreact"},
"typescript.tsserver.log": "verbose",
"javascript.suggest.autoImports": true,
"git.enableCommitSigning": true,
"git.enableSmartCommit": true,
"git.rebaseWhenSync": true,
"git.showPushSuccessNotification": true,
"workbench.sideBar.location": "left",
"workbench.activityBar.visible": true,
"terminal.integrated.automationShell.osx": "",
// "editor.defaultFormatter": "vscode.python",
// "editor.tokenColorCustomizationsExperimental": {},
"workbench.preferredDarkColorTheme": "Dracula",
"workbench.preferredHighContrastColorTheme": "Visual Studio Dark",
"material-icon-theme.activeIconPack": "nest",
"workbench.iconTheme": "material-icon-theme",
"material-icon-theme.folders.associations": {
"infra": "app",
"entities": "class",
"schemas": "class",
"typeorm": "database",
"repositories": "mappings",
"http": "container",
"migrations": "tools",
"modules": "components",
"implementations": "core",
"dtos": "typescript",
"fakes": "mock",
"coverage_reports": "tools",
},
"material-icon-theme.files.associations": {
"ormconfig.json": "database",
"routes.tsx": "routing",
"routes.ts": "routing",
"*.html": "html",
},
"sqlite.databaseExtensions": [
"db",
"db3",
"sdb",
"s3db",
"sqlite",
"sqlite3",
"ts"
],
}
Would there be anyone who can help in this issue?
I believe option + control + "B" should work
It is also a right click on the document and you should see a "format document" option.
It works for me