From 61278ebc6fc7e43b8e7c610266a481bf2f9c0a6a Mon Sep 17 00:00:00 2001 From: suxiang <651029594@qq.com> Date: Tue, 14 Jun 2022 16:33:49 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=94=B9=E8=BF=9B=EF=BC=9A=E5=BD=93break?= =?UTF-8?q?=5Fattr=5Flimit=E5=A4=A7=E4=BA=8E-1=E6=97=B6=EF=BC=8C=E6=8A=98?= =?UTF-8?q?=E6=88=90=20=E5=B1=9E=E6=80=A7=E6=95=B0/break=5Fattr=5Flimit=20?= =?UTF-8?q?=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 ++-- src/js-beautify.conf.js | 2 +- src/plugins.js | 8 +++++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index ea0125b..3e51119 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vue-format", "displayName": "vue-format", "description": "A beautify extension for .vue file", - "version": "0.1.8", + "version": "0.1.9", "publisher": "febean", "keyword": "vue vscode format js-beautify extension", "engines": { @@ -41,7 +41,7 @@ }, "vue-format.break_attr_limit": { "type": "number", - "default": -1, + "default": 5, "description": "Break attributes when tag's attributes.length > this number, no break when -1. (tag 的 attrs 大于该数值时,强制 attrs 换行,-1时不换行)" }, "vue-format.attr_end_with_gt": { diff --git a/src/js-beautify.conf.js b/src/js-beautify.conf.js index c369ebb..139773a 100644 --- a/src/js-beautify.conf.js +++ b/src/js-beautify.conf.js @@ -1,6 +1,6 @@ module.exports = { "html_indent_root": false, - "break_attr_limit": -1, + "break_attr_limit": 5, "attr_end_with_gt": true, "format_need": ["html", "js", "css"], "js-beautify": { diff --git a/src/plugins.js b/src/plugins.js index c6757e6..84f8a13 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -50,8 +50,14 @@ function breakTagAttr(str = '', breakLimitNum = 1, opt = { // console.log(matchRes); if (matchRes.length > breakLimitNum) { // 一个属性强制断行,或者多属性 // 每个 attr 先 trim,然后加换行,空格 + let index=0; let newStr = tagContent.replace(ATTR_REG, (match, $1) => { - return '\n' + indent + padIndent + $1.trim(); + index++; + if(index % breakLimitNum == 0) { + return '\n' + indent + padIndent + $1.trim(); + } else { + return ' ' + $1.trim(); + } }); // tag 结束括号换行 newStr = attrEndWithGt ? newStr : newStr.replace(TAG_CLOSE_REG, '\n' + indent + '$1'); From 13f2728c3dc561d6a596fed8187fd291ec430c75 Mon Sep 17 00:00:00 2001 From: suxiang <651029594@qq.com> Date: Tue, 14 Jun 2022 17:37:25 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/plugins.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 3e51119..60e86d0 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vue-format", "displayName": "vue-format", "description": "A beautify extension for .vue file", - "version": "0.1.9", + "version": "0.1.10", "publisher": "febean", "keyword": "vue vscode format js-beautify extension", "engines": { diff --git a/src/plugins.js b/src/plugins.js index 84f8a13..f0b674c 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -50,10 +50,10 @@ function breakTagAttr(str = '', breakLimitNum = 1, opt = { // console.log(matchRes); if (matchRes.length > breakLimitNum) { // 一个属性强制断行,或者多属性 // 每个 attr 先 trim,然后加换行,空格 - let index=0; + let index = -1; let newStr = tagContent.replace(ATTR_REG, (match, $1) => { index++; - if(index % breakLimitNum == 0) { + if(index > 0 && index % breakLimitNum == 0) { return '\n' + indent + padIndent + $1.trim(); } else { return ' ' + $1.trim();