summaryrefslogtreecommitdiff
path: root/check-style.py
Commit message (Collapse)AuthorAgeFilesLines
* check-style: Allow deciding on individual suggestions with --rewriteCarlos Garnacho2022-12-071-2/+10
| | | | | | | | | | | | | | | Currently, when the rewrite option is passed, the script does not give much choice on whether changes should be applied or not, it just does "git comit -a --amend". However, uncrustify is not always entirely right about the proposed style changes, or it might suggest changes in distant/unrelated bits in the changed functions. Thus the developer needs to be given some option. Change the approach of the --rewrite option, so that it first does "git add -p", so that individual changes may be decided upon, and after all the chunks were gone through, uses "git commit --squash" so that the changes may be reviewed before manually doing "git rebase --autosquash" to merge the changes.
* check-style: Improve the proposed git-rebase commandHunor Csomortáni2022-12-071-2/+6
| | | | Include the sha used for the dry-run instead of using 'origin/main'.
* check-style: Use run() instead of Popen()Hunor Csomortáni2022-12-071-13/+26
| | | | | | | | | | | | | The Python docs recommends using run() for all use-cases it can handle: https://docs.python.org/3/library/subprocess.html#using-the-subprocess-module run() waits for the subprocess started to complete, so it's not necessary to use wait() and communicate() anymore. This simplifies the script. Previously running "check-style.py -r" after each commit in an interactive rebase failed, b/c the script did not wait for the amend command to complete. Using run() instead of Popen() solves this issue.
* check-style: Don't turn off formatting when the chunk starts on line 1Hunor Csomortáni2022-12-071-1/+2
| | | | | | Before this, new files introduced by the range of commits checked were not considered for formatting b/c uncrustify was always turned off in the beginning of the files, and never turned back on.
* check-style: Start enumerating lines from 1Hunor Csomortáni2022-12-071-3/+3
| | | | | | This way "the line before start" and "the line before end" can be expressed as "[start|end] - 1", which looks less like using a magic number.
* ci: Avoid deadlock while reading uncrustify outputRobert Mader2022-12-071-1/+1
| | | | | | | The docu for `Popen.wait()` says: > This will deadlock when using stdout=PIPE and/or stderr=PIPE and > the child process generates enough output to a pipe such that it > blocks waiting for the OS pipe buffer to accept more data.
* ci: Ignore uncrustify calls resulting in unsuccessful return codesCarlos Garnacho2022-12-071-2/+6
| | | | | | | If for some reason uncrustify gets angry at our file and indent on/off marks, it will result in an error code other than 0. Since in those cases there is no output to diff with, we misinterpret those situations as "the whole file should be deleted", which is far from it.
* check-style: Separate uncrustify.cfg file location to a variableCarlos Garnacho2021-07-131-1/+4
| | | | So it's more easily visible.
* check-style: Ignore chunks that only contain deleted codeCarlos Garnacho2021-07-131-1/+1
| | | | These have no code style to check.
* check-style: Fix off-by-one errorCarlos Garnacho2021-07-131-1/+1
| | | | | | Checking the end line, we should account that the whole chunk was already displaced by the code comment that turns uncrustify on, so we are off by one here.
* check-style: Remove all context from diffsCarlos Garnacho2021-07-131-1/+1
| | | | | | | This avoids setting the uncrustify on/off code comments in the middle of surrounding code, and maybe breaking their style on the way. Reducing the context to 0 ensures these are right at the start and end lines of the function.
* build: Add check-style.py helper scriptCarlos Garnacho2021-06-171-0/+131
This script uses uncrustify to detect code style breaks in/around the given SHA diff. There's two ways to use it: - `check-style.py --sha $SHA` prints in stdout the diffs with the changes suggested to the modifications done between HEAD and $SHA. The default with no --sha specified is HEAD^ This is meant for integration in CI, in order to show code style differences, and suggest a set of changes. - `check-style.py -r` in addition amends the changes in the last commit. This is ideal to rewrite all commits in a branch one by one with the suggested changes, e.g.: `$ git rebase origin/master --exec "./check-style -r"` One caveat is that there is per-function granularity in the suggested code changes, so the script might suggest to fix style in unmodified portions of the changed functions.