Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: wxs标签内的代码格式化不对 #171

Open
lihanspace opened this issue Jul 27, 2023 · 2 comments
Open

[Bug]: wxs标签内的代码格式化不对 #171

lihanspace opened this issue Jul 27, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@lihanspace
Copy link

lihanspace commented Jul 27, 2023

如何复现:

步骤1:

// setting.json
"minapp-vscode.wxmlFormatter": "prettier",
"minapp-vscode.prettier": {
  "parser": "html",
  "useTabs": false,
  "tabWidth": 2,
  "printWidth": 160,
  "singleQuote": false,
  "bracketSameLine": true,
  "jsxBracketSameLine": true,
  "bracketSpacing": false
}
// .prettierc
{
  "semi": false,
  "singleQuote": true,
  "quoteProps": "as-needed",
  "jsxSingleQuote": false,
  "trailingComma": "es5",
  "bracketSpacing": true,
  "bracketSameLine": false,
  "arrowParens": "always",
  "overrides": [
    {
      "files": ["*.wxml"],
      "options": {
        "semi": true,
        "singleQuote": false,
        "bracketSameLine": true,
        "bracketSpacing": false
      }
    },
    {
      "files": ["*.wxss", "*.scss", "*.sass"],
      "options": {
        "semi": true,
        "singleQuote": false
      }
    }
  ]
}

步骤2:

<!-- index.wxml -->
<wxs module="timeFormat">
  function timeFormat(time) {
    if (time !== undefined) {
      var timeNum = getDate(time)
      var y = timeNum.getFullYear()
      var M = timeNum.getMonth() + 1
      var d = timeNum.getDate()
      var h = timeNum.getHours() + ''
      var m = timeNum.getMinutes() + ''
      if (h.length === 1) { h = '0' + h }
      if (m.length === 1) { m = '0' + m }
      return y + '年' + M + '月' + d + '日 ' + h + ':' + m
    }
  }
  module.exports = timeFormat
</wxs>
<view></view>

步骤3:
格式化

期望的表现:

<!-- index.wxml -->
<wxs module="timeFormat">
  function timeFormat(time) {
    if (time !== undefined) {
      var timeNum = getDate(time)
      var y = timeNum.getFullYear()
      var M = timeNum.getMonth() + 1
      var d = timeNum.getDate()
      var h = timeNum.getHours() + ''
      var m = timeNum.getMinutes() + ''
      if (h.length === 1) {
        h = '0' + h
      }
      if (m.length === 1) {
        m = '0' + m
      }
      return y + '年' + M + '月' + d + '日 ' + h + ':' + m
    }
  }
  module.exports = timeFormat
</wxs>
<view></view>

实际的表现:

<!-- index.wxml -->
<wxs module="timeFormat">
  function timeFormat(time) { if (time !== undefined) { var timeNum = getDate(time) var y = timeNum.getFullYear() var M = timeNum.getMonth() + 1 var d =
  timeNum.getDate() var h = timeNum.getHours() + '' var m = timeNum.getMinutes() + '' if (h.length === 1) { h = '0' + h } if (m.length === 1) { m = '0' + m }
  return y + '年' + M + '月' + d + '日 ' + h + ':' + m } } module.exports = timeFormat
</wxs>
<view></view>

gif

插件运行环境

  • 插件版本: v2.4.12
  • VSCode版本: v1.80.1
  • 操作系统(非必须): win10

是否可以把wxs标签当做script标签进行格式化?

@lihanspace lihanspace added the bug Something isn't working label Jul 27, 2023
@luckymore
Copy link

试了下,是以 html 规则使用 prettier 格式化导致的,需要把 *.wxml 里脚本内容单独格式化然后拼装起来。

let me try

@wangzhipeng-vicky
Copy link

以 html 规则使用 prettier 格式化导致的,需要把 *.wxml 里脚本内容单独格式化然后拼装起来。

我设置了这个也不行
"minapp-vscode.disableDecorate": false, "minapp-vscode.decorateType": { "color": "#27b89a" }, "minapp-vscode.wxmlFormatter": "prettier", // 指定格式化工具 "minapp-vscode.prettier": { // prettier 更多参考 https://prettier.io/docs/en/options.html "useTabs": false, "tabWidth": 2, "printWidth": 100, "singleQuote": false }, "[wxml]": { "editor.defaultFormatter": "qiu8310.minapp-vscode" },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants