From 85dba8c70f0f7eda3291c03c571fbfa353c06441 Mon Sep 17 00:00:00 2001 From: Mike Gelfand Date: Thu, 28 Feb 2019 02:01:21 +0300 Subject: [PATCH] Add code style script and Dockerfile --- README.md | 13 ++++++ code_style.sh | 78 ++++++++++++++++++++++++++++++++++++ docker-compose.yml | 9 +++++ docker/code_style/Dockerfile | 8 ++++ 4 files changed, 108 insertions(+) create mode 100755 code_style.sh create mode 100644 docker-compose.yml create mode 100644 docker/code_style/Dockerfile diff --git a/README.md b/README.md index c8fb038b7..02c1bc5f0 100644 --- a/README.md +++ b/README.md @@ -60,3 +60,16 @@ If you're new to building programs from source code, this is typically easier th $ cmake .. $ make $ sudo make install + +## Contributing + +### Code Style + +You would want to setup your editor to make use of uncrustify.cfg and .jsbeautifyrc configuration files located in the root of this repository. + +If for some reason you are unwilling or unable to do so, there is a shell script which you could run either directly or via docker-compose: + + $ ./code_style.sh + or + $ docker-compose build --pull + $ docker-compose run --rm code_style diff --git a/code_style.sh b/code_style.sh new file mode 100755 index 000000000..4bce5060f --- /dev/null +++ b/code_style.sh @@ -0,0 +1,78 @@ +#!/bin/sh + +set -euo pipefail + +[ -z "${1:-}" ] || cd "$1" + +echo '==================' +echo '=== uncrustify ===' +echo '==================' +echo '' + +find \ + cli \ + daemon \ + gtk \ + libtransmission \ + utils \ + \( -name '*.c' -o -name '*.h' \) \ + ! \( -name 'ConvertUTF.*' -o -name 'jsonsl.*' -o -name 'wildmat.c' \) \ + -print0 | +xargs \ + -0 \ + uncrustify \ + --replace \ + --no-backup \ + -c uncrustify.cfg + +find \ + qt \ + \( -name '*.cc' -o -name '*.h' \) \ + -print0 | +xargs \ + -0 \ + uncrustify \ + --replace \ + --no-backup \ + -l CPP \ + -c uncrustify.cfg + +echo '' +echo '=================================================================' +echo '=== const placement (until uncrustify supports it, hopefully) ===' +echo '=================================================================' +echo '' + +find \ + cli \ + daemon \ + gtk \ + libtransmission \ + qt \ + utils \ + \( -name '*.c' -o -name '*.cc' -o -name '*.h' \) \ + ! \( -name 'ConvertUTF.*' -o -name 'jsonsl.*' -o -name 'wildmat.c' \) \ + -print0 | +xargs \ + -0 \ + -n1 \ + perl \ + -pi \ + -e 'BEGIN { print STDOUT "Processing: ${ARGV[0]}\n" } s/((?:^|[(,;]|\bstatic\s+)\s*)\b(const)\b(?!\s+\w+\s*\[)/\1>\2