admin管理员组文章数量:1290095
On save of any file, it is indenting with two tabs i.e 4 space in the beginning. Which rule is conflicting with prettier
and .vscode
settings?
Editor config settings are below:
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
max_line_length = 120
Trying to indent with 2 space, this is happening only
with json files and other scripts.
vscode settings
{
"[javascript]": {
"editor.formatOnSave": false
},
"eslint.alwaysShowStatus": true,
"files.autoSave": "onFocusChange",
"prettier.proseWrap": "preserve",
"emmet.includeLanguages": {
"javascript": "javascriptreact",
"vue-html": "html",
"plaintext": "jade",
"edge": "html"
},
"emmet.syntaxProfiles": {
"javascript": "jsx"
},
"emmet.triggerExpansionOnTab": true,
"emmet.showSuggestionsAsSnippets": true,
"files.associations": {
"*.js": "javascriptreact"
},
"editor.fontSize": 14,
"git.enableSmartCommit": true,
"git.confirmSync": false,
"search.exclude": {
"**/__snapshots__/**": true,
"**/.bin": true,
"**/.git": true,
"**/.next": true,
"**/bower_ponents": true,
"**/coverage/**": true,
"**/node_modules": false,
"**/node_modules/**": true,
"**/report/**": true,
"**/tmp": true
},
"javascript.updateImportsOnFileMove.enabled": "always",
"explorer.confirmDragAndDrop": false,
"explorer.confirmDelete": false,
"workbench.editor.enablePreviewFromQuickOpen": false,
"files.exclude": {
".next": true,
"*.log": true,
"**/__pycache__": true,
"**/o": true,
"dist": true,
"geckodriver.log": true,
"node_modules/": true,
"package-lock.json": true,
"yarn.lock": true
},
"window.zoomLevel": 1,
"editor.find.globalFindClipboard": true,
"editor.fontLigatures": true,
"jshint.enable": false,
"editor.formatOnType": true,
"team.showWeleMessage": false,
"git.autofetch": true,
"workbench.startupEditor": "newUntitledFile",
"editor.codeActionsOnSave": {
// For ESLint
"source.fixAll.eslint": true,
// For TSLint
"source.fixAll.tslint": true,
// For Stylelint
"source.fixAll.stylelint": true
},
"launch": {},
"workbench.colorCustomizations": {},
"sync.forceUpload": true,
"sync.forceDownload": true,
"sync.autoDownload": true,
"vetur.format.defaultFormatter.html": "js-beautify-html",
"intelephense.diagnostics.undefinedTypes": false,
"workbench.editorAssociations": [],
"diffEditor.codeLens": true,
"editor.formatOnSave": true,
"team.showFarewellMessage": false,
"eslint.validate": [],
"vetur.validation.template": false,
"prettier.enable": true,
"editor.formatOnPaste": true,
"editor.tabSize": 2,
"files.insertFinalNewline": true,
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.tabSize": 2
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.tabSize": 2
},
"editor.tokenColorCustomizations": null
}
On save of any file, it is indenting with two tabs i.e 4 space in the beginning. Which rule is conflicting with prettier
and .vscode
settings?
Editor config settings are below:
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
max_line_length = 120
Trying to indent with 2 space, this is happening only
with json files and other scripts.
vscode settings
{
"[javascript]": {
"editor.formatOnSave": false
},
"eslint.alwaysShowStatus": true,
"files.autoSave": "onFocusChange",
"prettier.proseWrap": "preserve",
"emmet.includeLanguages": {
"javascript": "javascriptreact",
"vue-html": "html",
"plaintext": "jade",
"edge": "html"
},
"emmet.syntaxProfiles": {
"javascript": "jsx"
},
"emmet.triggerExpansionOnTab": true,
"emmet.showSuggestionsAsSnippets": true,
"files.associations": {
"*.js": "javascriptreact"
},
"editor.fontSize": 14,
"git.enableSmartCommit": true,
"git.confirmSync": false,
"search.exclude": {
"**/__snapshots__/**": true,
"**/.bin": true,
"**/.git": true,
"**/.next": true,
"**/bower_ponents": true,
"**/coverage/**": true,
"**/node_modules": false,
"**/node_modules/**": true,
"**/report/**": true,
"**/tmp": true
},
"javascript.updateImportsOnFileMove.enabled": "always",
"explorer.confirmDragAndDrop": false,
"explorer.confirmDelete": false,
"workbench.editor.enablePreviewFromQuickOpen": false,
"files.exclude": {
".next": true,
"*.log": true,
"**/__pycache__": true,
"**/o": true,
"dist": true,
"geckodriver.log": true,
"node_modules/": true,
"package-lock.json": true,
"yarn.lock": true
},
"window.zoomLevel": 1,
"editor.find.globalFindClipboard": true,
"editor.fontLigatures": true,
"jshint.enable": false,
"editor.formatOnType": true,
"team.showWeleMessage": false,
"git.autofetch": true,
"workbench.startupEditor": "newUntitledFile",
"editor.codeActionsOnSave": {
// For ESLint
"source.fixAll.eslint": true,
// For TSLint
"source.fixAll.tslint": true,
// For Stylelint
"source.fixAll.stylelint": true
},
"launch": {},
"workbench.colorCustomizations": {},
"sync.forceUpload": true,
"sync.forceDownload": true,
"sync.autoDownload": true,
"vetur.format.defaultFormatter.html": "js-beautify-html",
"intelephense.diagnostics.undefinedTypes": false,
"workbench.editorAssociations": [],
"diffEditor.codeLens": true,
"editor.formatOnSave": true,
"team.showFarewellMessage": false,
"eslint.validate": [],
"vetur.validation.template": false,
"prettier.enable": true,
"editor.formatOnPaste": true,
"editor.tabSize": 2,
"files.insertFinalNewline": true,
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.tabSize": 2
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.tabSize": 2
},
"editor.tokenColorCustomizations": null
}
Share
Improve this question
edited Jan 29, 2021 at 9:22
Mithun Shreevatsa
asked Jan 29, 2021 at 5:51
Mithun ShreevatsaMithun Shreevatsa
3,62910 gold badges58 silver badges104 bronze badges
2
- check vscode setting -> monly userd-> Editor: Tab Size – Ravi Ashara Commented Jan 29, 2021 at 6:00
- It is configured as 2 space per tab – Mithun Shreevatsa Commented Jan 29, 2021 at 6:32
4 Answers
Reset to default 4This was due to an extension: 'lonefy.vscode-js-css-html-formatter'.
You can add this rules for json files in your settings.json:
{
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.tabSize": 2
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.tabSize": 2
}
}
And to be explicit, you can also add this one outside of the [json] block:
{
"prettier.tabWidth": 2
}
just add this line in your .prettierrc file, here written in yaml style
overrides:
- files: '*.json'
options:
semi: true
parser: 'json'
That's all folk's !
In my case, it was a .prettierrc.js file, so I removed the js and changed it to a .prettierrc
file, and it worked fine.
本文标签: javascriptPrettier vscode json file indentation spacing issueStack Overflow
版权声明:本文标题:javascript - Prettier vscode json file indentation spacing issue - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741491823a2381655.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论