如何适应多种编码风格? (git vs. IDE) [英] How to accommodate multiple coding styles? (git vs. IDE)

查看:161
本文介绍了如何适应多种编码风格? (git vs. IDE)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用多个IDE(注1)与不同的代码样式偏好与使用git源代码,maven管理的Java项目合作。



是否有工具或IDE配置,允许使用 style-1 查看和编辑代码,但使用 style-2



我的研究指出了'no',而是一个结合 git钩子 Checkstyle / jrefactory



因此,如果上面的否,是否有一个工具/过程将执行下面的 TBD过程操作?



结帐流程User1将是:


  1. git pull

  2. / i>设置

User1的提交工作流程为:



<
  • User1已准备好提交/推送代码

  • TBD过程将代码格式化为标准格式

  • git push

  • p>
    注意1:多个IDE's = Eclipse,IntelliJ,Netbeans。



    注意2:我的问题不同于这个问题, d喜欢专注于IDE相关的解决方案,因为强制少数标准 - 不同的用户可能是一个更有效的解决方案。



    注意3:因为最佳做法的原因。但是,如果您授予我们的IDE和SCM更多的灵活性,则此问题旨在探索这些解决方案。

    解决方案

    首先,你真的不应该这样做。 Codestyle战争对任何项目都是坏的,最好决定一个 codestyle,每个人都必须使用。很容易配置IDE在每个文件夹自动应用指定的编码,所以开发人员不必在目标代码编写代码本身,他们可以让IDE为他们。是的,这并不能解决他们必须以一种他们不喜欢的编码方式阅读代码的事实,但它比隐形自动代码更改更安全;



    也许你可以使用Eclipse的代码格式化程序从命令行来应用不同的codestyle。你必须设置git钩子,确保每个人都有Eclipse可用,并提供适当的配置文件为他们喜欢的codestyle。你需要钩子既用于后检出和预提交,一个设置用户的codestyle,另一个提交在中央codestyle。要进一步,您可以使用索引来添加格式化的代码,以便它不包括 git diff 中的样式差异(虽然它们将显示在 git diff --staged )。



    同样,你不应该这样做


    I am collaborating on a git-sourced, maven-managed Java project with differing code styling preferences with users using multiple IDE's (note 1).

    Is there a tool or IDE configuration that will allow code to be viewed and edited using style-1, but committed to SCM using style-2?

    My research points me to 'no', but a solution combining git hooks and Checkstyle/jrefactory might be possible.

    So if 'no' to above, is there a tool/process that will perform the TBD process actions below?

    The checkout process flow for User1 would be:

    1. git pull
    2. TBD process formats code to User1 style-1
    3. User1 works in their preferred IDE with style-1 settings

    The commit workflow for User1 would be:

    1. User1 is ready to commit/push code
    2. TBD process formats code to standard format style-standard
    3. git push

    Note 1: multiple IDE's = Eclipse, IntelliJ, Netbeans.

    Note 2: My question differs from this question in that I'd like to focus on an IDE-related solution, since forcing the minority of standards-divergent users is probably a more efficient solution.

    Note 3: Acknowledging that this shouldn't be done for best-practices-reasons. However, if you grant that it's time expect more flexibility from our IDEs and SCMs, this question is intended to explore those solutions.

    解决方案

    First of all, you really shouldn't do that. Codestyle wars are bad for any project, and it is best to decide upon one codestyle that everybody must use. It is simple to configure IDEs to automatically apply the specified codestyle at every filesave, so the developers don't have to write code in the target codestyle themselves, they can let the IDE do that for them. True, this doesn't solve the fact that they'll have to read code in a codestyle they don't yet like, but it's a lot safer than having invisible automatic code changes; that's a major source of bugs.

    Maybe you can use Eclipse's code formatter from the command line to apply a different codestyle. You'd have to set up git hooks, make sure everybody has Eclipse available, and provide the proper configuration files for their preferred codestyle. You'd need hooks both for post-checkout and pre-commit, one to set up the user's codestyle, the other to commit in the central codestyle. To go one step further, you can play with the index to add the formatted code so that it doesn't include style differences in git diff (although they will show up in git diff --staged).

    Again, you shouldn't do that.

    这篇关于如何适应多种编码风格? (git vs. IDE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆