8000 Add example of using pre-commit hook to check code style · shiv-io/server-client-python@407ba6d · GitHub
[go: up one dir, main page]

Skip to content

Commit 407ba6d

Browse files
committed
Add example of using pre-commit hook to check code style
1 parent 326c4f9 commit 407ba6d

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

docs/dev-guide.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,40 @@ Here's a quick checklist to follow when coding to ensure a good pull request
7272
issues before submitting your pull request.
7373
- Keep commit messages clean and descriptive.
7474

75+
### Use git pre-commit hook
76+
77+
Setting up a git pre-commit hook can be helpful to ensure your code changes follow
78+
the project style conventions before pushing and creating a pull request.
79+
80+
To configure the pre-commit hook, navigate to your local clone/fork of the
81+
`server-client-python` project and change into the `.git/hooks` directory.
82+
Create a file `pre-commit` with the contents below and mark it as executable
83+
(`chmod +x pre-commit`).
84+
85+
To test that the hook is working correctly, make a style-inconsistent change (for
86+
example, changing some indentation to not be a multiple of 4), then try to commit
87+
locally. You should get a failure with an explanation from pycodestyle with the
88+
issue.
89+
90+
```shell
91+
#!/bin/sh
92+
93+
# only check if on a code branch (i.e. skip if on a docs branch)
94+
if [ -e tableauserverclient/__init__.py ];
95+
then
96+
# check for style conventions in all code dirs
97+
echo Running pycodestyle
98+
pycodestyle tableauserverclient test samples
99+
fi
100+
```
101+
102+
Windows users: The first line of the sample script above will need to be adjusted
103+
depending on how and where git is installed on your system, for example:
104+
105+
```shell
106+
#!C:/Program\ Files/Git/usr/bin/sh.exe
107+
```
108+
75109
### Adding features
76110

77111
1. Create an endpoint class for the new feature, following the structure of the

0 commit comments

Comments
 (0)
0