VSCode Add All Missing imports Not Working - visual-studio-code

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

Related

Prettier autosaving (esbenp.prettier-vscode) conflict with prettier/prettier rule

I want to use ESLint along with Prettier. Everything is fine except when I press Ctrl + S to save the file, Prettier changes file in a way which is not compatible with prettier/prettier rule in ESLint.
Content of .vscode/settings.json:
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"prettier.singleQuote": true,
"prettier.printWidth": 70,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"eslint.alwaysShowStatus": true,
"eslint.codeAction.showDocumentation": {
"enable": true
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.validate": ["javascript"]
}
Content of .eslint.json:
{
"env": {
"browser": true,
"es2021": true
},
"extends": ["google", "prettier"],
"parser": "#typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["#typescript-eslint", "prettier"],
"rules": {
"prettier/prettier": ["error"]
}
}
I know if I remove "editor.formatOnSave": true, from settings.json all of problems get resolved but I don't like the saved format because lines of code are too long and I like to break long line into multiple line.
The problem is that Prettier is using printWidth of 70 characters but ESlint have a max-len of 80 characters.
You should modify one of them to keep them sync, e.g. you can change printWidth inside settings.json to make Prettier compatible with ESlint("prettier.printWidth": 80).
Content of ./vscode/settings.json:
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"prettier.singleQuote": true,
"prettier.printWidth": 80,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"eslint.alwaysShowStatus": true,
"eslint.codeAction.showDocumentation": {
"enable": true
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.validate": ["javascript"]
}

Unable to write in VScode settings

It seems i am unable to write in any new setting as my settings.json has an error of some kind. I have tried removing certain duplicate lines and also adding new brackets to see if it would assist with the issue but so far i have not been able to figure out the problem. Here is what i have managed to do so far,
{
"editor.suggest.localityBonus": true,
"editor.suggest.statusBar.visible": true,
"editor.quickSuggestions": null,
"editor.snippetSuggestions": "bottom",
"files.autoSave": "afterDelay",
"liveServer.settings.donotShowInfoMsg": true,
"workbench.iconTheme": "material-icon-theme",
"prettier.jsxSingleQuote": true,
"prettier.singleQuote": true,
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
"workbench.colorTheme": "Monokai Pro (Filter Spectrum)",
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"emmet.preferences": {
},
"workbench.editorAssociations": {
"*.ipynb": "jupyter.notebook.ipynb"
},
"mssql.connections": [
{
"server": "{{put-server-name-here}}",
"database": "{{put-database-name-here}}",
"user": "{{put-username-here}}",
"password": "{{put-password-here}}"
}
],
"security.workspace.trust.untrustedFiles": "open",
"editor.fontSize": 18,
"editor.tabSize": 3,
"editor.guides.bracketPairs": true
{
"editor.bracketPairColorization.enabled": true,
"editor.guides.bracketPairs":"active"
}
}
I get an error saying "expected comma Ln33 col 3" and "end of file expected at Ln 37"
Change from:
"editor.guides.bracketPairs": true
{
"editor.bracketPairColorization.enabled": true,
"editor.guides.bracketPairs":"active"
}
to
"editor.guides.bracketPairs": true, // choose true/false/active
// { // gat rid of this {
"editor.bracketPairColorization.enabled": true,
// "editor.guides.bracketPairs":"active"
// } // get rid of this }

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

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>

In VS Code this line /** #format */ always appears at the top of my .js files on save

I'm a little confused as to why this line :
/** #format */
Always appears at the top of my .js files when i save. I have prettier globally installed as well as the prettier extension installed in vs code, I have it configured to auto format on save as well. I can't find any info on how to make that line go away or what caused it to start showing up in the first place.
Here is what my settings.json file looks like in vs code:
{
"editor.tabSize": 2,
"editor.insertSpaces": true,
"files.trimTrailingWhitespace": true,
"materialTheme.fixIconsRunning": false,
"workbench.colorTheme": "Winter is Coming (Dark Blue)",
"explorer.confirmDragAndDrop": false,
"explorer.confirmDelete": false,
"workbench.iconTheme": "material-icon-theme",
"files.autoSave": "off",
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
"[jsx]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
"[tsx]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
"[prisma]": {
"editor.defaultFormatter": "Prisma.prisma",
"editor.formatOnSave": true
},
"diffEditor.ignoreTrimWhitespace": true,
"liveshare.featureSet": "insiders",
"material-icon-theme.activeIconPack": "react",
"material-icon-theme.files.associations": {},
"workbench.startupEditor": "newUntitledFile",
"editor.snippetSuggestions": "bottom",
// "editor.quickSuggestions": null
"editor.quickSuggestionsDelay": 500,
"prettier.jsxSingleQuote": true,
"prettier.singleQuote": true,
"mssql.connections": [
{
"server": "{{put-server-name-here}}",
"database": "{{put-database-name-here}}",
"user": "{{put-username-here}}",
"password": "{{put-password-here}}"
}
],
"window.zoomLevel": -2,
"cSpell.userWords": [
"Signup",
"formik"
],
"prettier.insertPragma": true,
"settingsSync.ignoredExtensions": [
"esbenp.prettier-vscode"
]
}
For anyone running into the same issue, in the settings.json file, I changed this:
"prettier.insertPragma": true,
to false
"prettier.insertPragma": false,
that resolves the issue.

how to format js code in vscode

my settings.json
"editor.wordWrap": "off",
the setting can to display a single line in .vue file
but doesn't work in .js file when i format js code
import {
Message
} from 'element-ui'
import {
getLoginInfo,
getDeviceId,
deleteEmptyObjParam
} from 'util'
my expected result is
import {getLoginInfo, getDeviceId, deleteEmptyObjParam} from 'util'
how can I configure it?
my vscode version
1.23.0 (1.23.0)
full settings.json
{
"explorer.confirmDragAndDrop": true,
"files.associations": {
"*.vue": "vue"
},
"editor.wordSeparators": "`~!##$%^&*()=+[{]}\\|;:'\",.<>/?",
"workbench.iconTheme": "material-icon-theme",
"vsicons.presets.jsOfficial": true,
"vsicons.presets.tsOfficial": true,
"window.zoomLevel": 0,
"prettier.singleQuote": true,
"prettier.semi": false,
"editor.tabSize": 2,
"vetur.format.defaultFormatter.html": "js-beautify-html",
"vetur.format.defaultFormatterOptions": {
"wrap_attributes": "force-aligned"
},
"editor.wordWrap": "off",
"editor.formatOnPaste": false,
"editor.formatOnSave": false,
"editor.formatOnType": false,
"workbench.colorTheme": "Atom One Dark",
}