Skip to content

Commit 3257f96

Browse files
authored
Merge pull request #168 from DavidIkov/origin_master
Added lizard for code metrics in non blocking mode.
2 parents 811c499 + 6315e05 commit 3257f96

4 files changed

Lines changed: 81 additions & 1 deletion

File tree

.github/workflows/cmake-build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ jobs:
9090
run: docker run --platform=linux/${{ matrix.arch }} --rm -v ${{ github.workspace }}:/KNP -w /KNP/${{ steps.strings.outputs.build-output-dir }}/knp/tests kasperskydh/knp-build-image ctest -V
9191
timeout-minutes: 180
9292

93+
- name: Analyze C++ code with lizard
94+
run: docker run --platform=linux/${{ matrix.arch }} --rm -v ${{ github.workspace }}:/KNP -w /KNP kasperskydh/knp-build-image ci/run_lizard.sh
95+
continue-on-error: true
96+
9397
- name: Analyze Python code with PyLint
9498
run: docker run --platform=linux/${{ matrix.arch }} --rm -v ${{ github.workspace }}:/KNP -w /KNP kasperskydh/knp-build-image ci/run_pylint.py ${{ steps.strings.outputs.build-output-dir }}/knp_python_framework/knp ${{ steps.strings.outputs.build-output-dir }}
9599

ci/lizard_config.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"directories": [
3+
{
4+
"directory": "knp",
5+
"nloc": 50,
6+
"cyclomatic_complexity": 10,
7+
"token_count": 300,
8+
"parameter_count": 4
9+
},
10+
{
11+
"directory": "examples",
12+
"nloc": 100,
13+
"cyclomatic_complexity": 15,
14+
"token_count": 500,
15+
"parameter_count": 6
16+
}
17+
]
18+
}

ci/run_lizard.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env python3
2+
"""
3+
@file run_lizard.py
4+
@brief Run lizard static analyzer.
5+
6+
@kaspersky_support David P.
7+
@license Apache 2.0 License.
8+
@copyright © 2026 AO Kaspersky Lab
9+
@date 13.03.2026
10+
11+
Licensed under the Apache License, Version 2.0 (the 'License');
12+
you may not use this file except in compliance with the License.
13+
You may obtain a copy of the License at
14+
15+
http://www.apache.org/licenses/LICENSE-2.0
16+
17+
Unless required by applicable law or agreed to in writing, software
18+
distributed under the License is distributed on an 'AS IS' BASIS,
19+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20+
See the License for the specific language governing permissions and
21+
limitations under the License.
22+
"""
23+
24+
25+
import subprocess
26+
import json
27+
28+
29+
def run_lizard(path: str, nloc: int, complexity: int, token_count: int, arguments: int) -> None:
30+
print(f'Running lizard in {path}')
31+
command = [
32+
'lizard',
33+
path,
34+
'-T',
35+
f'nloc={nloc}',
36+
'-T',
37+
f'cyclomatic_complexity={complexity}',
38+
'-T',
39+
f'token_count={token_count}',
40+
'-T',
41+
f'parameter_count={arguments}',
42+
'-w',
43+
]
44+
subprocess.run(command, check=False)
45+
print()
46+
47+
48+
# Parse config.
49+
with open('ci/lizard_config.json', encoding='UTF-8') as config_file:
50+
config = json.load(config_file)
51+
for directory in config['directories']:
52+
run_lizard(
53+
directory['directory'],
54+
directory['nloc'],
55+
directory['cyclomatic_complexity'],
56+
directory['token_count'],
57+
directory['parameter_count'],
58+
)

docker/build-image/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ EOT
141141

142142
# COPY "${OCLINT_FILE}" .
143143
RUN \
144-
pip3 install --break-system-packages gcovr pytest \
144+
pip3 install --break-system-packages gcovr pytest lizard\
145145
&& pip3 uninstall --break-system-packages -y certifi \
146146
# && tar xf "${OCLINT_FILE}" \
147147
# && rsync -a oclint-22.02/* /usr/local/ \

0 commit comments

Comments
 (0)