Source files and automated formatting #134
Replies: 3 comments 5 replies
-
I think this should definitively be done. I already did this for FDISK.
|
Beta Was this translation helpful? Give feedback.
-
But not sure if it is that good doing it automatically in the pipeline. There are edge cases where the formatter may fail. I think it would be best to start with a configuration file for the formatter inside the repo and initially running the formatter manually. |
Beta Was this translation helpful? Give feedback.
-
I also use clang-format, but usually on a per function basis. I use it with vim integration so that I can select a region and just format that if required. I believe there are similar add-ons for Emacs and Vscode. In FDPP and Dosemu2 we've tried to limit the formatting changes where possible so that patches can go back and forth between FreeDOS kernel and Dosemu(1), respectively. If a function is so poorly formatted, or say more than 60% will be changed then it gets reformatted via clang-format in a separate commit first. Sure it will take longer to achieve a nice look, but with older projects where most of your development occurred before any global reformat, repository history will be considerably easier to navigate. I'm not a fan of automatically reformatting source in the pipeline as I think it should be the responsibility of the committer what gets committed. Sometimes I like to adjust the formatted code to make it more readable. As for style.
That said I don't commit that much to the kernel, so I'm happy to go with whatever you choose. And if you do choose clang-format to do the work leave the configuration file in the top level of the repository so others get to use it automatically. Regarding CI pipeline checks, we already have build and boot tests for Watcom and Gcc on Linux as the tools are freely available. Can something be done for Windows too? I could probably get a DOS build with Dosemu2 and GCC to work if it doesn't offend anyone? |
Beta Was this translation helpful? Give feedback.
-
I would like to apply automatic formatting to kernel source files before applying changes. I.e update commit pipeline to run a formatting tool on source. Currently there is a mix of styles, tabs, and spacing. It doesn't help that each computer I use seems to show and convert tabs to spaces differently.
For discussion are 3 major questions:
should the changes be applied to all files with one big commit or should files be formatted as updates to that file made (probably initially as two steps, 1 patch for formatting then apply the change). Either way it will effect history but I think piecemeal preserves history better while the first way is more like a ripping off a bandaid and may be better long term.
what program do people suggest using to format the files? clang has one, and there are at least a few others
which options? i.e. what should the formatting look like. this one is largely personal taste, but I figure once set then nothing to argue about:-)
Beta Was this translation helpful? Give feedback.
All reactions