//配置文档参考:<https://www.npmjs.com/package/js-beautify#options>
module.exports = {
parsers: {
".js": "js",
".json": "js",
".njs": "js",
".sjs": "js",
".wxs": "js",
".css": "css",
".nss": "css",
".wxss": "css",
".acss": "css",
".ttss": "css",
".qss": "css",
".html": "html",
".ux": "html",
".wxml": "html",
".nml": "html",
".vue": "html",
".nvue": "html",
".axml": "html",
".swan": "html",
".ttml": "html",
".qml": "html",
".md": "md",
},
options: {
"indent_size": 4,
"indent_char": "\\t",
"indent_with_tabs": false, //使用tab缩进
"eol": "\\r\\n", //行结束符
"end_with_newline": false, //使用换行结束输出
"indent_level": 0, //起始代码缩进数
"editorconfig": false,
"preserve_newlines": false, //保留空行
"max_preserve_newlines": 2, //最大连续保留换行符个数。比如设为2,则会将2行以上的空行删除为只保留1行
"space_in_paren": true, //括弧添加空格 示例 f( a, b )
"space_in_empty_paren": false, //函数的括弧内没有参数时插入空格 示例 f( )
"jslint_happy": false, //启用jslint-strict模式
"space_after_anon_function": false, //匿名函数的括号前加空格
"space_after_named_function": false,
"brace_style": "collapse", //代码样式,可选值 [collapse|expand|end-expand|none][,preserve-inline] [collapse,preserve-inline
"unindent_chained_methods": false, //不缩进链式方法调用
"break_chained_methods": false, //在随后的行中断开链式方法调用
"keep_array_indentation": false, //保持数组缩进
"unescape_strings": false, //使用xNN符号编码解码可显示的字符
"wrap_line_length": 120,
"e4x": false, //支持jsx
"comma_first": false, //把逗号放在新行开头,而不是结尾
"operator_position": "before-newline",
"unformatted": [ "wbr" ],
"html": {
"wrap-attributes": "auto", //自动包裹属性值
"wrap-attributes-indent-size": 1, //属性值缩进大小
"inline": undefined, //是否内联显示某些元素
"unformatted": undefined, //不需要格式化的部分。
"content_unformatted": undefined, //用于指定不需要格式化的内容。
"indent_handlebars": true, //缩进handlebars代码
"indent_inner_html": true, //指定是否缩进内部HTML代码
"indent-scripts": "keep", //[keep|separate|normal]脚本缩进方式(保持不变|分开|正常)
"extra_liners": [] //配置标签列表,需要在这些标签前面额外加一空白行
},
"css": {
"selector-separator-newline": true, //表示在选择器分隔符(比如逗号)后插入换行符
"newline-between-rules": false //表示在规则之间是否插入换行符
},
"typescript": {
// "convert_tabs_to_spaces":true,
"indent_multi_line_object_literal_beginning_on_blank_line": true, //跨越多行时在空行上开始缩进
"insert_space_after_comma_delimiter": true, //在逗号分隔符后插入空格
"insert_space_after_constructor": false, //在构造函数后插入空格
"insert_space_after_function_keyword_for_anonymous_functions": true, //对于匿名函数,在函数关键字后插入空格。
"insert_space_after_keywords_in_control_flow_statements": true, //在控制流语句中的关键字后插入空格
"insert_space_after_opening_and_before_closing_empty_braces": true, //在空括号的开头和结尾之间插入空格
"insert_space_after_opening_and_before_closing_jsx_expression_braces": false, //在JSX表达式的大括号的开头和结尾之间插入空格
"insert_space_after_opening_and_before_closing_nonempty_braces": true, //在非空括号的开头和结尾之间插入空格
"insert_space_after_opening_and_before_closing_nonempty_brackets": false, //在非空[方括号]的开头和结尾之间插入空格
"insert_space_after_opening_and_before_closing_nonempty_parenthesis": false, //在非空括号的开头和结尾之间插入空格
"insert_space_after_opening_and_before_closing_template_string_braces": false, //在模板字符串的大括号的开头和结尾之间插入空格
"insert_space_after_semicolon_in_for_statements": true, //在for语句中的分号后插入空格
"insert_space_after_type_assertion": false, //在类型断言后插入空格
"insert_space_before_and_after_binary_operators": true, //在二元操作符的前后插入空格
"insert_space_before_function_parenthesis": false, //在函数参数括号前插入空格
"insert_space_before_type_annotation": true, //在类型注解前插入空格
"place_open_brace_on_new_line_for_control_blocks": false, //控制块的开括号是否放在新行上
"place_open_brace_on_new_line_for_functions": false, //函数的开括号是否放在新行上
"semicolons": "ignore", //分号处理方式,可选值包括"ignore"(忽略)、"insert"(插入)、"remove"(移除)。
"trim_trailing_whitespace": true //是否修剪行尾空格
}
}
}
在 VS Code 中,接受 js
、 html
和 css
上的从属设置。请注意,这是 js-beautify 的非标准操作。
Setting | Formatter | [Type] Description / Default[类型] 描述/默认 |
---|---|---|
eol | All | [String] Character(s) to use as line terminators.[字符串] 用作行终止符的字符。"\n"“\n” |
end_with_newline | All | [Boolean] Ensure newline at end of file.[布尔值] 确保文件末尾换行。false错误的 |
indent_char | All | [String] Indentation character.[字符串] 缩进字符。" "” “ |
indent_size | All | [Integer] Indent size.[整数] 缩进大小。4 |
indent_with_tabs | All | [Boolean] Indent with tabs, overrides 'indent_size' and 'indent_char'[布尔值] 使用制表符缩进,覆盖 'indent_size' 和 'indent_char'false错误的 |
preserve_newlines | All | [Boolean] Preserve line-breaks.[布尔值] 保留换行符。true真的 |
max_preserve_newlines | JS, HTMLJS、HTML | [Integer] Number of line-breaks to be preserved in one chunk.[整数] 一个块中要保留的换行符数量。10 |
wrap_line_length | JS, HTMLJS、HTML | [Integer] Wrap lines at next opportunity after N characters. (Set zero to ignore wrapping)[整数] 在 N 个字符之后的下一个机会换行。 (设置为零以忽略换行)0 |
extra_liners | HTML | [Array<String>] List of tags that should have an extra newline before them.[Array<String>] 前面应有额外换行符的标签列表。["head", "body", "/html"][“头”,“正文”,“/html”] |
indent_body_inner_html | HTML |
[Boolean] Indent elements within html <body> element.[布尔值] html <body> 元素中的缩进元素。true真的
|
indent_handlebars | HTML |
[Boolean] format and indent {{#foo}} and {{/foo}} .[布尔] 格式并缩进 {{#foo}} 和 {{/foo}} 。false错误的
|
indent_head_inner_html | HTML | [Boolean] Indent elements within html <head> element.[布尔值] html <head> 元素中的缩进元素。true真的 |
indent_inner_html | HTML |
[Boolean] Indent <head> and <body> sections.[布尔值] 缩进 <head> 和 <body> 部分。false错误的
|
indent_scripts | HTML | [String] "keep", "separate", or "normal"[字符串]“保留”、“单独”或“正常”"normal"“普通的” |
inline | HTML | [Array<String>][ "a", "abbr", "area", "audio", "b", "bdi", "bdo", "br", "button", "canvas", "cite", "code", "data", "datalist", "del", "dfn", "em", "embed", "i", "iframe", "img", "input", "ins", "kbd", "keygen", "label", "map", "mark", "math", "meter", "noscript", "object", "output", "progress", "q", "ruby", "s", "samp", "select", "small", "span", "strong", "sub", "sup", "svg", "template", "textarea", "time", "u", "var", "video", "wbr", "text", "acronym", "address", "big", "dt", "ins", "strike", "tt" ] |
wrap_attributes | HTML | [String] Wrap attributes to new lines. "auto", "force", "force-aligned", "force-expand-multiline", "align-multiple", "preserve", or "preserve-aligned"[字符串] 将属性换行到新行。 “自动”、“强制”、“强制对齐”、“强制扩展多行”、“对齐多行”、“保留”或“保留对齐”"auto"“汽车” |
wrap_attributes_indent_size | HTML | [Boolean] Indent wrapped attributes to after N characters. Defaults to 'indent_size'.[布尔值] 将包装属性缩进 N 个字符之后。默认为“缩进大小”。false错误的 |
unformatted | HTML | [Array<String>] List of tags that should not be reformatted.[Array<String>] 不应重新格式化的标签列表。 |
content_unformatted | HTML | [Array<String>] List of tags who's content should not be reformatted[Array<String>] 内容不应重新格式化的标签列表["pre", "textarea"][“预”、“发短信”] |
void_elements | HTML | [Array<String>] HTML void elements - aka self-closing tags[Array<String>] HTML void 元素 - 又名自闭合标签["area", "base", "br", "col", "embed", "hr", "img", "input", "keygen", "link", "menuitem", "meta", "param", "source", "track", "wbr", "!doctype", "?xml", "?php", "?=", "basefont", "isindex"] |
newline_between_rules | CSS | [Boolean] Add a newline between CSS rules.[布尔值] 在 CSS 规则之间添加换行符。false错误的 |
selector_separator_newline | CSS | [Boolean] Add a newline between multiple selectors.[Boolean] 在多个选择器之间添加换行符。true真的 |
space_around_combinator | CSS | [Boolean] Ensure space around selector separators (>+~).[布尔值] 确保选择器分隔符 (>+~) 周围有空间。false错误的 |
brace_style | JS | [String] "collapse", "expand", "end-expand", "none", "collapse,preserve-inline", "expand,preserve-inline", "end-expand,preserve-inline", or "none,preserve-inline"[字符串]“折叠”、“展开”、“结束展开”、“无”、“折叠、保留内联”、“展开、保留内联”、“结束展开、保留内联”或“无” ,保留内联”"collapse"“坍塌” |
break_chained_methods | JS | [Boolean] Break chained method calls across subsequent lines.[布尔值] 中断后续行中的链式方法调用。false错误的 |
comma_first | JS | [Boolean] Put commas at the beginning of new line instead of end.[布尔值] 将逗号放在新行的开头而不是末尾。false错误的 |
e4x | JS | [Boolean] Pass E4X xml literals through untouched.[布尔值] 不受影响地传递 E4X xml 文字。false错误的 |
indent_level | JS | [Integer] Initial indentation level.[整数] 初始缩进级别。0 |
jslint_happy | JS | [Boolean] Enable jslint-stricter mode. (Forces 'space_after_anon_function')[Boolean] 启用 jslint-stricter 模式。 (强制'space_after_anon_function')false错误的 |
keep_array_indentation | JS | [Boolean] Preserve array indentation.[布尔值] 保留数组缩进。false错误的 |
keep_function_indentation | JS | [Boolean] Preserve function indentation.[布尔值] 保留函数缩进。false错误的 |
operator_position | JS | [String] Move operators to before or after a new line, or keep as is. "before-newline", "after-newline", or "preserve-newline"[String] 将运算符移动到新行之前或之后,或保持原样。 “换行之前”、“换行之后”或“保留换行”"before-newline"“换行之前” |
space_after_anon_function | JS |
[Boolean] Add a space before an anonymous function's parens, ie. function () .[Boolean] 在匿名函数的括号前添加一个空格,即。 function () 。false错误的
|
space_after_named_function | JS |
[Boolean] Add a space before a named function's parens, ie. function example () .[Boolean] 在命名函数的括号前添加一个空格,即。 function example () 。false错误的
|
space_before_conditional | JS | [Boolean] Ensure a space before conditional statement.[布尔值] 确保条件语句前有一个空格。true真的 |
space_in_empty_paren | JS |
[Boolean] Leave space in empty parentheses, ie. f( ) .[布尔值] 在空括号中留出空格,即。 f( ) 。false错误的
|
space_in_paren | JS |
[Boolean] Add padding spaces within parentheses, ie. f( a, b ) .[Boolean] 在括号内添加填充空格,即。 f( a, b ) 。false错误的
|
unescape_strings | JS | [Boolean] Decode printable characters encoded in xNN notation.[布尔值] 解码以 xNN 表示法编码的可打印字符。false错误的 |
unindent_chained_methods | JS | [Boolean] Unindent chained methods[布尔值] 取消缩进链式方法 |
发表留言 取消回复