Skip to content

Commit 16442a2

Browse files
committed
Add pre-commit config with linting for C++ and python
1 parent ade2c75 commit 16442a2

File tree

6 files changed

+134
-0
lines changed

6 files changed

+134
-0
lines changed

.clang-format

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# From https://github.com/man-group/sparrow with sparrow-specific regexes removed.
2+
3+
BasedOnStyle: Mozilla
4+
5+
AccessModifierOffset: '-4'
6+
AlignAfterOpenBracket: BlockIndent
7+
AlignEscapedNewlines: Left
8+
AllowAllArgumentsOnNextLine: false
9+
AllowAllParametersOfDeclarationOnNextLine: false
10+
AllowShortBlocksOnASingleLine: false
11+
AllowShortCaseLabelsOnASingleLine: false
12+
AllowShortFunctionsOnASingleLine: false
13+
AllowShortIfStatementsOnASingleLine: false
14+
# Forbid one line lambdas because clang-format makes a weird split when
15+
# single instructions lambdas are too long.
16+
AllowShortLambdasOnASingleLine: Empty
17+
AllowShortLoopsOnASingleLine: false
18+
AlwaysBreakAfterDefinitionReturnType: None
19+
AlwaysBreakAfterReturnType: None
20+
AlwaysBreakTemplateDeclarations: Yes
21+
BinPackArguments: false
22+
BinPackParameters: false
23+
BreakBeforeBinaryOperators: NonAssignment
24+
BreakBeforeBraces: Allman
25+
BreakBeforeTernaryOperators: true
26+
BreakConstructorInitializers: BeforeComma
27+
BreakInheritanceList: AfterComma
28+
BreakStringLiterals: false
29+
ColumnLimit: '110'
30+
ConstructorInitializerIndentWidth: '4'
31+
ContinuationIndentWidth: '4'
32+
Cpp11BracedListStyle: true
33+
DerivePointerAlignment: false
34+
DisableFormat: false
35+
EmptyLineAfterAccessModifier: Always
36+
EmptyLineBeforeAccessModifier: Always
37+
ExperimentalAutoDetectBinPacking: true
38+
IncludeBlocks: Regroup
39+
IncludeCategories:
40+
- Regex: <[^.]+>
41+
Priority: 1
42+
- Regex: <.+>
43+
Priority: 2
44+
- Regex: '".+"'
45+
Priority: 5
46+
IndentCaseLabels: true
47+
IndentPPDirectives: AfterHash
48+
IndentWidth: '4'
49+
IndentWrappedFunctionNames: false
50+
InsertBraces: true
51+
InsertTrailingCommas: Wrapped
52+
KeepEmptyLinesAtTheStartOfBlocks: false
53+
LambdaBodyIndentation: Signature
54+
Language: Cpp
55+
MaxEmptyLinesToKeep: '2'
56+
NamespaceIndentation: All
57+
ObjCBlockIndentWidth: '4'
58+
ObjCSpaceAfterProperty: false
59+
ObjCSpaceBeforeProtocolList: false
60+
PackConstructorInitializers: Never
61+
PenaltyBreakAssignment: 100000
62+
PenaltyBreakBeforeFirstCallParameter: 0
63+
PenaltyBreakComment: 10
64+
PenaltyBreakOpenParenthesis: 0
65+
PenaltyBreakTemplateDeclaration: 0
66+
PenaltyExcessCharacter: 10
67+
PenaltyIndentedWhitespace: 0
68+
PenaltyReturnTypeOnItsOwnLine: 10
69+
PointerAlignment: Left
70+
QualifierAlignment: Custom # Experimental
71+
QualifierOrder: [inline, static, constexpr, const, volatile, type]
72+
ReflowComments: true
73+
SeparateDefinitionBlocks: Always
74+
SortIncludes: CaseInsensitive
75+
SortUsingDeclarations: true
76+
SpaceAfterCStyleCast: true
77+
SpaceAfterTemplateKeyword: true
78+
SpaceBeforeAssignmentOperators: true
79+
SpaceBeforeParens: ControlStatements
80+
SpaceInEmptyParentheses: false
81+
SpacesBeforeTrailingComments: '2'
82+
SpacesInAngles: false
83+
SpacesInCStyleCastParentheses: false
84+
SpacesInContainerLiterals: false
85+
SpacesInParentheses: false
86+
SpacesInSquareBrackets: false
87+
Standard: c++20
88+
TabWidth: '4'
89+
UseTab: Never

.pre-commit-config.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v6.0.0
4+
hooks:
5+
- id: check-merge-conflict
6+
- id: check-toml
7+
- id: check-yaml
8+
- id: debug-statements
9+
- id: end-of-file-fixer
10+
- id: mixed-line-ending
11+
- id: trailing-whitespace
12+
13+
- repo: https://github.com/asottile/pyupgrade
14+
rev: v3.21.2
15+
hooks:
16+
- id: pyupgrade
17+
args: ['--py312-plus']
18+
19+
- repo: https://github.com/pre-commit/mirrors-clang-format
20+
rev: v21.1.2
21+
hooks:
22+
- id: clang-format
23+
args: [--style=file]
24+
exclude_types: [javascript,json]
25+
26+
- repo: https://github.com/astral-sh/ruff-pre-commit
27+
rev: v0.14.0
28+
hooks:
29+
- id: ruff-check
30+
args: [--fix]
31+
- id: ruff-format

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ The CLI is tested using `python`. From the top-level directory:
2929
pytest -v
3030
```
3131

32+
`pre-commit` runs automatically on `git commit`. To run it manually use:
33+
34+
```bash
35+
pre-commit run --all-files
36+
```
37+
3238
# WebAssembly build and deployment
3339

3440
The `wasm` directory contains everything needed to build the local `git2cpp` source code as an

dev-environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ dependencies:
66
- libgit2
77
- cmake
88
- pkg-config
9+
- pre-commit
910
- python
1011
- pytest
1112
- termcolor-cpp

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# This is not a python project but it contains python tests so here are settings for python linting.
2+
[tool.ruff]
3+
line-length = 100
4+
target-version = "py312"
5+
[tool.ruff.format]
6+
line-ending = "lf"

wasm/wasm-environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: git2cpp-wasm
33
channels:
44
- conda-forge
55
dependencies:
6+
- pre-commit
67
# To modify emscripten-forge recipe
78
- python
89
- pyyaml

0 commit comments

Comments
 (0)