标签: code-formatting

HTML格式

我必须对一些未格式化的HTML进行一些更改(没有换行符,没有任何内容),并且想知道是否有任何基于Web或开源的工具会自动格式化它以便更容易阅读.

谢谢!

html code-formatting

5
推荐指数
2
解决办法
233
查看次数

VS2008 XAML代码格式化程序

在我的团队中,.xaml文件中的代码样式目前不是很一致.我们查看了Visual Studio自动格式化程序,使其将代码格式化为我们喜欢的内容.但是,对于一种选择,我们缺乏额外的条件.我在谈论的选项可以在工具 - >选项 - >文本编辑器 - > XAML - >格式化下找到.

我们希望每个属性都在一个单独的行上.最初,我们还想要新行上的第一个属性(在标记的开头下面),如下所示:

<MyFooBarButton
    Attrib1="a"
    Attrib2="b" />
Run Code Online (Sandbox Code Playgroud)

但是我们很快意识到运行这些规则会使只设置一个属性的标签看起来很糟糕,特别是如果它们是嵌套的:

<MyFooBarButton
    Attrib1="a" />
    <NestedFoo
        Attrib="b" />
        <NestedFoo2
            Attrib="c" />
Run Code Online (Sandbox Code Playgroud)

所以我们尝试将第一个属性放在与开始标记相同的行上.同时仍然保留两个重要规则(每行一个属性,垂直对齐).在两种情况下看起来都不错:

<MyFooBarButton Attrib1="a"
                Attrib2="b" />

<MyFooBarButton Attrib1="a" />
    <NestedFoo Attrib="b" />
        <NestedFoo2 Attrib="c" />
Run Code Online (Sandbox Code Playgroud)

现在的问题是,Visual Studio似乎缺乏兼顾两者的条件.即:

  • 如果只设置了一个属性:将其保留在一行上.
  • 如果设置了多个属性:将第一个属性放在新行上,每行一个属性并垂直对齐它们.

Visual Studio 2008可以这样做吗?如果没有,ReSharper中的代码格式化程序可以做到吗(可能值得花费)吗?

resharper xaml code-formatting visual-studio-2008

5
推荐指数
1
解决办法
1007
查看次数

Visual C++不断破坏我的代码格式对齐

我正在开发一个在源代码中使用水平对齐的开源项目.代码是用C++编写的,我使用的是Visual Studio 2013.Visual Studio尝试在间距方面很聪明,但最终会破坏我的手动对齐.

典型的代码如下所示:

bool  ?   ?   ? GetFieldWithType  ?   ? ( int idx, cc8* name, int type );
bool  ?   ?   ? GetFieldWithType  ?   ? ( int idx, int key, int type );
static cc8*   ? GetLuaTypeName    ?   ? ( int type );
void* ?   ?   ? GetPtrUserData    ?   ? ( int idx );
Run Code Online (Sandbox Code Playgroud)

现在,如果我像这样添加另一行,只要我输入左括号(在两个选项卡之后),Visual Studio就会删除我刚刚输入的两个选项卡并用一个空格替换它们.我试着耐心点击Ctrl + Z来撤消自动格式化.但是一旦我输入分号,它就会再次杀死标签.

我在工具>选项>文本编辑器> C/C++>格式设置>间距>间距中找到了一个选项,用于切换是否在参数列表的左括号之前插入空格的函数括号.如果我取消激活此选项,VS仍然坚持在左括号之前删除选项卡,它只是不添加空格.我如何摆脱这种行为?

要明确:我很好用VS自动插入空格(根据我的配置).我不想完全停用自动格式化.我只是不希望它删除我手动输入的间距.

code-formatting autoformatting visual-studio visual-c++ visual-studio-2013

5
推荐指数
1
解决办法
3564
查看次数

阻止Resharper StyleCop代码清理以创建区域

代码清理后(profile:StyleCop)它总是为构造函数,属性等创建区域......

#region Constructors and Destructors

public IpDiagnosticsService()
{
    // : base()
    // NOP. Required for serializer.
}

public IpDiagnosticsService(string applicationName, SPFarm farm) : base(applicationName, farm)
{
    // NOP
}

#endregion

#region Properties

// ...omitted.

#endregion
Run Code Online (Sandbox Code Playgroud)

真棒.我不希望这样. 怎么把它关掉?找不到任何选项.

resharper code-formatting stylecop visual-studio resharper-8.0

5
推荐指数
1
解决办法
2278
查看次数

有没有一种方法可以漂亮地格式化或美化NSIS脚本源代码?

我有一个NSIS脚本,它有几千行,而且缩进不正确,使脚本难以阅读。有没有一种格式化NSIS脚本的方法,或者至少能够缩进Ifs和Endifs部分?有很多用于HTML,Javascript,XML等的在线脚本格式化程序。

format formatting code-formatting nsis

5
推荐指数
1
解决办法
359
查看次数

将data.table链分成两行代码以便于阅读

我正在研究一个Rmarkdown文档,并被告知要严格限制最大列数(边距列)为100.在文档的代码块中,我使用了许多不同的包,其中包括data.table.

为了符合限制,我可以拆分链(甚至长命令),如:

p <- ggplot(foo,aes(bar,foo2))+
       geom_line()+
       stat_smooth()
bar <- sum(long_variable_name_here,
         na.rm=TRUE)
foo <- bar %>% 
         group_by(var) %>%
         summarize(var2=sum(foo2))
Run Code Online (Sandbox Code Playgroud)

但我不能拆分data.table链,因为它会产生错误.我怎样才能实现这样的目标?

bar <- foo[,.(long_name_here=sum(foo2)),by=var]
           [order(-long_name_here)]
Run Code Online (Sandbox Code Playgroud)

当然,最后一行会导致错误.谢谢!

code-formatting r data.table

5
推荐指数
3
解决办法
2332
查看次数

VS Code,使用Twig或Swig标签格式化HTML代码

当我们使用Twig或Swig标签时,有没有办法在VSCode中正确格式化HTML

{% if ... %} {%else%} {%endif%} {% for %} {%endfor%} {% include %}, etc...
Run Code Online (Sandbox Code Playgroud)

现在,代码格式化程序会删除这些标记之前和之后的所有换行符.

无法找到合适的扩展名.既不是配置内部代码格式化程序的方法.

html code-formatting twig visual-studio-code

5
推荐指数
1
解决办法
1740
查看次数

编写argparse解析器的最佳实践

是否有使用Python argparse模块的最佳实践或样式指南?

我会argparse定期进行工作,并且很快会占用大量的行来处理所有配置。对于几乎所有内容,我发现紧贴PEP 8会生成清晰易读的代码,但在这里不是。最终结果始终是很难阅读的丑陋代码块。

痛苦的阅读不是Pythonic:

美丽胜于丑陋。

那么,是否有PEP或其他资源提供有关如何更好地格式化此代码的准则?

丑陋样本(主要遵循PEP 8):

parser = argparse.ArgumentParser(description='A nontrivial modular command')
subparsers = parser.add_subparsers(help='sub-command help')

parser_load = subparsers.add_parser('load', help='Load something somewhere')
parser_load.add_argument('--config',
                         help='Path to configuration file for special settings')
parser_load.add_argument('--dir', default=os.getcwd(),
                         help='The directory to load')
parser_load.add_argument('book', help='The book to load into this big thing')
parser_load.add_argument('chapter', nargs='?', default='',
                         help='Optionally specify a chapter')
parser_load.add_argument('verse', nargs='*',
                         help='Optionally pick as many verses as you want to'
                         ' load')
parser_load.set_defaults(command='load')

parser_write = subparsers.add_parser(
                'write', help='Execute commands …
Run Code Online (Sandbox Code Playgroud)

python code-formatting argparse

5
推荐指数
2
解决办法
2722
查看次数

Python如何打印而不会覆盖我们在多线程时输入的内容

我正在尝试使用python进行聊天,但是如果对方在我输入内容时发送文本,那就搞砸了.我的代码是这样的:

import threading
import time
import sys

def printf(str, *args):
    print(str % args, end='')

def printwait():
    global End
    while not End:
        time.sleep(3)
        print(' ')
        print('waiting respond')


def reqinput():
    global End
    while not End:
        name = input("Input your name:")
        End=name=='@end'

End=False

t1=threading.Thread(target=printwait)
t2=threading.Thread(target=reqinput)

t1.start()
t2.start()

t1.join()
t2.join()

print('done')
Run Code Online (Sandbox Code Playgroud)

当我在打字中间,然后睡眠时间到期时,它就像这样搞砸了:

Input your name:waiting respond
im trying twaiting respond
o typwaiting respond
e somethingwaiting respond
 here
Input your name:waiting respond
waiting respond
waiting respond
waiting respond
waiting respond
waiting respond
waiting respond
@waiting …
Run Code Online (Sandbox Code Playgroud)

python code-formatting python-3.x

5
推荐指数
0
解决办法
81
查看次数

我可以一次在同一项目中的两种不同的代码格式配置之间切换吗?

我正在一个Java项目中,在IntelliJ中有一些严格的代码格式要求。我发现很难理解首选格式,以至于损害了我的效率,并且无法轻松地查看自己的代码。

我正在寻找是否可以存储可以应用于我的代码的两种不同的代码格式配置或配置文件的方法。例如,我想在实现和调试期间将代码格式化为“我的样式”,然后在提交之前将其格式化为“公司样式”。我需要在多个提交中使用相同的代码,因此我需要随意从一种格式转换为另一种格式。

这可能吗?

企业风格,许多换行和空格:

private boolean scpLocalToRemote (String localIP, String remoteIP, String remoteUser,
                   String localFilePath, String remoteFilePath) {
        String scpCommand = "scp " + localFilePath + " " + remoteUser + "@[" + remoteIP + "]:"
                + remoteFilePath;
        log.info("SCP Command: '" + scpCommand + "'");

        try {
            MyProjectInterfaceUtils.runCommand(scpCommand);
        } catch (IOException e) {
            log.severe(e.toString());
            return false;
        }

        return true;
}
Run Code Online (Sandbox Code Playgroud)

我的风格(这是一种开发偏爱,不寻求有关格式化最佳实践的建议):

private boolean scpLocalToRemote(String localIP, String remoteIP, String remoteUser, localFilePath, String remoteFilePath) 
{
        String scpCommand = "scp " + …
Run Code Online (Sandbox Code Playgroud)

code-formatting intellij-idea

5
推荐指数
1
解决办法
60
查看次数