チケット #45075

configure linter to enforce code style

登録: 2022-07-09 20:39 最終更新: 2023-05-28 02:44

報告者:
担当者:
(未割り当て)
チケットの種類:
状況:
オープン
コンポーネント:
マイルストーン:
(未割り当て)
優先度:
5 - 中
重要度:
5 - 中
解決法:
なし
ファイル:
1

詳細

there are a lot of rules in the code style required and most of them can be enforced by a linter. another open source project i contributed in the past has a linter configured so that after coding you only need to run a command to be in the correct style, this is a significantly better coding experience than submitting a patch and then someone saying you forgot a space after a comma, on the otherside if a linter was configured you wouldn't have to deal with non compliant code patches. besides that if we configure a linter we could make old non compliant code follow the style, and it would lower the barrier for contributing.

i tried to create a configuration for clang-format, and it mostly works, however clang format doesn't have a option to automatically insert a space after a comma and it mistakes the looping macros as functions so it adds a line break, however the previously said part about making old code compliant is still true so if we wanted to change the code style rules we could just run the linter on the whole project to change, i do not know any other linters for c other than clang format/tidy but if there is a better one i would be willing to configure it, the two problems i mentioned don't seem fixable without upstream patches, although i may be wrong.

i am not saying we need to change the coding style to follow the linter configuration however something like this could be an option. to use clang format just install clang and place the .clang-format file in the freeciv directory or a parent directory. do note that it outputs to stdout normally and needs a option to edit in place.

チケットの履歴 (5 件中 3 件表示)

2022-07-09 20:39 更新者: dark-ether
  • 新しいチケット "configure linter to enforce code style" が作成されました
2022-07-09 21:36 更新者: None
コメント

See also https://github.com/longturn/freeciv21/blob/master/.clang-format Still changed many lines including comments.

Note that the clang-format output depends on the clang-format version.

2022-07-19 15:08 更新者: cazfi
コメント

One thing to note is that we usually don't want reformatting old code, but only update those parts that we're touching anyway. That's to avoid unnecessarily breaking patches and/or cherry-picking between branches.

2023-05-28 02:44 更新者: cazfi
コメント

Once we've cleared most of the clang analyzer warnings, we may have time to start looking in to style issues. Not sure, though, as there are also other tools we could/should take to use.

添付ファイルリスト

  • .clang-format(763バイト)
    • a clang format configuration mostly following the coding style

編集

このチケットにコメントを追加するには、ログインが必要です » ログインする