有没有一个不糟糕的格式化 JavaScript 的工具?
我正在寻找一个可以为我格式化 javascript 的工具。很多时候,我希望我可以让一个工具格式化我的源代码,因为重组一些代码或者因为我想确保代码结构确实像我相信的那样。我的问题是我发现的所有格式化程序都会产生非常迟缓的结果。
如果我自己格式化源代码,我会像这样格式化它:
var structure = {
key1: {
subkey1: 3,
subkey: 6,
sublist: [
{
deep: "yes"
},
{
deep: "yes",
somekey: 4
},
5,
10
]
},
key2: [
{
key: 5,
key2: 10
},
[1, 2, 3],
[
{
nestedObj: "hello",
siblingProp: 5
},
{}
]
]
}
无论我找到什么工具,都不必以完全相同的方式执行此操作,但看看 eclipse 内置格式化程序的功能:
var structure = {
key1 : {
subkey1 : 3,
subkey : 6,
sublist : [{
deep : "yes"
}, {
deep : "yes",
somekey : 4
}, 5, 10]
},
key2 : [{
key : 5,
key2 : 10
}, [1, 2, 3], [{
nestedObj : "hello",
siblingProp : 5
}, {}]]
}
或者我使用 Aptana 插件(3.0 beta)获得的格式化程序
var structure = {
key1: {
subkey1: 3,
subkey: 6,
sublist: [
{
deep: "yes"
},
{
deep: "yes",
somekey: 4
},
5,
10
]
},
key2: [
{
key: 5,
key2: 10
},
[1, 2, 3],
[
{
nestedObj: "hello",
siblingProp: 5
},
{}
]
]
}
它们在可视化我的数据结构的结构方面提供零帮助。 有人知道一个不错的格式化程序吗?请。
I am looking for a tool that formats my javascript for me. There are many times when I wish I could just let a tool format my source code because of restructuring some code or because I want to make sure the code structure really is like I believe it to be. My problem is that all formatters I have found produce really retarded results.
If I format the source myself I would format it like this:
var structure = {
key1: {
subkey1: 3,
subkey: 6,
sublist: [
{
deep: "yes"
},
{
deep: "yes",
somekey: 4
},
5,
10
]
},
key2: [
{
key: 5,
key2: 10
},
[1, 2, 3],
[
{
nestedObj: "hello",
siblingProp: 5
},
{}
]
]
}
Whatever tool I find doesn't have to do it exactly the same way but look at what eclipse's built in formatter does:
var structure = {
key1 : {
subkey1 : 3,
subkey : 6,
sublist : [{
deep : "yes"
}, {
deep : "yes",
somekey : 4
}, 5, 10]
},
key2 : [{
key : 5,
key2 : 10
}, [1, 2, 3], [{
nestedObj : "hello",
siblingProp : 5
}, {}]]
}
Or the one I get with Aptana's plugin (3.0 beta)
var structure = {
key1: {
subkey1: 3,
subkey: 6,
sublist: [
{
deep: "yes"
},
{
deep: "yes",
somekey: 4
},
5,
10
]
},
key2: [
{
key: 5,
key2: 10
},
[1, 2, 3],
[
{
nestedObj: "hello",
siblingProp: 5
},
{}
]
]
}
They provide zero help in visualizing the structure of my datastructure.
Does anyone know of a decent formatter? Please.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
WebStorm / PHPStorm / Intellij IDEA
刚刚在我的 PHPStorm 中进行了快速检查:我已经粘贴了“Eclipse”示例中的代码,运行了 Code ->;重新格式化代码,它给了我代码,就像您手动执行的一样(唯一的区别是它用两边的空格包裹冒号)
WebStorm / PHPStorm / Intellij IDEA
Just made a quick check in my PHPStorm: i've pasted your code from "Eclipse" example, ran Code -> Reformat code and it gave me the code, like you would do it manually (the only difference is that it wraps colons with spaces from both sides)
我认为 JS Beautifier 启用“大括号在自己的行”至少接近。
I think the JS Beautifier with "braces on own line" enabled comes at least close.