Skip to content

Commit 85ec448

Browse files
Chris Chinchillachriseth
andcommitted
Add style checker
Rename files Changes from review Update test/docsCodeStyle.sh Co-Authored-By: chriseth <[email protected]> Update test/docsCodeStyle.sh Co-Authored-By: chriseth <[email protected]> Remove extraneous brackets
1 parent 967ee94 commit 85ec448

File tree

6 files changed

+81
-3
lines changed

6 files changed

+81
-3
lines changed

.circleci/config.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,22 @@ jobs:
183183
name: Check spelling
184184
command: ~/.local/bin/codespell -S "*.enc,.git" -I ./scripts/codespell_whitelist.txt
185185

186+
chk_docs_examples:
187+
docker:
188+
- image: circleci/node
189+
environment:
190+
TERM: xterm
191+
steps:
192+
- checkout
193+
- attach_workspace:
194+
at: build
195+
- run:
196+
name: JS deps
197+
command: sudo npm install -g solhint
198+
- run:
199+
name: Test Docs examples
200+
command: ./test/docsCodeStyle.sh
201+
186202
chk_coding_style:
187203
docker:
188204
- image: buildpack-deps:disco
@@ -586,6 +602,7 @@ workflows:
586602
# basic checks
587603
- chk_spelling: *workflow_trigger_on_tags
588604
- chk_coding_style: *workflow_trigger_on_tags
605+
- chk_docs_examples: *workflow_trigger_on_tags
589606
- chk_buglist: *workflow_trigger_on_tags
590607
- chk_proofs: *workflow_trigger_on_tags
591608

@@ -646,4 +663,3 @@ workflows:
646663
# Code Coverage enabled build and tests
647664
- b_ubu_codecov: *workflow_trigger_on_tags
648665
- t_ubu_codecov: *workflow_ubuntu1904_codecov
649-

scripts/isolate_tests.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ def extract_docs_cases(path):
5959
def write_cases(f, tests):
6060
cleaned_filename = f.replace(".","_").replace("-","_").replace(" ","_").lower()
6161
for test in tests:
62-
open('test_%s_%s.sol' % (hashlib.sha256(test).hexdigest(), cleaned_filename), 'wb').write(test)
63-
62+
# When code examples are extracted they indented by 8 spaces, which violates the style guide,
63+
# so before checking remove 4 spaces from each line.
64+
remainder = re.sub(r'^ {4}', '', test, 0, re.MULTILINE)
65+
open('test_%s_%s.sol' % (hashlib.sha256(test).hexdigest(), cleaned_filename), 'wb').write(remainder)
6466

6567
def extract_and_write(f, path):
6668
if docs:

test/.solhint.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "solhint:default",
3+
"plugins": [],
4+
"rules": {
5+
"compiler-fixed": false,
6+
"no-inline-assembly": false
7+
}
8+
}

test/.solhintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*contributing_rst*

test/cmdlineTests.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ SOLTMPDIR=$(mktemp -d)
308308
set -e
309309
cd "$SOLTMPDIR"
310310
"$REPO_ROOT"/scripts/isolate_tests.py "$REPO_ROOT"/docs/ docs
311+
311312
for f in *.sol
312313
do
313314
# The contributors guide uses syntax tests, but we cannot
@@ -317,6 +318,7 @@ SOLTMPDIR=$(mktemp -d)
317318
continue
318319
fi
319320
echo "$f"
321+
320322
opts=''
321323
# We expect errors if explicitly stated, or if imports
322324
# are used (in the style guide)

test/docsCodeStyle.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
## GLOBAL VARIABLES
6+
7+
REPO_ROOT=$(cd $(dirname "$0")/.. && pwd)
8+
9+
## FUNCTIONS
10+
11+
if [ "$CIRCLECI" ]
12+
then
13+
function printTask() { echo "$(tput bold)$(tput setaf 2)$1$(tput setaf 7)"; }
14+
function printError() { echo "$(tput setaf 1)$1$(tput setaf 7)"; }
15+
else
16+
function printTask() { echo "$(tput bold)$(tput setaf 2)$1$(tput sgr0)"; }
17+
function printError() { echo "$(tput setaf 1)$1$(tput sgr0)"; }
18+
fi
19+
20+
printTask "Checking docs examples style"
21+
SOLTMPDIR=$(mktemp -d)
22+
(
23+
set -e
24+
cd "$SOLTMPDIR"
25+
"$REPO_ROOT"/scripts/isolate_tests.py "$REPO_ROOT"/docs/ docs
26+
27+
if npm -v >/dev/null 2>&1; then
28+
if npm list -g | grep solhint >/dev/null 2>&1; then
29+
echo "node is installed, setting up solhint"
30+
cp "$REPO_ROOT"/test/.solhint.json "$SOLTMPDIR"/.solhint.json
31+
cp "$REPO_ROOT"/test/.solhintignore "$SOLTMPDIR"/.solhintignore
32+
33+
for f in *.sol
34+
do
35+
echo "$f"
36+
# Only report errors
37+
solhint -f unix "$SOLTMPDIR/$f"
38+
done
39+
else
40+
echo "node is installed, but not solhint"
41+
exit 1
42+
fi
43+
else
44+
echo "node not installed, skipping docs style checker"
45+
exit 1
46+
fi
47+
)
48+
rm -rf "$SOLTMPDIR"
49+
echo "Done."

0 commit comments

Comments
 (0)