How to disable vscode auto format adding newline at EOF when auto save js files? - visual-studio-code

I am using vscode and enabled the auto-format config to format files when saving files.
But i recently found that vscode editor always add a newline at EOF of each js file,so how to disable this?
I have specially added the config "files.insertFinalNewline": false, but it still not worked.
vscode info:
Version: 1.33.1 (system setup)
Commit: 51b0b28134d51361cf996d2f0a1c698247aeabd8
Date: 2019-04-11T08:27:14.102Z
Electron: 3.1.6
Chrome: 66.0.3359.181
Node.js: 10.2.0
V8: 6.6.346.32
OS: Windows_NT x64 6.1.7601
vscode config.json
{
"workbench.colorTheme": "Monokai",
"editor.fontSize": 16,
"editor.formatOnPaste": true,
// Format a file on save.
// A formatter must be available,
// the file must not be auto-saved,
// and editor must not be shutting down.
"editor.formatOnSave": true,
"debug.console.fontSize": 16,
"terminal.integrated.fontSize": 14,
"markdown.preview.fontSize": 14,
"window.zoomLevel": 1,
"editor.renderWhitespace": "all",
"window.title": "${dirty}${activeEditorLong}${separator}${rootName}${separator}${appName}",
"search.exclude": {
"**/.gitignore": true,
"**/.idea": true,
"**/.vscode": true,
"**/build": true,
"**/dist": true,
"**/tmp": true,
"**/yarn.lock": true
},
"workbench.iconTheme": "material-icon-theme",
"editor.wordWrapColumn": 110,
"http.proxyStrictSSL": false,
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": false,
"files.trimFinalNewlines": false,
"html.format.endWithNewline": false,
"javascript.implicitProjectConfig.experimentalDecorators": true,
// Enable/disable default JavaScript formatter (For Prettier)
"javascript.format.enable": false,
// Use 'prettier-eslint' instead of 'prettier'.
// Other settings will only be fallbacks
// in case they could not be inferred from eslint rules.
"prettier.eslintIntegration": true,
"prettier.tabWidth": 4,
"prettier.singleQuote": true,
"prettier.arrowParens": "always"
}
.eslintrc.json
{
"extends": "airbnb",
"plugins": [
"react",
"jsx-a11y",
"import",
"react-hooks"
],
"parserOptions": {
"sourceType": "module",
"ecmaFeatures": {
"legacyDecorators": true,
"experimentalObjectRestSpread": true
}
},
"env": {
"browser": true,
"es6": true
},
"parser": "babel-eslint",
"globals": {
"describe": true,
"it": true,
"inject": true,
"beforeEach": true,
"addProviders": true,
"spyOn": true,
"expect": true,
"global": true,
"require": true,
"async": true,
"ENVIRONMENT": true,
"client": true
},
"rules": {
"linebreak-style": 0,
"quotes": [2, "single", {
"avoidEscape": true,
"allowTemplateLiterals": true
}],
"indent": [2, 4, {
"SwitchCase": 1,
"VariableDeclarator": 1
}],
"react/jsx-indent": [2, 4],
"comma-dangle": ["error", "never"],
"class-methods-use-this": 0,
"import/newline-after-import": 0,
"space-before-function-paren": ["error", "never"],
"func-names": ["error", "never"],
"consistent-return": [0],
"eol-last": ["error", "never"],
"no-script-url": ["off"],
"react/jsx-indent-props": [2, 4],
"react/forbid-prop-types": [2, {
"forbid": []
}],
"jsx-a11y/anchor-is-valid": ["error", {
"components": ["Link"],
"specialLink": ["to"],
"aspects": ["noHref"]
}],
"jsx-a11y/href-no-hash": "off",
"jsx-a11y/no-static-element-interactions": "off",
"jsx-a11y/click-events-have-key-events": "off",
"import/no-unresolved": [
"error",
{
"ignore": ["client/"]
}
],
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": true
}
],
"import/extensions": 0,
"max-len": [
0, 110, 4
],
"react/jsx-filename-extension": [
1,
{
"extensions": [
".js",
".jsx"
]
}
],
"react-hooks/rules-of-hooks": "error"
},
"settings": {
"import/resolver": {
"node": {
"extensions": [".js", ".jsx", ".json", ".css"]
}
}
}
}
So, how to config vscode correctly?

I had the same problem. To fix it you need to be in the folder of your project. then open your settings i.e command + shift + p, type settings, select Preferences: open settings UI, under Text Editor tab, choose Files and you'll find Eol tab to choose from \n, \n, auto. I choose auto so it will override whatever you specify.

Related

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>

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.

VSCode Python Intellisense Not Working Properly

Python autocomplete in VSCode is messing up my code
Here is my system:
If I use Pylance, Intellisense does not work properly
and if I use Jedi, Intellisense does not work properly
When I press enter, my code is completely borked. This is just one example and has been frustrating the heck out of me!
Below is my settings.json file:
{
"AREPL.pythonPath": "${workspaceFolder}\\.venv\\Scripts\\python.exe",
"dicom.alwaysShowMenu": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"editor.formatOnSave": true,
"editor.insertSpaces": false,
"editor.rulers": [
90
],
"editor.suggestSelection": "first",
"explorer.compactFolders": false,
"explorer.confirmDragAndDrop": false,
"files.exclude": {
"**/.git": false
},
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true,
"git-graph.defaultColumnVisibility": {
"Author": false,
"Commit": true,
"Date": false
},
"git-graph.referenceLabels.alignment": "Branches (aligned to the graph) & Tags (on the right)",
"glassit.alpha": 255,
"json.format.enable": true,
"mypy.dmypyExecutable": "${workspaceFolder}\\.venv\\Scripts\\dmypy.exe",
"mypy.runUsingActiveInterpreter": true,
"notebook.cellToolbarLocation": {
"default": "right",
"jupyter-notebook": "left"
},
"python.defaultInterpreterPath": "${workspaceFolder}\\.venv\\Scripts\\python.exe",
"python.formatting.blackArgs": [
"--line-length",
"90"
],
"python.formatting.provider": "black",
"python.languageServer": "Jedi",
"python.linting.enabled": true,
// "python.linting.flake8Args": [
// "--line-length",
// "90"
// ],
"python.linting.mypyEnabled": true,
"python.linting.mypyPath": "${workspaceFolder}\\.venv\\Scripts\\mypy.exe",
// "python.linting.pylintArgs": [
// "--generate-members"
// ],
// "python.linting.pylintEnabled": true,
"python.pythonPath": "${workspaceFolder}\\.venv\\Scripts\\python.exe",
"python.terminal.activateEnvironment": true,
"python.testing.pytestArgs": [
"${workspaceFolder}\\tests"
],
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": true,
"python.venvPath": ".venv",
"restructuredtext.builtDocumentationPath": "${workspaceFolder}\\docs\\build\\html",
"restructuredtext.confPath": "{workspaceFolder}\\docs\\source",
"restructuredtext.languageserver.disabled": true,
"restructuredtext.sphinxBuildPath": "${workspaceFolder}\\.venv\\Scripts\\sphinx-build.exe",
"screencastMode.keyboardOverlayTimeout": 1500,
"screencastMode.mouseIndicatorSize": 20,
"screencastMode.onlyKeyboardShortcuts": true,
"screencastMode.verticalOffset": 0,
"security.workspace.trust.untrustedFiles": "open",
"shellcheck.customargs": [
"-x"
],
"terminal.integrated.defaultProfile.windows": "PowerShell",
"terminal.integrated.fontFamily": "CaskaydiaCove Nerd Font Mono",
"terminal.integrated.tabs.enabled": true,
"trailing-spaces.syntaxIgnore": [
"markdown"
],
"update.enableWindowsBackgroundUpdates": false,
"vsicons.dontShowNewVersionMessage": true,
"workbench.colorTheme": "Predawn",
"workbench.editor.enablePreview": true,
"workbench.editorAssociations": {
"*.dcm": "default",
"*.ipynb": "jupyter-notebook",
"*.tiff": "tiff.preview",
"git-rebase-todo": "default"
},
"workbench.iconTheme": "material-icon-theme",
"workbench.settings.editor": "json",
"workbench.settings.openDefaultSettings": true,
"workbench.settings.useSplitJSON": true,
"workbench.startupEditor": "newUntitledFile"
}
Why is this happening and how can I fix my Intellisense?
Update:
Removing "editor.suggestSelection": "first" helped, but I still get errors:
Adding the following to my settings.json makes Intellisense work as expected:
"editor.acceptSuggestionOnEnter": "off",
"editor.tabCompletion": "on"
Why the defaults are "on" and "off", respectively, I will never know. Everyone expects to press tab if you want to use the suggestion (like in bash terminal), and no one wants the autocomplete to complete blindly upon hitting enter.

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

How do I remove the annoying underline in flycheck (using eslint)?

I am using spacemacs and flycheck-eslint as linter to check my React code.
Here is my project's .eslintrc,
{
"extends": [
"eslint:recommended",
"plugin:react/recommended"
],
"parser": "babel-eslint",
"env": {
"browser": true,
"es6": true,
"node": true
},
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"jsx": true
},
"sourceType": "module"
},
"plugins": [
"react"
],
"rules": {
"semi": [0, "never"],
"eqeqeq": 2,
"no-console": 1,
"no-unused-vars": [1, {"vars": "all", "args": "after-used"}],
"comma-spacing": [2, {"before": false, "after": true}],
"react/prop-types": [2, {
"ignore": ["dispatch"]
}]
},
"globals": {
"__DEV_MODE__": true,
"__API_SERVER__": true
}
}
I have set NO semicolon in the .eslintrc. I've try Atom Editor, Sublime Text3, VSCode, they work as expect.
But in spacemacs, I got the annoying underline hint.
How can I remove the annoying underline ??
Thanks!
After researching, I've found that it is not related to flycheck. The underline is added by js2-mode.
The solution is to add (setq js2-strict-missing-semi-warning nil) in .spacemacs file.