]> granicus.if.org Git - transmission/commitdiff
Add code style script and Dockerfile
authorMike Gelfand <mikedld@mikedld.com>
Wed, 27 Feb 2019 23:01:21 +0000 (02:01 +0300)
committerMike Gelfand <mikedld@mikedld.com>
Thu, 28 Feb 2019 00:19:24 +0000 (03:19 +0300)
README.md
code_style.sh [new file with mode: 0755]
docker-compose.yml [new file with mode: 0644]
docker/code_style/Dockerfile [new file with mode: 0644]

index c8fb038b7707cea1d482ba90645b29bfc59b7658..02c1bc5f0531266d0e3c9860465d02a98dce86e7 100644 (file)
--- 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 (executable)
index 0000000..4bce506
--- /dev/null
@@ -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</g'
+
+echo ''
+echo '==================='
+echo '=== js-beautify ==='
+echo '==================='
+echo ''
+
+find \
+        web \
+    ! -path '*/jquery/*' \
+    -name '*.js' \
+    -print0 |
+xargs \
+    -0 \
+    js-beautify \
+        --config .jsbeautifyrc \
+        --replace
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644 (file)
index 0000000..fe49716
--- /dev/null
@@ -0,0 +1,9 @@
+version: '3'
+
+services:
+  code_style:
+    build: docker/code_style
+    volumes:
+      - .:/src
+      - ./code_style.sh:/code_style.sh:ro
+    command: ["/bin/sh", "/code_style.sh", "/src"]
diff --git a/docker/code_style/Dockerfile b/docker/code_style/Dockerfile
new file mode 100644 (file)
index 0000000..1c1ec57
--- /dev/null
@@ -0,0 +1,8 @@
+FROM alpine
+
+RUN apk add --no-cache \
+        npm \
+        perl \
+        uncrustify \
+    && npm install -g \
+        js-beautify