Incidencia #45075

configure linter to enforce code style

Abrir Fecha: 2022-07-09 20:39 Última actualización: 2023-05-28 02:44

Informador:
Propietario:
(Ninguno)
Tipo:
Estado:
Open
Componente:
Hito:
(Ninguno)
Prioridad:
5 - Medium
Gravedad:
5 - Medium
Resolución:
Ninguno
Fichero:
1

Details

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.

Ticket History (3/5 Histories)

2022-07-09 20:39 Updated by: dark-ether
  • New Ticket "configure linter to enforce code style" created
2022-07-09 21:36 Updated by: None
Comentario

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 Updated by: cazfi
Comentario

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 Updated by: cazfi
Comentario

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.

Attachment File List

  • .clang-format(763octetos)
    • a clang format configuration mostly following the coding style

Editar

You are not logged in. I you are not logged in, your comment will be treated as an anonymous post. » Entrar