设置
在 kscript.json 中的 "format" 下设置样式。每个设置都是可选的:
{
"format": {
"indent": 2, // spaces per level, or "tab"
"tab_width": 2, // with "indent": "tab", the columns a tab counts as
"print_width": 80, // the longest a line should be; longer lines are wrapped
"max_blank_lines": 1, // blank lines kept in a row
"end_of_line": "auto", // auto (keep each file's), lf or crlf
"preserve": ["pre-like"], // elements whose content is kept exactly
"rules": {}, // turn rules off, e.g. { "statement_per_line": false }; see below
"enabled": true, // false: no formatting anywhere in this project
"include": ["**/*.kscript", "**/*.ks.xml", "**/*.html"],
"exclude": ["_templates", "node_modules", ".git"]
}
}这些设置也可以来自一个标准,因此多个项目可以共享同一种风格:将它们放在标准文件中的"format"下,并在kscript.json中用"standard"为其命名。默认标准kscript:recommended会写出上面的值。kscript.json自身设置的任何内容都优先于其标准。
在编辑器中,当既没有设置 kscript.json 也没有其标准设置时,缩进使用编辑器自身的制表符设置(editor.tabSize、editor.insertSpaces)。当项目或其标准设置了 format.indent 时,则以该设置为准,从而确保项目中的所有人得到相同的结果。