aswinkumar863 / smarty-vscode-support

Smarty template support extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=aswinkumar863.smarty-template-support
MIT License
107 stars 11 forks source link

Extra whitespace is added in nested double quote #9

Closed tanigaki39 closed 4 years ago

tanigaki39 commented 4 years ago

Attempt code for format

<div class="foo{if $bar=="1"} bar{/if}">foo</div>

Result

<div class="foo{if $bar==" 1"} bar{/if}">foo</div>

Additional info

It works fine when use single quote in curly braces.

<div class="foo{if $bar=='1'} bar{/if}">foo</div>
Mordef commented 4 years ago

Looks like a Problem in js-beautify ( you can test here https://beautifier.io/ ) When i disable it (in formatter.js directly) it works fine.

tanigaki39 commented 4 years ago

@Mordef

Thanks for your information. I disabled js-beautify in formatter.js directly, but I still get the same result as I mentioned.

What I did is,

  1. clean install smarty-vscode-support
  2. Modify ~/.vscode/extensions/aswinkumar863.smarty-template-support-1.6.0/client/out/formatter.js
  3. Restart VSCode

Modded formatter.js

hoge

Extensions list

code --install-extension 8amjp.convertwidth
code --install-extension aaron-bond.better-comments
code --install-extension alefragnani.Bookmarks
code --install-extension amandeepmittal.pug
code --install-extension aswinkumar863.smarty-template-support
code --install-extension dbaeumer.vscode-eslint
code --install-extension donjayamanne.githistory
code --install-extension eamodio.gitlens
code --install-extension Gruntfuggly.todo-tree
code --install-extension mauve.terraform
code --install-extension mechatroner.rainbow-csv
code --install-extension mhutchie.git-graph
code --install-extension mkaufman.HTMLHint
code --install-extension mrmlnc.vscode-puglint
code --install-extension ms-azuretools.vscode-docker
code --install-extension ms-mssql.mssql
code --install-extension ms-vsliveshare.vsliveshare
code --install-extension octref.vetur
code --install-extension OfHumanBondage.react-proptypes-intellisense
code --install-extension ritwickdey.LiveServer
code --install-extension shd101wyy.markdown-preview-enhanced
code --install-extension stylelint.vscode-stylelint
code --install-extension vscodevim.vim

setting.json

{
  "html.format.enable": false,
  "files.insertFinalNewline": true,
  "editor.fontSize": 11,
  "editor.tabSize": 2,
  "editor.renderWhitespace": "all",
  "editor.formatOnType": false,
  "editor.wordWrap": "on",
  "editor.minimap.enabled": false,
  "editor.fontFamily": "SourceHanCodeJP-Regular, Source Han Code JP, Menlo, Monaco, 'Courier New', monospace",
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  },
  "editor.formatOnSave": false,
  "editor.trimAutoWhitespace": true,
  "emmet.showSuggestionsAsSnippets": true,
  "emmet.includeLanguages": {
    "smarty": "html"
  },
  "terminal.integrated.fontSize": 11,
  "terminal.integrated.fontFamily": "monospace",
  "terminal.integrated.lineHeight": 1.25,
  "terminal.integrated.fontWeight": "bold",
  "typescript.updateImportsOnFileMove.enabled": "never",
  "git.autofetch": true,
  "vim.easymotion": true,
  "vim.useSystemClipboard": true,
  "vim.hlsearch": true,
  "vim.visualstar": true,
  "vim.useCtrlKeys": true,
  "vim.surround": true,
  "debug.console.fontSize": 14,
  "eslint.options": {
    "configFile": ".eslintrc.js"
  },
  "eslint.autoFixOnSave": true,
  "liveServer.settings.root": "/dist",
  "eslint.alwaysShowStatus": true,
  "eslint.packageManager": "yarn",
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    {
      "language": "typescript",
      "autoFix": true
    },
    {
      "language": "typescriptreact",
      "autoFix": true
    }
  ],
  "puglint.enable": true,
  "puglint.config": {
    "extends": "clock"
  },
  "javascript.updateImportsOnFileMove.enabled": "never",
  "eslint.lintTask.enable": true,
  "terraform.indexing": {
    "enabled": true,
    "liveIndexing": false,
    "delay": 500,
    "exclude": [
      ".terraform/**/*",
      "**/.terraform/**/*"
    ]
  },
  "terraform.languageServer": {
    "enabled": false,
    "args": []
  },
  "liveServer.settings.donotVerifyTags": true,
  "liveServer.settings.donotShowInfoMsg": true,
  "html.mirrorCursorOnMatchingTag": false,
  "[json]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "window.zoomLevel": 0,
  "todo-tree.highlights.enabled": true,
  "todo-tree.tree.showScanModeButton": false,
  "bookmarks.navigateThroughAllFiles": true,
}
Mordef commented 4 years ago

Take a look in #8 and test again with that changes. When i have time i'll try make a PR

aswinkumar863 commented 4 years ago

Looks like a Problem in js-beautify ( you can test here https://beautifier.io/ ) When i disable it (in formatter.js directly) it works fine.

@Mordef This comment is misleading.

Disabling the js-beautify will not be a fix to this issue. Let me clear the cause of this issue.

<div class="foo{if $bar=="1"} bar{/if}">foo</div>

Here the HTML formatter doesn't aware of smarty literals and closes the class attribute at double quote (class="foo{if $bar=="). So it also adds the extra space before 1"} and makes this as another attribute.

Even after disabling the js-beautify the issue occurs. And there is no problem with js-beautify, it does HTML formatting very well. It doesn't deal with smarty (other formatters too).

Also, this is not related to #8.

Mordef commented 4 years ago

Im sorry, looks like it only works with the changes in #8 and disable beautify.