Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
pybind11
Commits
8b0ccf76
Commit
8b0ccf76
authored
Jul 20, 2020
by
Henry Schreiner
Committed by
Henry Schreiner
Jul 23, 2020
Browse files
style: adding pre-commit check-style.sh
parent
b16347e5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
42 deletions
+22
-42
.pre-commit-config.yaml
.pre-commit-config.yaml
+10
-1
.travis.yml
.travis.yml
+2
-4
CONTRIBUTING.md
CONTRIBUTING.md
+4
-5
tools/check-style.sh
tools/check-style.sh
+6
-32
No files found.
.pre-commit-config.yaml
View file @
8b0ccf76
...
...
@@ -24,5 +24,14 @@ repos:
rev
:
3.8.2
hooks
:
-
id
:
flake8
additional_dependencies
:
[
flake8-bugbear
]
additional_dependencies
:
[
flake8-bugbear
,
pep8-naming
]
exclude
:
^(docs/.*|tools/.*)$
-
repo
:
local
hooks
:
-
id
:
check-style
name
:
Classic check-style
language
:
system
types
:
-
c++
entry
:
./tools/check-style.sh
.travis.yml
View file @
8b0ccf76
...
...
@@ -9,7 +9,7 @@ matrix:
# also tests the automatic discovery functions in CMake (Python version, C++ standard).
-
os
:
linux
dist
:
xenial
# Necessary to run doxygen 1.8.15
name
:
Style, d
ocs
,
and pip
name
:
D
ocs and pip
cache
:
false
before_install
:
-
pyenv global $(pyenv whence 2to3)
# activate all python versions
...
...
@@ -18,12 +18,10 @@ matrix:
install
:
# breathe 4.14 doesn't work with bit fields. See https://github.com/michaeljones/breathe/issues/462
# Latest breathe + Sphinx causes warnings and errors out
-
$PY_CMD -m pip install --user --upgrade "sphinx<3" sphinx_rtd_theme breathe==4.13.1
flake8 pep8-naming
pytest
-
$PY_CMD -m pip install --user --upgrade "sphinx<3" sphinx_rtd_theme breathe==4.13.1 pytest
-
curl -fsSL https://sourceforge.net/projects/doxygen/files/rel-1.8.15/doxygen-1.8.15.linux.bin.tar.gz/download | tar xz
-
export PATH="$PWD/doxygen-1.8.15/bin:$PATH"
script
:
-
tools/check-style.sh
-
flake8
-
$PY_CMD -m sphinx -W -b html docs docs/.build
-
|
# Make sure setup.py distributes and installs all the headers
...
...
CONTRIBUTING.md
View file @
8b0ccf76
...
...
@@ -27,11 +27,10 @@ adhere to the following rules to make the process as smooth as possible:
do add value by themselves.
*
Add tests for any new functionality and run the test suite (
``make pytest``
)
to ensure that no existing features break.
*
Please run
[
``pre-commit``
][
pre-commit
]
and
``tools/check-style.sh``
to check
your code matches the project style. (Note that
``check-style.sh``
requires
``gawk``
.) Use
`pre-commit run --all-files`
before committing (or use
installed-mode, check pre-commit docs) to verify your code passes before
pushing to save time.
*
Please run
[
``pre-commit``
][
pre-commit
]
to check your code matches the
project style. (Note that
``gawk``
is required.) Use
`pre-commit run
--all-files`
before committing (or use installed-mode, check pre-commit docs)
to verify your code passes before pushing to save time.
*
This project has a strong focus on providing general solutions using a
minimal amount of code, thus small pull requests are greatly preferred.
...
...
tools/check-style.sh
View file @
8b0ccf76
...
...
@@ -4,45 +4,19 @@
#
# This script currently checks for
#
# 1. use of tabs instead of spaces
# 2. MSDOS-style CRLF endings
# 3. trailing spaces
# 4. missing space between keyword and parenthesis, e.g.: for(, if(, while(
# 5. Missing space between right parenthesis and brace, e.g. 'for (...){'
# 6. opening brace on its own line. It should always be on the same line as the
# 1. missing space between keyword and parenthesis, e.g.: for(, if(, while(
# 2. Missing space between right parenthesis and brace, e.g. 'for (...){'
# 3. opening brace on its own line. It should always be on the same line as the
# if/while/for/do statement.
#
# Invoke as: tools/check-style.sh
# Invoke as: tools/check-style.sh
<filenames>
#
check_style_errors
=
0
IFS
=
$'
\n
'
found
=
"
$(
GREP_COLORS
=
'mt=41'
GREP_COLOR
=
'41'
grep
$'
\t
'
include tests/
*
.
{
cpp,py,h
}
docs/
*
.rst
-rn
--color
=
always
)
"
if
[
-n
"
$found
"
]
;
then
# The mt=41 sets a red background for matched tabs:
echo
-e
'\033[31;01mError: found tab characters in the following files:\033[0m'
check_style_errors
=
1
echo
"
$found
"
|
sed
-e
's/^/ /'
fi
found
=
"
$(
grep
-IUlr
$'
\r
'
include tests/
*
.
{
cpp,py,h
}
docs/
*
.rst
--color
=
always
)
"
if
[
-n
"
$found
"
]
;
then
echo
-e
'\033[31;01mError: found CRLF characters in the following files:\033[0m'
check_style_errors
=
1
echo
"
$found
"
|
sed
-e
's/^/ /'
fi
found
=
"
$(
GREP_COLORS
=
'mt=41'
GREP_COLOR
=
'41'
grep
'[[:blank:]]\+$'
include tests/
*
.
{
cpp,py,h
}
docs/
*
.rst
-rn
--color
=
always
)
"
if
[
-n
"
$found
"
]
;
then
# The mt=41 sets a red background for matched trailing spaces
echo
-e
'\033[31;01mError: found trailing spaces in the following files:\033[0m'
check_style_errors
=
1
echo
"
$found
"
|
sed
-e
's/^/ /'
fi
found
=
"
$(
grep
'\<\(if\|for\|while\|catch\)(\|){'
include tests/
*
.
{
cpp,h
}
-rn
--color
=
always
)
"
found
=
"
$(
grep
'\<\(if\|for\|while\|catch\)(\|){'
$@
-rn
--color
=
always
)
"
if
[
-n
"
$found
"
]
;
then
echo
-e
'\033[31;01mError: found the following coding style problems:\033[0m'
check_style_errors
=
1
...
...
@@ -60,7 +34,7 @@ last && /^\s*{/ {
last=""
}
{ last = /(if|for|while|catch|switch)\s*\(.*\)\s*$/ ? $0 : "" }
'
$(
find include
-type
f
)
tests/
*
.
{
cpp,h
}
docs/
*
.rst
)
"
'
$(
find include
-type
f
)
$@
)
"
if
[
-n
"
$found
"
]
;
then
check_style_errors
=
1
echo
-e
'\033[31;01mError: braces should occur on the same line as the if/while/.. statement. Found issues in the following files:\033[0m'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment