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

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.

Related

Prettier not working. Already set to default formatter

Getting this error:
Extension 'Prettier - Code formatter' is configured as formatter but it cannot format 'TypeScript React'-files
I've tried in all types of files including typescriptreact, javascriptreact, javascript, etc.
To be more specific, I am using ESLint with Prettier for a NextJS13 app. Below are my settings.json
"files.autoSave": "afterDelay",
"[php]": {
"editor.defaultFormatter": "bmewburn.vscode-intelephense-client"
},
"[erb]": {
"editor.defaultFormatter": "aliariff.vscode-erb-beautify"
},
"javascript.updateImportsOnFileMove.enabled": "always",
"git.autofetch": true,
"editor.fontSize": 16,
"eslint.format.enable": true,
"python.formatting.provider": "black",
"[python]": {
"editor.defaultFormatter": "ms-python.python"
},
"editor.fontFamily": "JetBrains Mono",
"editor.accessibilitySupport": "off",
"editor.defaultFormatter": "esbenp.prettier-vscode",
"workbench.iconTheme": "vscode-icons",
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"terminal.integrated.env.osx": {
"FIG_NEW_SESSION": "1"
},
"snyk.yesWelcomeNotification": false,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[ruby]": {
"editor.defaultFormatter": "rebornix.ruby"
},
"bracket-pair-colorizer-2.depreciation-notice": false,
"eslint.workingDirectories": [
"./react-client"
],

Troubleshooting VS Code 'settings.json'?

Hi guys I'm getting a message from VS Code that says "Unable to sync settings because the content in the file is not valid. Please open the file and correct it."
Why is it saying that and how could I fix it. I'm pasting my settings.json
{
"editor.fontSize": 16,
"editor.fontFamily": "Cascadia Code",
"editor.formatOnSave": true,
"terminal.integrated.fontSize": 16,
"terminal.integrated.fontWeight": 500,
"terminal.integrated.lineHeight": 1.1,
"prettier.tabWidth": 3,
"terminal.integrated.tabs.enableAnimation": false,
"workbench.iconTheme": "material-icon-theme",
"editor.guides.bracketPairs": true,
"editor.bracketPairColorization.independentColorPoolPerBracketType": true,
"workbench.colorCustomizations": {},
"editor.inlineSuggest.enabled": true,
"[html]": {
"editor.defaultFormatter": "vscode.html-language-features"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode", // worked!
"editor.defaultFormatter": "vscode.typescript-language-features" //Not worked?
}
"security.workspace.trust.untrustedFiles": "open", // expected comma error, but👈 has a comma. Where is the comma supposed to go?
"[css]": {
"editor.defaultFormatter": "aeschli.vscode-css-formatter"
},
"git.autofetch": true,
"editor.formatOnType": true,
"css.lint.emptyRules": "error",
"html-css-class-completion.enableEmmetSupport": true,
"editor.formatOnPaste": true,
"editor.defaultFormatter": "AndersEAndersen.html-class-suggestions",
"html.format.templating": true,
"emmet.triggerExpansionOnTab": true,
"workbench.colorTheme": "Brogrammer Plus",
"editor.fontWeight": "normal",
"eslint.codeActionsOnSave.rules": null
"editor.wordWrap" : "wordWrapColumn", // expected comma error, but👈 has a comma. Where is the comma supposed to go?
}
Where do the commas go for:
"editor.wordWrap" : "wordWrapColumn",
&
"security.workspace.trust.untrustedFiles": "open",
They 👆have commas?
You are missing some commas in the file.
Next time, you can verify that your settings.json file is valid by creating a new file in VSCode, setting its language to JSON (Select a language -> JSON) and pasting the content of your settings.json file - VSCode will mark any errors.
You were missing a comma after "eslint.codeActionsOnSave.rules": null and "editor.defaultFormatter": "vscode.typescript-language-features"}.
Here's a working version of your settings.json file, I checked it on my VSCode:
{
"editor.fontSize": 16,
"editor.fontFamily": "Cascadia Code",
"editor.formatOnSave": true,
"terminal.integrated.fontSize": 16,
"terminal.integrated.fontWeight": 500,
"terminal.integrated.lineHeight": 1.1,
"prettier.tabWidth": 3,
"terminal.integrated.tabs.enableAnimation": false,
"workbench.iconTheme": "material-icon-theme",
"editor.guides.bracketPairs": true,
"editor.bracketPairColorization.independentColorPoolPerBracketType": true,
"workbench.colorCustomizations": {},
"editor.inlineSuggest.enabled": true,
"[html]": {
"editor.defaultFormatter": "vscode.html-language-features"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.defaultFormatter": "vscode.typescript-language-features"
},
"security.workspace.trust.untrustedFiles": "open",
"[css]": {
"editor.defaultFormatter": "aeschli.vscode-css-formatter"
},
"git.autofetch": true,
"editor.formatOnType": true,
"css.lint.emptyRules": "error",
"html-css-class-completion.enableEmmetSupport": true,
"editor.formatOnPaste": true,
"editor.defaultFormatter": "AndersEAndersen.html-class-suggestions",
"html.format.templating": true,
"emmet.triggerExpansionOnTab": true,
"workbench.colorTheme": "Brogrammer Plus",
"editor.fontWeight": "normal",
"eslint.codeActionsOnSave.rules": null,
"editor.wordWrap": "wordWrapColumn"
}

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"]
}

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
}

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